I assume you want to securely wipe the internal SSD/HDD of multiple computers after booting from an USB that runs the full version of Ubuntu. The full version allows installing additional software, while the live installation USB does not.
Step 1: Install nvme-cli
This utility will allow you to securely erase NVME drives without damaging them. Open a terminal and enter:
sudo apt install nvme-cli
Step 2: Write a bash script
Create a plain text file called squeakyclean
in the folder $HOME/bin
with the following content:
#!/bin/bash
# Purpose: find if there are any sata or nvme drives and take different
# action on the each such drive
while IFS= read -r line; do
case $line in
NAME | loop*)
;;
sd?)
echo "Found disk /dev/$line:"
lsblk /dev/"$line"
while true; do
read -p "Do you want to scrub $line? (y/n) " yn < /dev/tty
case $yn in
y)
echo sudo scrub /dev/"$line"
echo " "
break
;;
n)
echo "keeping $line"
echo " "
break
;;
*) echo "invalid response";;
esac
done
;;
nvme[0-9]n[1-9])
echo "Found disk /dev/$line:"
lsblk /dev/"$line"
while true; do
read -p "Do you want to format $line? (y/n) " yn < /dev/tty
case $yn in
y)
echo sudo nvme format -s1 /dev/"$line"
echo " "
break
;;
n)
echo "keeping $line"
echo " "
break
;;
*) echo "invalid response";;
esac
done
;;
*)
echo "$line found doing nothing"
;;
esac
done < <( lsblk -d -o name )
Save the file and make it executable.
Note: this assumes all the SATA drives are HDDs. You should probably use a different utility like hdparm
for scrubbing SATA SSDs.
The Logic
First, the script uses the lsblk
command to list all the internal and external disks. This list may look like:
NAME
sda
sdb
sdc
nvme0n1
nvme0n2
nvme0n3
Second, the script asks if you want to scrub the first SATA disk, sda
. You have to enter either y
or n
. Then it does the same thing for the second SATA disk sdb
etc.
Third, the script asks if you want to securely format the first NVMe disk called nvme0n1
if it exists. You have to enter either y
or n
. Then it does the same thing for the second NVMe disk nvme0n1
etc.
Finally, for any other disks found, it lists them.
Test
Run the script as and see what it outputs. This will tell you which disks it has found and which will be scrubbed. If your USB drive is recognized as /dev/sda
then you have to change the script so that it does not erase your USB drive.
Step 3: Execute!
When you are ready, remove the echo
before sudo
in the two lines of the script.
Warning: Executing this script will delete everything in your computer!
Boot the computer you want to clean using the USB with the full install of Ubuntu.
Open a terminal and type squeakyclean
. You will be asked to enter your sudo password when needed.
Hope this helps
/
? The former may not be the same as the latter, and indeed the latter can be multiple disks.lsblk
to list your devices - and use the ID provided there. My NVME drive is namednvme0n1
./
is mounted on? What if this is an LVM? What of they are mounted remote partitions on a diskless server? Please edit your question and explain what you are trying to achieve here/dev/sda
. Do you perhaps mean/dev/sda1
? What is the mkfs doing? I don't see an-F
option, what does that do? What file system type are you trying to create? How do you know which disk you want to use? How do you know if you wantnvme0n1
ornvme0n2
for example? Are you just looking for the/
partition? If you want to generalize something, you need to tell us what the general principle is. So, again: how do you, as a human, choose the disk?