How do I uninstall Ubuntu from a computer?
DO NOT RUN sudo rm -rf / --no-preserve-root
on systems with systemd
When running the command on a UEFI computer (2012 or newer) you are deleting all the UEFI firmware variables which can cause your PC to be bricked and cannot be repaired without a motherboard replacement on some devices.
Here is what happened to one Linux user : An Ubuntu command bricked my system?
So don't try what the other answers talking about rm -rf /
say since it only works on legacy BIOS machines. I am typing this from a UEFI laptop which can also be bricked by the command.
Proper Method for UEFI devices.
Boot an Ubuntu Live USB / CD and open GParted. Then delete all the partitions and click apply.
Please note that after this, most of your data can still be recovered easily using professional tools.
Proper Method for UEFI devices if you have private data
As @ByteCommander says, download DBAN (Darik's Boot And Nuke), burn the ISO to a disc / USB and tell it to erase the disk
After performing this, all data is irreversibly gone!
I guess you want to sell your computer. In that case it would be the best to securely wipe the entire disk to prevent that anybody can recover any of your personal files later.
The best tool for this is DBAN (Darik's Boot And Nuke).
Download the .iso
image and burn it to a CD or flash drive. Then boot your computer from it and let it erase the whole hard disk.
Depending on the option you chose, the erasure will be more or less secure, but take longer. Unless you have really private data on that disk, a quick pass should be enough.
Please note that erasing a hard disk this way will irreversibly destroy all data on it, there's no way it can be recovered. Use with caution!
Yes, running sudo rm -rf / --no-preserve-root
will destroy your installation and your motherboard if you have UEFI, leaving only an expensive paperweight , the bootloader (GRUB) and an empty partition.
Note that this will not securely erase data ! Files deleted in this way can still be recovered using data recovery tools.
To securely erase the contents of the disk, leaving your computer without any trace of Ubuntu or your files, boot from a Linux / Ubuntu live DVD / USB, and run
sudo dd if=/dev/zero of=/dev/sda bs=4M
which will securely erase data. Make sure that /dev/sda
is the main hard drive in the computer - you can check with lsblk
. You can also use DBAN, which might be easier to use - see Byte Commander's answer.
Boot into a livecd. take note of the device names of your old system install, and unmount the drives if automounted. I'd use lsblk to check, and umount to unmount.
Run the shred
command on each device. This basically overwrites each partition with zeros, much like dban does. You can then delete the partitions with a suitable tool.
dd
should work, but I prefer shred
since its a more precise tool designed to clear data.
If its an SSD, you might want to use hdparm
to run a sata secure erase command instead.
rm -rf /
is a terrible way to wipe a disk. It risks bricking your system as Suici Doga has suggested. If it dosen't, the data is likely recoverable, and your system may be at a point where you've deleted enough that more cannot be deleted. Its a little like using a hammer to turn a nut. It might work, or you may end up hitting yourself in the head.
If you're on a single drive system attempting to wipe the root drive you should boot from a live media as mentioned by @JourneymanGeek.
My preferred method for wiping a drive uses dc3dd
.
If you don't have it you can install it from the universe
repository on a terminal with sudo apt-get install dc3dd
.
You'll want to determine exactly what drive you are trying to wipe (this is especially important in a multi-drive system).
You can find the correct drive using the output of sudo fdisk -l
.
After determining that the drive is /dev/sdX
or whatever you can issue the command
sudo dc3dd wipe=/dev/sdX
which will overwrite the entire drive with zeros.
A more secure approach might be to overwrite using a pattern such as sudo dc3dd wipe=/dev/sdX pat=FFEEDD
which will overwrite the drive using a hexadecimal pattern (in this case FFEEDD)
You can also use a text pattern to overwrite such as
sudo dc3dd wipe=/dev/sdX tpat=iloveubuntu
which will overwrite the drive using the text string iloveubuntu.
Sources: Experience and Linhost.info (article).
Another method of wiping a whole drive consists of using the ATA Secure Erase feature implemented on many newer drives. This will erase all data on the selected device. Be aware that depending on circumstances (buggy kernel, firmware, or BIOS or using a USB interface) it appears that it's possible to brick the device at least temporarily by locking your self out of it.
If I haven't managed to convince you to use the easier solution above continue from here.
1st insure the drive isn't frozen and secure erase is supported:
Example from a Samsung HD103SJ I found on my shelf:
$ sudo hdparm -I /dev/sdd | grep -A9 Security:
Security:
Master password revision code = 65534
supported
not enabled
not locked
frozen
not expired: security count
supported: enhanced erase
150min for SECURITY ERASE UNIT. 150min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: 50024e92033cfe47
This drive is frozen and need to be unfrozen in order to continue After trying everything from putting the drive to sleep via Disks unplugging and replugging the data cable I ws finally successful in getting the drive into a not frozen state by unplugging the power to it, waiting for it to spin down and plugging the power back into the drive resulting in :
Security:
Master password revision code = 65534
supported
not enabled
not locked
not frozen
not expired: security count
supported: enhanced erase
150min for SECURITY ERASE UNIT. 150min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: 50024e92033cfe47
Now we proceed to set a security password so that we can perform the secure erase.
sudo hdparm --user-master u --security-set-pass Pass /dev/sdd
security_password="Pass"
/dev/sdd:
Issuing SECURITY_SET_PASS command, password="Pass", user=user, mode=high
Since the time for a secure erase of this drive is in excess of 2 hours we had best verify our hdparm version.
hdparm -V
hdparm v9.43
We do this because hdparm versions prior to 9.31 do not pass-through the long command time-outs required for the erase commands to the SCSI-ATA Command Translation ("SAT") layer which such devices use. Mine is version 9.43 so I will proceed.
First I'll confirm that the security mode was properly set:
sudo hdparm -I /dev/sdd |grep -A9 Security
* Security Mode feature set
* Power Management feature set
* Write cache
* Look-ahead
* Host Protected Area feature set
* WRITE_BUFFER command
* READ_BUFFER command
* NOP cmd
* DOWNLOAD_MICROCODE
* Advanced Power Management feature set
--
Security:
Master password revision code = 65534
supported
enabled
not locked
not frozen
not expired: security count
supported: enhanced erase
Security level high
150min for SECURITY ERASE UNIT. 150min for ENHANCED SECURITY ERASE UNIT.
Yes it is as we can see above. Now I will begin to secure erase the drive and go away for the 2 1/2 hours it will take on this one.
sudo hdparm --user-master u --security-erase Pass /dev/sdd
/dev/sdd:
Issuing SECURITY_ERASE command, password="Pass", user=user
When the process is complete your prompt will simply return.
A final alternative:
If you just want to insure that no data on the drive is retrievable and wish to retire the drive permanently. You can pound it flat with a big hammer (wear eye protection and do this at your own risk)
Secure Erase Sources:
https://ata.wiki.kernel.org/index.php/ATA_Secure_Erase
man hdparm
http://www.overclockers.com/forums/archive/index.php/t-693716.html