Secure free space on Raspbian appliance via CentOS

Install the wipe command:
cat > /usr/bin/wipe-free-space.sh << EOF
dd if=/dev/zero of=zero.small.file bs=1024 count=102400
dd if=/dev/zero of=zero.file bs=1024
sync ; sleep 60 ; sync
rm zero.small.file
rm zero.file
EOF
chmod +x /usr/bin/wipe-free-space.sh
set partition name to work with:
partition=sdc2
echo $partition
Check current block:
tune2fs -l /dev/$partition | grep "Reserved block count"
Set block to 0:
tune2fs -m 0 /dev/$partition
Check again block:
tune2fs -l /dev/$partition | grep "Reserved block count"
Go to /mnt and check if there is nothing there:
cd /mnt && ls -1
Mount the partition:
mount /dev/$partition /mnt
Go to the /mnt and see if there is something mounted
cd /mnt && ls -1
Execute the wipe operation:
wipe-free-space.sh
Go to home dir and umount partition:
cd && umount /mnt
Set back "Reserved block count" as it was before:
tune2fs -m 5 /dev/$partition
Check again block:
tune2fs -l /dev/$partition | grep "Reserved block count"
Backup device
# see if this is the right device
device=$(echo $partition | egrep -o "[a-z]+")
echo $device

# observ the situation
fdisk -l /dev/$device

# see the end block of last partition
endblock=$(fdisk -l /dev/$device | tail -1 | awk '{ print $3 }')
echo $endblock

filename=$(date +%Y%m%d%H%M)

# execute backup operation
dd if=/dev/$device of=$filename.img bs=512 count=$endblock status=progress

# compress the file using maximum compression
zip $filename.zip $filename.img -9

# or with 7-zip
# yum -y install p7zip p7zip-plugins
7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on $filename.7z $filename.img

# or all togetehr
dd if=/dev/$device of=$filename.img bs=512 count=$endblock status=progress && zip $filename.zip $filename.img -9

No comments: