Showing posts with label swap. Show all posts
Showing posts with label swap. Show all posts

Saturday, November 3, 2012

How to add a swap partition on Redhat Linux system?

I was trying to add a SWAP partition on a Linux system just like Solaris but didn't work. Then after some debugging, I found that method of adding swap in Linux requires few extra steps as mentioned below:

1. Create a partition (/dev/vdb4 in my case) using either fdisk or parted
2. Modify the parition type of this one to Hex code 82
3. Then Make sure the partition table of the disk is saved.
4. Once above is done, then run following commands as shown below:

[root@client1 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           996        264        732          0         19        118
-/+ buffers/cache:        125        871
Swap:            0          0          0

[root@client1 ~]# blkid -c /dev/null
/dev/vda1: UUID="ebf8bf59-fd61-45fd-93f8-c55214f2948f" TYPE="ext4"
/dev/vda2: UUID="ud5dLg-RYz6-WNMO-fj4W-5Z1e-KiHP-jGIk4r" TYPE="LVM2_member"
/dev/vdb1: UUID="37846ba4-2434-4cdc-b322-b7aa28854bfc" TYPE="ext2"
/dev/vdb2: UUID="162b6c2d-9ace-47b2-a7ba-b14abdf95bf4" TYPE="ext3"
/dev/vdb3: UUID="88e9c86d-d7ab-47cc-9746-3eec78e698e0" TYPE="ext4"
/dev/mapper/vg_client1-lv_root: UUID="5bf41004-9bd6-45ea-8880-eb0472fd134a" TYPE="ext4"
/dev/mapper/vg_client1-lv_swap: UUID="3fd6f62f-3538-4e1a-85a3-231771121cad" TYPE="swap"

[root@client1 ~]# which mkswap
/sbin/mkswap

[root@client1 ~]# mkswap -help
Usage: mkswap [-c] [-pPAGESZ] [-L label] [-U UUID] /dev/name [blocks]

[root@client1 ~]# mkswap /dev/vdb4
Setting up swapspace version 1, size = 352796 KiB
no label, UUID=da1f8f91-45c7-4bef-a47c-c5d1a0a4d081

[root@client1 ~]# blkid -c /dev/null
/dev/vda1: UUID="ebf8bf59-fd61-45fd-93f8-c55214f2948f" TYPE="ext4"
/dev/vda2: UUID="ud5dLg-RYz6-WNMO-fj4W-5Z1e-KiHP-jGIk4r" TYPE="LVM2_member"
/dev/vdb1: UUID="37846ba4-2434-4cdc-b322-b7aa28854bfc" TYPE="ext2"
/dev/vdb2: UUID="162b6c2d-9ace-47b2-a7ba-b14abdf95bf4" TYPE="ext3"
/dev/vdb3: UUID="88e9c86d-d7ab-47cc-9746-3eec78e698e0" TYPE="ext4"
/dev/vdb4: UUID="da1f8f91-45c7-4bef-a47c-c5d1a0a4d081" TYPE="swap"
/dev/mapper/vg_client1-lv_root: UUID="5bf41004-9bd6-45ea-8880-eb0472fd134a" TYPE="ext4"
/dev/mapper/vg_client1-lv_swap: UUID="3fd6f62f-3538-4e1a-85a3-231771121cad" TYPE="swap"

[root@client1 ~]# swapon -s
Filename                                Type            Size    Used    Priority

[root@client1 ~]# swapon -a

[root@client1 ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/vdb4                               partition       352792  0       -1

[root@client1 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           996        264        732          0         20        118
-/+ buffers/cache:        125        871
Swap:          344          0        344

Lastly, dont forget to make an entry of this newly created swap partition in /etc/fstab file (so that it remains in effect even after reboot).
[root@client1 ~]# vi /etc/fstab
:
:
/dev/vdb4               swap                    swap    defaults        0 0
:
:

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.