I have a new disk attached to the system. How can I create a new swap partition using this disk on the system?
For the purpose of this post, let’s assume that you do not have any swap configured on your system. /dev/sdc is the drive referenced with no partitions. Since we are going to make a single partition filling the disk, note that any data currently on that disk will be lost. Follow the steps given below to add /dev/sdc1 partition as the new swap partition on the system.
1. Use the fdisk command as root to create a swap partition.
# fdisk /dev/sdc
A new prompt will appear, type ‘p’ to display the current partitions. Verify that you do not have any existing partitions here.
To create a new swap partition type “n“. Since this will be the first partition make it primary by selecting ‘p‘. Select ‘1‘ for the partition number. To accept the default settings for the beginning sector, just press ‘enter’. On the next prompt entre a value of +2G to set the size of swap partition.
On the next prompt, press ‘t‘ to change the partition type. Enter the number ‘1’, to change the partition that was just created
Type ‘82‘ and press enter. Type 82 is for swap partitions. Verify the results by checking the partition table by typing ‘p’. Type ‘w’ to write the changes made.
2. Reread the partition using the partprobe command for the kernel to see the newly created swap partition.
3. Create the swap association on the new device:
# mkswap /dev/sdc1 Setting up swapspace version 1, size = 2097148 KiB no label, UUID=99e34f44-b366-4805-b290-614717f9058b
4. you can use UUID from the output of mkswap when creating the swap to add an entry in /etc/fstab. This entry ensures that the swap partition is activated after each reboot.
# vi /etc/fstab UUID=99e34f44-b366-4805-b290-614717f9058b swap swap defaults 0 0
5. Activate the swap partition:
# swapon -a
6. Verify it is present by executing:
# swapon -s Filename Type Size Used Priority /dev/sdc1 partition 2097148 0 -2