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.