Note: You should run almost all of the following commands using a Live CD. Sometimes, it wants you to unmount the partition that already mounted on / (in this case, you cannot unmount it).
These are all the steps required to resize a LVM or LVM2 partition:
sudo lvresize --verbose --resizefs -L -150G /dev/mapper/ubuntu
sudo pvresize --setphysicalvolumesize {some-space} /dev/sda5
If the second command produces something like this:
/dev/sda5: cannot resize to xxxxx extents as later ones are allocated.
Then, you have to rearrange the unallocated space at the end of the LVM. That means after root and swap_1 partition. So, initially, you need to check physical volumes' information using the command below:
sudo pvs -v --segments /dev/sda5
This will show the output like:
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-rrr
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx sss 0 free
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g zzz ttt swap 0 linear /dev/sda5:yyy-www
Note the yyy-www. Use the following command to remove external fragmentation:
sudo pvmove --alloc anywhere /dev/sda5:yyy-www
Now, let us see how it goes:
sudo pvs -v --segments /dev/sda5
This will show the output like (note the changes):
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-rrr
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx ttt swap 0 linear /dev/sda5:xxx-sss
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g yyy www 0 free
After that, use the GParted and resize the LVM to maximum used area and rest will be in unallocated space. Enjoy...
e2fsck -f /dev/vg_blah/lv_blah
returns: "e2fsck: Device or resource busy while trying to open /dev/sda2 Filesystem mounted or opened exclusively by another program?", the same with resize2fs... – Idan Yadgar Oct 08 '12 at 13:52vg_blah
) – pzkpfw Oct 09 '12 at 08:39e2fsck -f /dev/sda2
. – Idan Yadgar Oct 09 '12 at 18:56lvreduce -r
. – Flimm Nov 28 '12 at 17:021G
tolvreduce
is 1000000000 bytes, whereas toresize2fs
it is a gibibyte. If you want to pass 1 gibibyte tolvreduce
, use1g
instead. – Flimm Nov 28 '12 at 17:08vgreduce
; that is for removing a pv from a volume group. – psusi Nov 23 '14 at 22:45lvreduce
uses G = gibibyte in differential mode. It certainly does in absolute mode. Its man pages are poorly written and don't explain what their units mean, which I consider as bordering on criminal negligence. – Urhixidur May 22 '15 at 19:39lvresize --resizefs -L 9G /dev/vg_blah/lv_blah
(or-L -1G
) rather than two seperate commands to resize the logical volume and the filesystem – STW Jun 16 '15 at 17:35G
as GiB (2^30 bytes). – Aleksandr Dubinsky Mar 10 '16 at 09:13Invalid path for Logical Volume
, uselvdisplay
. The path of my volume was/dev/myHost/root/
when performing parititioning with the GParted live CD. – Matthias Braun Jan 10 '18 at 15:57