Problem removing swap partition

26,046

Solution 1

You are using LVM. GParted cannot see beyond the LVM volume, it can only see that the LVM volume is present.

115 GiB = 115*1024*1024*1024 bytes ~ 123480000000 = 123.48*1000*1000*100 = 123.48 GB (close enough to your SSD size) - that's an artifact of using SI decimal prefixes in some places and binary prefixes in others.

Presumably the 4GB swap partition you made was not formatted correctly. You can unmount it and run:

sudo mkswap /dev/ubuntu-vg/swap_1
sudo swapon -a

What Ubuntu did here is presumably this:

  • Created a 250 MB /boot primary partition.
  • Created an extended partition for the rest of the partitions.
  • Created an LVM volume within the above extended partition.
  • Created your root and swap partitions within the LVM volume.

(That's why you have both sda2 and sda5. Try using the lsblk command to see how they're related.)

Why the swap partition did not get formatted correctly is a mystery.


To delete the swap and merge back the space to root:

  1. Disable swap. The live environment automatically activates any swap partitions it finds:

    sudo swapoff -a
    
  2. Use lvremove to remove the LVM logical volume of the swap:

    lvremove ubuntu-vg/swap_1
    
  3. Extend the root partition's logical volume using lvextend:

    lvextend ubuntu-vg/root /dev/sda5
    

    This will use all the available space on /dev/sda5 (the 4GB left).

  4. Use resize2fs to resize the filesystem on the root partition to use the new extra space:

    resize2fs /dev/ubuntu-vg/root
    

Solution 2

Follow the steps below:

  1. Delete the 4GB ext4 disk partition (previously, swap) so that File System shows unallocated space.

  2. Now, right-click the linux partiton (in your case, /dev/sda2) and select resize.

  3. Include the unallocated disk space into the linux partition by allocating as per your requirement.

UPDATE

In your case :

  1. Use, Ctrl+Alt+T

  2. Execute sudo lvremove -f dev/ubuntu-vg/swap_1 to remove your swap partition.

  3. Also, executing, sudo lvextend -L +3.89g dev/ubuntu-vg/root will extend your ext4 partition.

  4. Use resize2fs dev/ubuntu-vg/root will resize your new extended space to your ext4 partition.

    NOTE: You'll need to reboot your system to take effect.

Solution 3

If you're using Ubuntu it's very simple:

  1. Open the terminal (ctrl+alt+t) and execute swapoff -a
  2. Open gparted and then delete the swap partitions.
Share:
26,046

Related videos on Youtube

magnese
Author by

magnese

Updated on September 18, 2022

Comments

  • magnese
    magnese over 1 year

    I have a SanDisk SSD U100 124GB. When I installed Ubuntu 14.04 I partitioned as:

    - 250mb boot; - 4gb swap; - the rest ext4.

    Some times later, I removed the swap partition in order to merge it with the big one since I do not need it. I have successfully removed the swap and format to ext4 but I am not able to merge it and I don't understand what is happening.

    In gparted I see only one device (/dev/sda) of size 115.48GB subdivided like this:

    • /dev/sda1 250MiB ext2 /boot;
    • /dev/sda2 115.24 GiB extended;
    • /dev/sda5 115.24 GiB lvm2 pv ubuntu-vg.

    Why do I have 2 partition sda2 and sda5 and not only 1? And why the size is 115 and not 120? Moreover why I cannot see the 4 gb of swap which I have formatted?

    If I open disks under disk drives I have my 124 hdd which is partitioned as:

    • 250 MB ext2;
    • 124GB Extended partition 2;
    • 124GB Partition 5 LVM2 PV.

    But I have also under Other Devices 2 disks:

    • 120GB Block Device /dev/ubuntu-vg/root;
    • 4GB Block Device /dev/ubuntu-vg/swap_1.

    I don't understand all of this. What are other devices? And why gparted and disks show me different things.

    When I boot, the 4gb are automatically mounted in media and I can browse it like a classical usb drive.

    Update

    Following the suggestion of @muru I have restored the swap and now I have

    lvm pvs: /dev/sda5  ubuntu-vg lvm2 a--  115.24g 40.00m
    lvm vgs: ubuntu-vg   1   2   0 wz--n- 115.24g 40.00m
    lvm lvs: root   ubuntu-vg -wi-ao--- 111.32g
             swap_1 ubuntu-vg -wi-a----   3.89g
    

    Let's suppose now that I use a livecd. Could you please tell me the commands to delete swap_1 and merge it with root (I would like to avoid to mess up all the system

  • magnese
    magnese over 9 years
    Thank you for the explanation! I wasn't aware about GiB! Now I have a clear idea what is LVM and with your command I restored the previous swap partition.
  • magnese
    magnese over 9 years
    Since gparted doesn't support lvm, which tool can I use to delete the swap partition and resize sda2?
  • wvxvw
    wvxvw about 7 years
    I had Ubuntu installed in parallel with Fedora on the same laptop. Fedora was using LVM partitioning while Ubuntu was using physical partitioning. How did Ubuntu find Fedora's swap partition is beyond me, but turning off swapping did work for me! So kudos :)