How to remove swap partition

11,991

First, a word of warning: the solution to your problem requires something rather risky that may render your Ubuntu installation unbootable. It involves moving your /boot partition. If anything of value is on this installation, back it up before proceeding. Anyways here's the steps:

To disable the swap partition, open /etc/fstab as root and remove the line pertaining to your swap partition. Then, run sudo swapoff /dev/sda1 or whichever sdx# your swap partition is on.

Reclaiming the space from your swap partition would ordinarily be a matter of opening gparted, deleting the old swap partition and resizing the original, but since you want to add it to your home partition you'll need to do it either with your hard drive plugged into another Linux machine or from a live USB with gparted.

Once you are on another machine/live USB, run sudo gparted. The reason you can't resize it immediately, based on your image, is because the swap partition isn't consecutive with your home folder. For partitions to be merged, they need to be 'next' to each other (a partition is a consistent region of data space, and can't be broken up or it'd just be two partitions). It's still possible, but a step needs to be added; move the swap partition next to your home partition.

Doing this is a bit of a process, though. I used a flash drive to show you what needs to be done; here's the starting partitions: Image1

You can see I have 2 partitions and some empty space. To expand partition A into the empty space at the end of the disk, I need to move partition B. Right click partition B and select "resize or move" to get this window: img2

From here, copy the value in "free space following" into "free space preceding". This will move it to the end of the free space, or simply drag the partition to the end with the slider.

Once that's done, apply the operation and your free space will now be next to your home partition. Using the move/resize option should now allow you to adjust the size of your home partition.

Share:
11,991

Related videos on Youtube

imnwb
Author by

imnwb

Updated on September 18, 2022

Comments

  • imnwb
    imnwb over 1 year

    Hi i wanted to know if it is possible to remove the swap partition and merge it with home partition. I'm dual booting with mac os using refind, and tried to boot gpartedlive from refind, but it wont boot and gets stuck on a terminal-like black screen. gparted output

    Edit : I forgot to ask how come I have two recovery hd partitions? is it safe to delete one? maybe it's because I did a fresh reinstall of the whole osx system?

    • Pilot6
      Pilot6 about 5 years
      Boot from Ubuntu LiveUSB. It has gparted there.
    • imnwb
      imnwb about 5 years
      Thanks, ill try that too, I thought it was equivalent to gpartedlive and i would get the same error. Btw is it possible to resize partition the way I asked?
    • Pilot6
      Pilot6 about 5 years
      It is possible, but you will need to disable swap first. You can do it in gparted.
    • imnwb
      imnwb about 5 years
      Actually I tried, here are the step I did. 1.unswap the swap partition, 2 delete the partition so it becomes free space 3. I tried to extend home to the free space now preceding it but the slider wont move...
    • Pilot6
      Pilot6 about 5 years
      This can be done only from LiveUSB.
    • Boris Hamanov
      Boris Hamanov about 5 years
      HOLD ON! STOP! Before taking any of the advice here on manipulating swap... it begs a more obvious question... Why are you wanting to remove swap? Do you understand the implications of doing so? And note that it's only 4G, so adding it to your / partition really won't make any difference. Report back to @heynnema
    • Boris Hamanov
      Boris Hamanov about 5 years
      WHAT YOU SHOULD BE DOING IS... reducing your /dev/sda2 "Macintosh HD" partition, moving your recovery partitions, backup your important Ubuntu files, deleting the current Ubuntu installation (which for the short term may reder your machine not bootable), and reinstalling Ubuntu without the /boot and /home partitions. Restoring your Ubuntu data files.
    • Admin
      Admin almost 2 years
      Should this question have been closed? The first alleged duplicate was itself closed, with a pointer toward a question that has nothing to do with removing a swap partition. The second alleged duplicate does not presently contain any references to "swap." Neither seems to provide guidance on how to remove a swap partition.
  • Pilot6
    Pilot6 about 5 years
    Why? Doesn't need to move /boot.
  • imnwb
    imnwb about 5 years
    I already did like Pilot6 suggested: booted ubuntu live usb, deleted swap and extended home partition to the adjacent free space. In conclusion I managed to merge swap and home partition, now i have 3 linux partition : sda5 /, sda6 /boot, sda8 /home. Now i have 2 questions :1.can I merge sda5 with sda8, eventually deleting sda6, preserving the ubuntu installation 2. is it safe to delete one recovery hd partition to merge with macintosh hd?
  • Admin
    Admin almost 2 years
    Upvoting this answer for its first few paragraphs, which are helpful. The rest of it seems confused. Looking at the screenshot, swap is immediately adjacent to home. So, as imnwb says, s/he had no problem extending home to include the newly free, former swap space. But maybe the screenshot was a later addition?