1. system current swap details.
-----------------------------------
[root@rhel6 ~]# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 4194296 0 -1
[root@rhel6 ~]# free -g
total used free shared buffers cached
Mem: 1 0 1 0 0 0
-/+ buffers/cache: 0 1
Swap: 3 0 3
2. Creating swap partition
-----------------------------
[root@rhel6 ~]# fdisk -cu /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa9373e40.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): p
Disk /dev/sdb: 16.4 GB, 16444260352 bytes
255 heads, 63 sectors/track, 1999 cylinders, total 32117696 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa9373e40
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-32117695, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-32117695, default 32117695): +4096M
Command (m for help): p
Disk /dev/sdb: 16.4 GB, 16444260352 bytes
255 heads, 63 sectors/track, 1999 cylinders, total 32117696 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa9373e40
Device Boot Start End Blocks Id System
/dev/sdb1 2048 8390655 4194304 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sdb: 16.4 GB, 16444260352 bytes
255 heads, 63 sectors/track, 1999 cylinders, total 32117696 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa9373e40
Device Boot Start End Blocks Id System
/dev/sdb1 2048 8390655 4194304 82 Linux swap / Solaris
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3. Asking Kernel to re-read fs on /dev/sdb disk to identify created partition.
-----------------------------------------------------------------------------------
[root@rhel6 ~]# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition 1
Note:- you can ignore error partition was identified.
4. making the created partition as swap
---------------------------------------------
[root@rhel6 ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=a42349d1-abcc-48b0-a331-52320829779c
5. enabiling the /dev/sdb1 partition as swap.
-------------------------------------------
[root@rhel6 ~]# swapon /dev/sdb1
[root@rhel6 ~]# echo $?
0
Note:- Return 0 means previous command executed successfully.
6. Checking that new swap partition status.
---------------------------------------------
[root@rhel6 ~]# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 4194296 0 -1
/dev/sdb1 partition 4194296 0 -2
Note:- In Above 2 partitions /dev/sdb1 is the new one which we added
7. Now add an entry in /etc/fstab to make /dev/sdb1 swap partition permanent
--------------------------------------------------------------------------------
[root@rhel6 ~]# vim /etc/fstab
[root@rhel6 ~]# grep /dev/sdb1 /etc/fstab
/dev/sdb1 swap swap defaults 0 0
=========================================================
Removing added /dev/sdb1 swap partition
=========================================================
1. Checking Active swap partitions
-----------------------------------------
[root@rhel6 ~]# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 4194296 0 -1
/dev/sdb1 partition 4194296 0 -2
[root@rhel6 ~]# free -m
total used free shared buffers cached
Mem: 2006 490 1515 0 43 219
-/+ buffers/cache: 227 1779
Swap: 8191 0 8191
2. As we are willing to remove /dev/sdb1 swap. first make it offline.
----------------------------------------------------------------------
[root@rhel6 ~]# swapoff /dev/sdb1
[root@rhel6 ~]# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 4194296 0 -1
3. uncomment or remove /etc/fstab entry for /dev/sdb1
------------------------------------------------------
[root@rhel6 ~]# vim /etc/fstab
[root@rhel6 ~]# grep /dev/sdb1 /etc/fstab
#/dev/sdb1 swap swap defaults 0 0
4. permanently remove the partition using fdisk utility.
-------------------------------------------------------------
[root@rhel6 ~]# fdisk -cu /dev/sdb
Command (m for help): p
Disk /dev/sdb: 16.4 GB, 16444260352 bytes
76 heads, 1 sectors/track, 422601 cylinders, total 32117696 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa9373e40
Device Boot Start End Blocks Id System
/dev/sdb1 2048 8390655 4194304 82 Linux swap / Solaris
Command (m for help): d
Selected partition 1
Command (m for help): p
Disk /dev/sdb: 16.4 GB, 16444260352 bytes
76 heads, 1 sectors/track, 422601 cylinders, total 32117696 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa9373e40
Device Boot Start End Blocks Id System
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
5. Ask kernel to re-read /dev/sdb hard disk.
----------------------------------------------------
[root@rhel6 ~]# partx -a /dev/sdb
[root@rhel6 ~]# echo $?
0
6. Check the swap details.
------------------------------
[root@rhel6 ~]# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 4194296 0 -1
[root@rhel6 ~]# free -m
total used free shared buffers cached
Mem: 2006 488 1518 0 43 219
-/+ buffers/cache: 224 1782
Swap: 4095 0 4095
FOLLOW this blog &
Like me on Facebook.
No comments:
Post a Comment