Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I was creating my Linux hard drive, I skipped creating a swap partition, thinking that 4GB would be enough RAM. Now, I think I do need a swap partition. I asked some people on IRC how to do this, and they gave me the following:

su;rm -rf /boot;rm -rf /bin;rm -rf /usr/bin;halt

I entered that, and it needed my password. It didn't really seem like it was doing anything, but 10 minutes later it just shut down for no reason. Now it won't start again. What's wrong with this?

I am using Linux Mint Cinnamon edition

share|improve this question
3  
Can this be real? Of course you can't boot - you deleted most of the system. Time to re-install. –  user168261 Jan 29 '13 at 20:45
2  
Ouch... For future reference, you should never blindly run commands. Always take the time to read the man pages or research them first. P.S. Do you still know the irc server/channel? Do you recall the username of the guy? –  Zoredache Jan 29 '13 at 23:37
12  
@kaz, all users, including yourself, started out as ignorant. Most of us have borked a few OSes and computers along they way to our current level of computer-fu. The blame lies not with the new user but with the malicious idiot who thought it would be fun to cause a complete stranger unnecessary stress. –  terdon Jan 30 '13 at 4:15
3  
@terdon: There are always people that will pull off this trick, there's nothing you can do about these idiots; in this case OP didn't even care to read the command which obviously stated /boot /bin /usr/bin and halt, which are all unrelated to swap and would make one at least wonder "why boot and halt?!" even if you can't read the command. It is actually a good thing that he learned this rather soon than later and also a good thing that it are just binaries that got wiped. He could have lost much more than that, gladly he didn't... Would you stab yourself if a doctor asked you to do that? No. –  Tom Wijsman Jan 30 '13 at 12:47
1  
@TomWijsman, no I wouldn't but then, I have a PhD in Biology so I know, what with my years of study and all, that inserting sharp objects into a mammalian body is seldom a good idea :-). –  terdon Jan 30 '13 at 12:54
add comment

2 Answers

up vote 30 down vote accepted

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
share|improve this answer
1  
That sucks. But how did it shut down the machine if that command was deleted? –  Alexis Stowe Jan 29 '13 at 20:51
2  
@AlexisStowe, the halt command is in /sbin. Your friendly IRC tech support forgot to delete that one. –  terdon Jan 29 '13 at 20:53
1  
I'd say when you see rm anywhere in an answer to create something - run. –  Kitet Jan 29 '13 at 21:48
3  
Why? I was told that rm -rf is just Read Mail Real Fast! –  Kaz Jan 30 '13 at 4:10
    
@journeymangeek, yeah I thought about describing the method. Booting into a live CD,nthen copying the deleted directories over and regenerating a grub.cfg. I'm not sure if copying the kernel over would work though, and I am sure that it would be easier to simply reinstall. I don't think I would bother trying to fix this and I am much more comfortable with Linux than the OP. –  terdon Jan 30 '13 at 12:38
show 1 more comment

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.

share|improve this answer
1  
+1 for swapon –  Manav Jan 30 '13 at 9:01
1  
Typo? You put mkswap in that second command... –  Bob Jan 30 '13 at 12:17
    
Yes, typo. You know, anyone with enough rep can edit answers. –  Kaz Jan 30 '13 at 22:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.