I don't know why the default LVM setup was chosen, but I can offer some background on how LVM works.
Without LVM, you divide a disk in partitions, and each partition contains a filesystem (/
, /home
, etc.) or something else such as swap space.
LVM introduces a layer of insulation between the disk structures and the content-bearing structures. I'll refer you to the Wikipedia article for a more in-depth presentation, but in a nutshell, each disk partition is an LVM physical volume, while each filesystem or swap area is an LVM logical volume. There's no relationship between the extent of logical and physical volumes: the space in a physical volume can be divided between several logical volumes, and a logical volume can be stored across multiple physical volumes.
This explains why you're seeing two views. At the disk partitioning level, you have a disk with two partitions, one of which happens to be an LVM physical volume. At the content level, you have several filesystems, some of which happen to be on LVM logical volumes.
Parted isn't showing the LVM logical volumes. Either this version of Parted doesn't support LVM (hmm, I thought it did), or you need to tell it to switch to a different view, or you have already created partitions but not logical volumes yet.
I don't know where you're seeing 4MB wasted. I see 17MB unallocated, and I don't know why. Up to 4MB unused could happen with LVM: the size of each logical volume is a multiple of 4MB.
I don't know for sure what the 255MB ext2 partition is for, but I guess it's meant to be /boot
. It used to be that Grub, the default Ubuntu bootloader, couldn't boot from LVM. But Grub 2, the default bootloader for new installation since Ubuntu 9.10, supports an all-LVM installation, so you probably don't need that boot partition. (There are rare cases where an ext2 boot partition is still useful, for example if you're dual-booting with another operating system that doesn't support loading a kernel from LVM or ext4.)
I think I've addressed everything except the amount of swap. (Aside: you shouldn't ask unrelated questions in one question. The amount of swap has nothing to do with your interrogations about LVM. But the topic has already been done to death, so don't ask it separately, just search the site.) Since disk space is cheap, don't hesitate to have ample swap. The machine I'm posting this from has 4GB of RAM and 16GB of swap. Having low or not swap space will absolutely not “force the OS to use faster RAM”, this is completely wrong and I advise treating any source that says this with deep suspicion. (As far as I know this applies to Windows as well.) The OS will use RAM whenever it can. Swap is only used as a last resort, when there isn't enough RAM. Note that on a normal system, you should expect to see some swap in use. That's because RAM isn't just for storing the memory of running processes, it's also for caching disk contents. In fact, it's quite common to have about half the RAM used by the disk cache, and to have some process memory swapped out. If your system didn't do this, it would be running slower, because it would waste more time reloading the same files from disk again and again.
After a lot of consternation :) I discovered my issue was related at least in part to snapshots (as mentioned, this is all in a VM).
- the disk i'm attempting to modify is from a machine with snapshots
- i mounted / attempted to resize the base/original
.vdi
, didn't do anything with the snapshots
- the contents of that were literally a fresh install, so it wasn't apparent to me initially that the GUID i saw was actually the right disk but an old 'snapshot'.
to prove this out, i cloned the VM from virtualbox's snapshot UI, which gives the option to flatten it at the current state.
This appears to work (including no observed data corruption) so I'm back booted in the original svr vm, with the resized disk!
- power down & clone the vm from whatever state/snapshot - including only 'current state` (which will flatten all snapshots)
- I'm sure this is all possible on top of the snapshots; for me this was acceptable and took some variables out of the mix
- note i have a dynamic disk. Not sure if there are any differences for static (should be NO, but i haven't tested)
- resize the resultant cloned & flattened vdi (eg no snapshots)
VboxManage.exe modifyhd <vdi> --resize 50000
#~50gb
- connect that resized disk to a separate linux VM and boot up
- unmount and remove the vg
- the root fs I'm trying to resize is at
/dev/mm-ubuntu16-svr-vg/root
- call this
/dev/MY_VG/root
below
mount | grep 'VG'
then sudo umount <mountpoint>
if it was mounted
sudo lvchange -an /dev/MY_VG
# remove the logical volume
sudo vgchange -an MY_VG
# remove the volume group
- resize the partition/volumn/and fs
sudo gparted &
# proceed with normal resize
- mine was an extended partition grow, then a grow on the lv
- all the 'normal' instructions work here, in my quetions picture this is a resize (grow)
/dev/sda2
followed by a resize (grow) on /dev/sda5
lvresize -l +100%FREE /dev/MY_VG/root
e2fsk -f /dev/MY_VG/root
# resize2fs prompted me to run this cleanup
resize2fs /dev/MY_VG/root
Done! while still in the other VM, mount and check capacity:
sudo vgchange -ay MY_VG && sudo lvchange -ay /dev/MY_VG
# eg reverse of the remove
sudo mkdir <mountpoint> && sudo mount /dev/MY_VG/root <mountpoint>
df -h
# YAY shows ~50gb total !
And then shutting down, and booting into the original (well, the Cloned & flattened) vm, it boots and has the expected free space / 50gb root drive & filesystem.
hope this helps someone!
Best Answer
I do not like using GParted, partially because most of my servers are without GUI.
Here's how to extend a swap setup as a logical volume:
1) Determine the name of the swap logical volume using the "lvs" command:
2) Turn off the swap partition:
3) Resize the swap partition, adding 15GB more space to it:
4) Format the new swap space to make it usable:
5) Turn the swap volume back on:
6) Use free command to show your new swap space: