Wipe free space on external SD card, Raspberry Pi

In this scenario i want to wipe raspberry pi ext4 main partition in my appliance:

These are commands i do in another raspberry pi system:

Install secure-delete package:
sudo apt-get install secure-delete -y
Plug the appliance sd card into usb

Check out partitions Reserved block count:
sudo tune2fs -l /dev/sda2 | grep "Reserved block count"
If the block size are not 0 then set it to 0:
sudo tune2fs -m 0 /dev/sda2
Check again:
sudo tune2fs -l /dev/sda2 | grep "Reserved block count"
Now the block size is 0

Now i mount the filesystem:
sudo mount /dev/sda2 /mnt
Move to the directory which include the disk you want to wipe:
cd /mnt
Execute commands:
sudo su
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
Leave the disk:
cd ..
Umount disk:
umount /mnt
Set back Reserved block count:
tune2fs -m 5 /dev/sda2
log out root:
exit
Appendix:
Install wipe-free-space.sh command:
sudo su
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

No comments: