In this lab, you will create a swap partition and enable it for use.
| Resources: | |
|---|---|
| Machines: | serverX |
Outcomes:
Your serverX host will have 500 MiB of swap space running on its second disk.
Log into serverX.
Switch to root using sudo -i.
No swap partition was created during the installation of serverX. During peak usage, the server has been running out of physical memory. You have ordered additional RAM and are anxiously waiting for its arrival. In the meantime, you decide to alleviate the problem by enabling swap space on the second disk. To make sure that the newly added swap space is always available for use, you will also need to configure it to be enabled upon boot.
Once you have completed your work, reboot your serverX machine and verify that the swap space is available after the reboot.
Create a 500 MiB partition on /dev/vdb of type
Linux swap.
Use fdisk to modify the second disk.
[root@serverX ~]#fdisk /dev/vdb
Print the original partition table, then create a new partition that is 500 MiB in size.
Command (m for help):pDisk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos Disk identifier: 0xfd41a9d3 Device Boot Start End Blocks Id System /dev/vdb1 2048 2099199 1048576 83 Linux Command (m for help):nPartition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p):pPartition number (2-4, default 2):2First sector (2099200-20971519, default 2099200):EnterUsing default value 2099200 Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519):+500MPartition 2 of type Linux and of size 500 MiB is set Command (m for help):pDisk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos Disk identifier: 0xfd41a9d3 Device Boot Start End Blocks Id System /dev/vdb1 2048 2099199 1048576 83 Linux /dev/vdb2 2099200 3123199 512000 83 Linux
Set the newly created partition to type Linux swap.
Command (m for help):tPartition number (1,2, default 2):2Hex code (type L to list all codes):L... 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- ... Hex code (type L to list all codes):82Changed type of partition 'Linux' to 'Linux swap / Solaris' Command (m for help):pDisk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos Disk identifier: 0xfd41a9d3 Device Boot Start End Blocks Id System /dev/vdb1 2048 2099199 1048576 83 Linux /dev/vdb2 2099200 3123199 512000 82 Linux swap / Solaris
Save the partition table changes.
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.Run partprobe to make the kernel aware of the partition table change.
[root@serverX ~]#partprobe
Initialize the newly created partition as swap space.
[root@serverX ~]#mkswap /dev/vdb2Setting up swapspace version 1, size = 511996 KiB no label, UUID=74f8f3e1-6af3-4e51-9ab5-c48e52bf4a7b
Enable the newly created swap space.
Creating and initializing swap space does not yet enable it for use, as shown by the free and swapon -s command.
[root@serverX ~]#freetotal used free shared buffers cached Mem: 1885252 557852 1327400 17096 1080 246040 -/+ buffers/cache: 310732 1574520 Swap: 0 0 0
[root@serverX ~]#swapon -s[root@serverX ~]#
Enable the newly created swap space.
[root@serverX ~]#swapon /dev/vdb2
Verify that the newly created swap space is now available.
[root@serverX ~]#swapon -sFilename Type Size Used Priority /dev/vdb2 partition 511996 0 -1
Disable the swap space.
[root@serverX ~]#swapoff /dev/vdb2
Verify that the swap space is disabled.
[root@serverX ~]#swapon -s[root@serverX ~]#
Configure the new swap space so that it is enabled upon boot.
Determine the UUID of the new swap partition on the second disk.
[root@serverX ~]#blkid /dev/vdb2/dev/vdb2: UUID="74f8f3e1-6af3-4e51-9ab5-c48e52bf4a7b" TYPE="swap"
Add an entry to /etc/fstab.
UUID=74f8f3e1-6af3-4e51-9ab5-c48e52bf4a7b swap swap defaults 0 0
Test enabling the swap space using the entry just added to
/etc/fstab.
[root@serverX ~]#swapon -a
Verify that the new swap space was enabled.
[root@serverX ~]#swapon -sFilename Type Size Used Priority /dev/vdb2 partition 511996 0 -1
Reboot serverX. After the server has rebooted, log in and verify that swap space is enabled.
[student@serverX ~]#swapon -sFilename Type Size Used Priority /dev/vdb2 partition 511996 0 -1