Set custom LABEL for SWAP partition

Linux specific questions/information are gathered here. The main thrust of topics are applied to Centos/RedHat(RH)/Debian/Ubuntu/Gentoo distributives

Set custom LABEL for SWAP partition

Postby lik » Sat Aug 14, 2010 6:51 am

It is possible to set the label of a SWAP partition by using the mkswap command with the '-L' option.

Command syntax is:
Code: Select all
mkswap -L <label> <partition>
              Specify a label, to allow swapon by label.

Replace <label> with the label you would like to use. Replace the partition with the SWAP partition. If following is the output of:
Code: Select all
fdisk -l

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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: 0x00061a23

Device Boot Start End Blocks Id System
/dev/sda1 * 63 417689 208813+ 83 Linux
/dev/sda2 417690 8803619 4192965 82 Linux swap / Solaris
/dev/sda3 8803620 324545129 157870755 83 Linux
/dev/sda4 324545130 488392064 81923467+ 83 Linux

then <partition> would be replaced with /dev/sda2.
Code: Select all
mkswap -L SWAP2 /dev/sda2

Once the SWAP partition has been labeled, remember to change the /etc/fstab to reflect the new label.
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am

Return to Linux specific


  • Related topics
    Last post