What is the safest way to remove a swap partition?

47,494

Solution 1

Try to monitor your swap memory usage in a terminal with top or htop, which is more user friendly. If you don't have htop installed, you can install it with:

sudo apt-get install htop

With your amount of RAM, I would say that your swap usage is 0% a lot of time.

If you want to format your swap partition, first you have to disable the swap with the swapoff command. Then format the partition with mkfs.ext4 or mkfs. After that you need to edit your /etc/fstab so that the system will mount your new partition at the boot time.

You can also use a graphical application like Disks, which ships with Ubuntu.

Solution 2

Having a swap partition on any kind of flash storage (like USB drives) is, indeed, not such a good idea.

It should be safe to simply remove the swap partition. While I personally never bothered removing it from /etc/fstab, it most certainly won't hurt either.

If you have sufficient amounts of RAM, the size of the swap partition becomes less relevant (please do correct me if I'm wrong, someone). I usually create a 4GB swap partition, and so far I can't say I've had any problems with it.
When the system is out of RAM (like, 0 bytes available), it will freeze. If it has a swap partition, it can move some data from RAM to swap to prevent the system from freezing. On the other hand, swap (HDD) is slower than RAM, so if it needs to fetch a lot of data from the swap partition, you're going to experience very noticable delays.

Share:
47,494

Related videos on Youtube

user212062
Author by

user212062

Updated on September 18, 2022

Comments

  • user212062
    user212062 almost 2 years

    I am running Ubuntu 12.04 on a 64-bit HP laptop with a 16 GB flash drive. I do not have a working hard drive right now. When I installed Ubuntu, I created a 2 GB swap partition on sdb1. I have since learned that swap partitions are generally a bad idea on flash drives, so I would like to use my swap space for my other partitions. You can see my partition scheme in the link below.

    GParted Screen

    I have read that I just have to comment sdb1 out of the fstab file, boot from a GParted live CD, select swapoff for sdb1, delete/merge with other partition, and everything's good.

    But, I've also read that messing with sdb1 can change the UUID of sdb2 or sdb3 and cause problems. Is this true? Does initramfs use swap at all?

    Also, when I get Ubuntu running on my laptop with an internal hard drive, does the swap partition help that much? I have 6 GB of DDR3. Does the rule of 1.5xActual RAM still apply? It seems like quite a bit to me.

    Thanks for the help!

    UPDATE: I have removed swap. The process I followed is:

    1. Right click swap partition in GParted and selected swapoff.
    2. Used # to comment the swap partition out of fstab.
    3. I tried to boot from a live GParted CD, but I kept getting an error, so I ran GParted in Ubuntu.
    4. Deleted swap partition in GParted.
    5. Unmounted /windows.
    6. Expanded /windows to take the remaining space.
    7. Mounted /windows.

    The / and /windows partitions each kept their own names and UUIDs, and everything is running fine. I have never seen any swap space being used before, and I don't intend to use the hibernate function, so I think removing swap was a good idea.

    • 23  93  26  35  19  57   3  89
      23 93 26 35 19 57 3 89 over 10 years
      When you're using the laptop are you wanting to suspend/hibernate? Perhaps add that to the question - it affects the swap size?
    • 23  93  26  35  19  57   3  89
      23 93 26 35 19 57 3 89 over 10 years
      @qbi - you know that by doing that with the screenshot it is almost unreadable here ;)
    • 23  93  26  35  19  57   3  89
      23 93 26 35 19 57 3 89 over 10 years
      IF you do get problems with UUID's changing then you're in the best place to deal with it, a livecd, mount the partition and edit fstab with new UUID's.
    • qbi
      qbi over 10 years
      @Elfy I linked the image too. So clicking on it will open a larger variant.
    • 23  93  26  35  19  57   3  89
      23 93 26 35 19 57 3 89 over 10 years
      @qbi thanks - could have done that myself I guess :)
    • igauravsehrawat
      igauravsehrawat almost 9 years
      That update in question really helped more.