Wednesday, January 7, 2009

How to add swap on a Linux machine?

I created /dev/hda2 slice on my disk and then it looks like below. Once slice is created, then the next steps are as follows:

# fdisk -l
Disk /dev/hda: 40.0 GB, 40027029504 bytes
255 heads, 63 sectors/track, 4866 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 1530 12289693+ 83 Linux
/dev/hda2 1531 1780 2008125 82 Linux swap / Solaris
/dev/hda3 3061 4865 14498662+ 7 HPFS/NTFS
/dev/hda4 1781 3060 10281600 83 Linux

# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 12G 8.7G 2.2G 81% /

# mkswap /dev/hda2
Setting up swapspace version 1, size = 2056314 kB

# swapon /dev/hda2


Later, I added the swap space entry in /etc/fstab file also so that everytime system reboots, I dont need to do this again and again.

No comments: