swaplabel
Create or modify a swap space label
TLDR
Display the current label and UUID of a swap area
Set the label of a swap area
Set the UUID of a swap area (you can generate a UUID using uuidgen)
SYNOPSIS
swaplabel [options] device [label]
PARAMETERS
device
The block device representing the swap partition (e.g., /dev/sda5).
label
The new label to be written to the swap partition. If omitted, the current label is displayed.
-U, --uuid
Specify the UUID to be written to the swap partition. Overrides the label argument if provided.
-h, --help
Display help text and exit.
-V, --version
Display version information and exit.
DESCRIPTION
The swaplabel command is a Linux utility designed to read, and most importantly, to *write* the label on a swap device. This is crucial when you need to identify swap partitions correctly, especially in complex system configurations involving multiple swap spaces or automated swap configuration scripts. Prior to its introduction (and as a fallback), `mkswap` could be used to recreate the label. However, recreating the swap label is not ideal if the data within the swap space is crucial (although swap data is considered ephemeral). `swaplabel` provides a safe way to change the UUID or label associated with a swap partition without reformatting, thus avoiding potential data loss and speeding up the configuration process. It’s primarily used by system administrators and advanced users needing fine-grained control over swap space management. Note, the device given as input must not be in active use as a swap space.
Properly labeled swap devices simplify system administration, particularly when using tools like `swapon -a` to enable all swap devices listed in `/etc/fstab`. Using consistent and meaningful labels helps ensure that the correct swap partitions are activated, preventing accidental activation of the wrong devices. The command is part of the `util-linux` package.
CAVEATS
Using swaplabel on a device already in use as swap space is highly discouraged and can lead to unpredictable behavior and data corruption. Ensure the swap partition is deactivated using `swapoff` before modifying its label or UUID. Incorrect labels in `/etc/fstab` can prevent your system from booting correctly if your swap partition is required before the root filesystem becomes available.
EXIT STATUS
The swaplabel command exits with a status of 0 upon success, and a non-zero value in case of errors. Common errors include attempting to modify a swap device that is currently active, specifying an invalid device, or lacking sufficient permissions.
HISTORY
The swaplabel command was introduced as part of the util-linux package to provide a dedicated utility for managing swap partition labels. Prior to its availability, the only way to change a swap partition's label was to recreate the swap space using mkswap, which is a destructive operation. swaplabel addresses this by allowing non-destructive label modifications, enhancing system administration capabilities. It sees most usage within automated system configuration tools and scripts.