Ubuntu – How to automatically mount swap partition

fstabmountpartitioning

I didn't use a swap partition during installation so now that my ubuntu is installed, I used GParted Partition Editor to create an unallocated partition which I formatted as linux-swap. It didn't automatically mount so I right clicked it and selected swapon. Now, whenever I boot the laptop, the partition is not mounted automatically. Swapon still works but if the partition isn't mounted at boot, its as good as useless.
I saw some answers which said to edit some file named Fstab, but I'm not sure about what changes to make… Please help me by giving step-by-step instructions as I'm a TOTAL noob and don't know U of Ubuntu, I'm having a lot of problems… please help me! :'( 🙁
Here's what my fstab file contains-

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=33a0fc77-06b0-406c-95fd-15bf7033b619 /               ext4    errors=remount-ro 0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

Best Answer

  • This is your previous /etc/fstab:

    # /etc/fstab: static file system information.
    #
    # Use 'blkid' to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    # / was on /dev/sda2 during installation
    UUID=33a0fc77-06b0-406c-95fd-15bf7033b619 /               ext4    errors=remount-ro 0       1
    # a swapfile is not a swap partition, no line here
    #   use  dphys-swapfile swap[on|off]  for that
    

    Now, to add your swap partition to it, do the following:

    1. Open Gparted.

      Gparted screenshot

    2. Right-click on the swap partition and click on Information.

      select partition in Gparted

    3. Note down your UUID.

      UUID in partition info

    4. Now, modify your previous /etc/fstab, by doing the following:

      • Open the file by typing the command:

        sudo -H gedit /etc/fstab
        
      • Then, add this line,

        UUID=THE UUID YOU OBTAINED FROM ABOVE none       swap   sw         0     0
        

        after the line

        # a swapfile is not a swap partition, no line here
        
      • Save the file and restart your computer. Everything should be working now.