Linux Mint doesn’t boot after running “rm” command that was supposed to setup a swap partition

The commands you ran do the following things, none of which is even remotely connected to creating a swap partition:

  1. Switch to root (su)
  2. Delete everything in the /boot folder (rm -rf /boot). This is where all the files needed to boot your OS are kept. Including the kernel.
  3. Remove all the basic system commands (rm -rf /bin). Now things like bash,rm,ls,mkdir,mount are no longer available to your system.
  4. Delete most other installed programs (rm -rf /usr/bin)
  5. Turn off the machine (halt).

The final result of these commands is a completely destroyed Linux system. It is theoretically possible to rescue your system but it is really not worth the effort. It will require considerable Linux expertise which I will assume you don't have or you wouldn't be in this situation in the first place :-). The best thing to do really, is to simply reinstall from scratch. The good news is that your data has not been touched and you will have access to it when you boot into a live session to reinstall.

The moral of the story is, do not trust random 15-year-olds you find in IRC channels and always understand what a command does before you run it. Especially if that command needs to be run as root (su).


For future reference, the way to create a swap partition is to use something like GParted live CD. Once you have booted into the live session, you can use gparted to shrink one of your available partitions, then create a new one in the unpartitioned space and assign that to swap. Finally, you will have to reboot into your normal system and update your /etc/fstab file to point to that new swap partition. Something like:

UUID=123-345-abc    swap    swap    sw  0 0

Although your system will not boot because important system directories are gone, all the other directories are still there. It should be possible to, for instance, boot a Linux "live" CD or DVD ROM, mount the drive and poke around. Any good distro should also let you install the system over top of an existing partition without deleting the existing files, such as user home directories.

If there was anything in that system that is valuable (i.e. your personal data, and not just the Linux installation), do not do anything overly hasty which will result in further loss.

If, in the future, you need swap space and there is no space on the drive, instead of trying to resize partitions to make room, you can tell Linux to swap to a file! First you have to create a large file. Usually a file full of zero bytes is created by copying from /dev/zero. Then that file has to be formatted for swapping using the mkswap command. Finally, the kernel can be told to start swapping to that file with swapon.

E.g. one gigabyte file:

$ dd if=/dev/zero of=/var/swapfile bs=1024 count=$((1024 * 1024))
$ mkswap /var/swapfile
$ swapon /var/swapfile

This trick is good for emergencies when some program is chewing up a lot of virtual memory, and you do not want to kill that program (because, say, you're a scientist and the program has been performing some valuable computation for hours). If you just need the swap temporarily for such a situation, you can then get rid of it afterward:

$ swapoff /var/swapfile
$ rm /var/swapfile

But suppose you want to keep this. If you reboot the system, it will forget all about your swap file. The file will be there but the system won't be swapping to it because nobody ran a swapon command. To record the swap file so that it is used on boot, enter it into the /etc/fstab file by adding a line like:

/var/swapfile swap swap defaults 0 0

That's it.