How to automatically mount swap partition?

28,241

Solution 1

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.

Solution 2

Type in terminal:

gnome-disks 

Then select the swap partition. In the settings menu select "Edit mount" option.

Share:
28,241

Related videos on Youtube

Hrijul Bhatnagar
Author by

Hrijul Bhatnagar

Updated on September 18, 2022

Comments

  • Hrijul Bhatnagar
    Hrijul Bhatnagar over 1 year

    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
    
    • mikewhatever
      mikewhatever over 8 years
      Can you post the output of sudo blkid. It will show the UUID of the swap partition, and we can then add it to /etc/fstab.
  • Hrijul Bhatnagar
    Hrijul Bhatnagar over 8 years
    It worked!! Thanks a lot! You're a god... But hibernate and is still not working. I have 2gb RAM and 3gb swap.
  • Raphael
    Raphael over 8 years
    @HrijulBhatnagar - The question was only about swap so, I answered it at that. If you want to know how to hibernate, then, please ask a new question and share the link in this comment section, I will answer it for you. Also, if the answer helped, then PLEASE ACCEPT THE ANSWER AND UPVOTE IT.
  • Hrijul Bhatnagar
    Hrijul Bhatnagar over 8 years
    I did upvote it but since I'm a new user, it says that I need a reputation of 15 to publicly display my vote...
  • Raphael
    Raphael over 8 years
    @HrijulBhatnagar - If you want the answer to be accepted then click on the tick below the upvote downvote buttons.
  • Raphael
    Raphael over 8 years
    And regarding hibernation please ask a new question and link that question in the comments here, I shall try to answer that for you.
  • Hrijul Bhatnagar
    Hrijul Bhatnagar over 8 years
    I'm over hibernation now... you can help me with this though- askubuntu.com/questions/712002/how-to-get-back-unity-greeter