45

I created a VM using VirtualBox and realized it was too small. After some time I managed to create a new, bigger hard drive.

Live GParted CD image (v.022):

GParted screenshot

Now I need to integrate the unallocated space to the /dev/sda5 partition.

  • Right-clicking on sda5 shows the option to resize but I dont get any free space before or after.
  • I though that perhaps I needed to extend the sda2 partition first but right-clicking on sda2 does not allow me to resize.

Do you have any useful advice?

Gaff
  • 18,569
  • 15
  • 57
  • 68
papnikol
  • 1,551
  • 4
  • 15
  • 19
  • this image sourced from the linux HOST or GUEST (aka VM) – linuxdev2013 May 22 '15 at 00:33
  • The image is from the guest VM, sorry if I was not clear – papnikol May 22 '15 at 00:38
  • 2
    Okay , Is the vg crypted OR just mounted in both cases it needs to be unmounted and additionally in the first case decrypted and unmounted – linuxdev2013 May 22 '15 at 00:40
  • 1
    It is not encrypted. Since I started from the gparted live cd, shouldn't all partitions be unmounted? If not, how do I unmount them from gparted? – papnikol May 22 '15 at 01:06
  • 2
    the lock implies mounted or crypted select them should have ` unmount ` option – linuxdev2013 May 22 '15 at 01:56
  • The lock you mentioned was the problem. There was a choice called deactivate, I used it, increased the extended partition (sda2) and then increased the lvm partition (sda5). It worked fine. Still, when I enter my VM I see only the previous space as available, but I suspect I must do something to increase th filesystem in the, now allocated, space. – papnikol May 22 '15 at 16:42
  • lvextend -r /dev/sda5 should fix that (the -r 'flag' tells the system to resize the filesystem as well) – linuxdev2013 May 24 '15 at 13:06
  • Yes, I already found out, after your help, and wrote something similar in the answer – papnikol May 24 '15 at 13:09

2 Answers2

62

After some help from linuxdev2013, this is what I did:
The problem was that the partitions were somehow locked. So:

  1. I right Clicked both sda2 and sda5 and chose "Deactivate".
  2. I resized the extended (sda2) partition.
  3. I resized the lvm (sda5) partition.

The problem was fixed.

I should add that in the VM the new space was not available, so I had to run those 2 commands: expand LVM to all remaining free space:

lvextend –l +100%FREE [MOUNTPOINT]

expand filesystem:

sudo resize2fs [MOUNTPOINT]
papnikol
  • 1,551
  • 4
  • 15
  • 19
  • 4
    Thanks! I also needed lvm lvdisplay to get the exact device for lvextend, and later df -h to find out the volume on which to resize. – Andreas Reiff Aug 20 '15 at 11:02
  • Thanks for your precise answer, that saved me hours and grey hair! – derFunk Sep 02 '15 at 16:40
  • After using gparted, the partition wasn't showing the right amount free. These 2 command line functions were exactly what I needed to finish the job. Thanks for sharing that wizardry – twig Nov 25 '15 at 22:54
  • Unfortunately, for me deactivating them doesn't work. No error message either... Any hints? – Christoph Wurm Dec 04 '15 at 16:08
  • 6
    I had to run `sudo lvdisplay` to get the [MOUNTPOINT]. In my case it came back as LV Path (/dev/ubuntu-vg/root) – Sheamus O'Halloran Mar 09 '16 at 21:10
  • Nothing was working for me, the lock wouldn't go away even after trying to "deactivate" several times. The only thing that actually unlocked my partition in gparted was to create a new partition in the empty space and then delete it. The lock icon went away and I was able to extend the extended partition... – Frank.Germain Sep 08 '16 at 14:14
  • The GParted Live CD image automatically used the swap space within the LVM partition of my RHEL 5 and 6 VMs. I had to run `sudo swapoff -a` from the command line then use the `deactivate` on the partitions with the padlock. – dan_linder Sep 23 '16 at 15:01
  • Thanks - The deactivate of the extended and VG partitions did it for me. – Chris Mendla Jun 09 '17 at 17:17
  • This helped me realize that I had to extend sda2 AND sda5 (using the example image above). I was pulling my hair out as to why I didn't seem to have any room to extend sda5, even when booting from a liveCD – user6457623 May 26 '20 at 18:11
  • the argument for `lvextend` would be capital `-L` instead of `-l` if using actual size like 1GB. For swap, do `swapoff -a` then `sudo mkswap [MOUNTPOINT]` then `swapon -a` – Yvon Oct 16 '20 at 22:26
1

appliance@zabbix:~$ sudo lvdisplay

--- Logical volume ---

LV Path /dev/zabbix-vg/root

LV Name root

VG Name zabbix-vg

LV Size 15.52 GiB


--- Logical volume ---

LV Path /dev/zabbix-vg/swap_1

LV Name swap_1

VG Name zabbix-vg

LV Size 4.00 GiB


appliance@zabbix:~$ sudo vgs

VG #PV #LV #SN Attr VSize VFree

zabbix-vg 1 2 0 wz--n- 24.52g 5.00g


As you see i have 5 GB Free space


appliance@zabbix:~$ sudo lvextend -L+5G /dev/zabbix-vg/root

Size of logical volume zabbix-vg/root changed from 15.52 GiB (3973 extents) to 20.52 GiB (5253 extents).

Logical volume root successfully resized.


appliance@zabbix:~$ sudo resize2fs /dev/zabbix-vg/root

The filesystem on /dev/zabbix-vg/root is now 5379072 (4k) blocks long.


appliance@zabbix:~$ sudo lvdisplay

--- Logical volume ---

LV Path /dev/zabbix-vg/root

LV Name root

VG Name zabbix-vg

LV Size 20.52 GiB


--- Logical volume ---

LV Path /dev/zabbix-vg/swap_1

LV Name swap_1

VG Name zabbix-vg

LV Size 4.00 GiB

Abdelhak
  • 11
  • 2
  • 1
    He was asking how to resize the physical volume ( the disk partition ), not a logical volume. – psusi Nov 07 '18 at 16:49
  • exactly what I am looking for. extended my physical drive with no problem but it doesn't apply on the logical drive. you helped me adjust my logical drive. thanks a million! – kapitan Oct 22 '19 at 02:27