Saturday 21 June 2014

Swap Partition Change

   This tutorial will explain about how to change that Swap space partition to the newly attached drive[ here its /dev/sdd]

   Currently the swap space has been allocated on the drive /dev/sdc. In order to check the swap space details, use the below command.

# swapon -s
Filename    Type  Size Used Priority
/dev/sdc1                             partition 4192924 102580 -1

   Also check the mounted partitions details on /etc/fstab file

# cat /etc/fstab
/dev/sda / ext4 usrjquota=quota.user,jqfmt=vfsv0 0 0
/usr/tmpDSK             /tmp                    ext3    defaults,noauto        0 0
/dev/sdc1   swap swap defaults 0 0

   Then look onto the details about the newly attached drive using fdisk command. The output in our case is below. Here the older swap disk is /dev/sdc with Linux Swap partition and the new raw drive [/dev/sdd] has been attached.

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9fc28f0c

    Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         522     4192933+  82  Linux swap / Solaris

Disk /dev/sdd: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


   Now, create a swap partition on the newly attached drive by using the below commands,

# fdisk /dev/sdd -- accessing the drive to create a partition
then press 'm' for help, there you can see many command option to create partition and make it as swap partition. command 'n' for creating new partition, 't' to change the partition type.
  Once the partition has been created with Linux Swap type, you can see these details by pressing 'p' to print the partition lists, once verified the new settings, press 'w' to write the changes on the disk.

Disk /dev/sdd: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9c471342

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         522     4192933+  82  Linux swap / Solaris


   Lets issue the command 'partprobe' to tell about the new changes on the disk to the kernel, in order to reboot the server. Then make swap space on the newly created partition by using the below command.
# mkswap /dev/sdd1
Setting up swapspace version 1, size = 4192928 KiB
no label, UUID=09e7d007-2459-4d9d-bc6b-8d8cd1825596

   Once the swap partition has been created on the new partition, use the 'swapon' command to use this drive as follows and to see the active swap partition, you can use 'swapon -s' command.
# swapon /dev/sdd1
# swapon -s
Filename    Type  Size Used Priority
/dev/sdc1                             partition 4192924 102580 -1
/dev/sdd1                              partition 4192924 0 -2

   We have achieved the target now, and the server is using two partitions for swap space. Here the drives /dev/sdc and /dev/sdd being used for Swap Space.
   If you want to remove the old drive from the Swap partition, yes we can do this by simply issuing the below command with the drive name.
# swapoff /dev/xdc1

   Once the old drive has been swap off, we can ensure this by issuing the 'swapon -s' command to see the current swap space details. Also make the necessary changes for swap on the /etc/fstab, in order to take effect on next boot. This means, change the drive name on /etc/fstab to new one.

# swapon -s
Filename    Type  Size Used Priority
/dev/sdd1                              partition 4192924 0 -1

No comments:

Post a Comment