Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    • Archives

    • Recent comments

    Linux: how to label swap partition w/o losing swap UUID

    16th July 2010

    In short: sudo mkswap -L new_swap_label -U old_swap_UUID /dev/sd_swap_device.
    If you don’t care about the UUID: just sudo mkswap -L new_swap_label /dev/sd_swap_device.

    Step-by-step:

    1. Identify current swap UUID: grep swap /etc/fstab ; you should see a line starting with UUID=b4e6e… – note that UUID; let us assume our UUID is b4e6e5d8-8854-4a3e-8edb-f423ded31e2a
    2. Identify swap partition device. If you are using Debian or Ubuntu, device might have been shown to you when running command #1 as a comment of the form
      # /dev/sdX4 none swap sw 0 0

      Just to be sure, run cat /proc/swaps (or sudo swapon -s), to be shown something like this:

      Filename Type Size Used Priority
      /dev/sdX4 partition 2104504 0 -1

      You can also use partition managers to identify swap device, e.g. sudo fdisk -l. Let us assume our partition device is sdX4.

    3. If that swap partition is in use, you need to disable it first: sudo swapoff /dev/sdX4
    4. Now that you have both the UUID and the device, run
      sudo mkswap -L new_swap_label -U b4e6e5d8-8854-4a3e-8edb-f423ded31e2a /dev/sdX4
      Do not forget replacing sample values above (label, UUID and device) with your actual values.
    5. Enable swap: sudo swapon /dev/sdX4

    Now, if you wish so, you may proceed to edit /etc/fstab and replace UUID=…. with LABEL=your_new_swap_label, leaving all other spaces and values in that line untouched.

    Share

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>