Ubuntu – Problem removing swap partition

14.04gpartedlvmpartitioningswap

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

Best Answer

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