LVM+ext3 rocks
6 06 2008I guess this is old news to most people, but I’m still excited: The combination of LVM and ext3 makes it possible to resize a partition while it is still mounted.
The short story:
root@TreeHouse:~# lvextend -L+1G /dev/hd/kubuntu
Extending logical volume kubuntu to 6.00 GB
Logical volume kubuntu successfully resized
root@TreeHouse:~# resize2fs /dev/hd/kubuntu
resize2fs 1.40.8 (13-Mar-2008)
Filesystem at /dev/hd/kubuntu is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/hd/kubuntu to 1572864 (4k) blocks.
The filesystem on /dev/hd/kubuntu is now 1572864 blocks long.
That took maybe two seconds.
The long story: Some time ago I replaced the harddisk in my notebook with a 120 GB one. When I reinstalled Kubuntu, I decided to go with LVM for everything. My typical partitioning scheme has one partition (or volume) for the root, a big one for /home and a separate relatively small one for /var (so eg. /var/tmp can’t fill up your root). Plus a big swap partiton and /tmp mounted as tmpfs (so /tmp can’t fill up root neither). Additionally I usually symlink /usr/src to /var/src. Only /boot is not located in the LVM. Which results in the following fstab:
/dev/hd/kubuntu / ext3 defaults,noatime,errors=remount-ro 0 1
/dev/hd/kubuntu+var /var ext3 defaults,relatime 0 2
/dev/hd/home /home ext3 defaults,relatime 0 3
/dev/hd/media /media/Media ext3 defaults,noatime 0 0
/media/Media/music /home/mss/Music none bind 0 0
/media/Media/pictures /home/mss/Pictures none bind 0 0
/dev/sda1 /boot ext3 defaults,noatime 0 2
/dev/hd/swap none swap sw 0 0
proc /proc proc defaults 0 0
tmp /tmp tmpfs size=3G,mode=1777 0 0
For a typical desktop system partitioned like that and running KDE you don’t need more than 4 GiB for the root.
My initial volumes looked like this:
root@TreeHouse:~# pvdisplay /dev/sda3
--- Physical volume ---
PV Name /dev/sda3
VG Name hd
PV Size 110.69 GB / not usable 1.24 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 28337
Free PE 5809
Allocated PE 22528
PV UUID 3aP8yu-j0R1-gnKW-DXOd-rPjd-BHXz-8gjmP7
root@TreeHouse:~# vgdisplay hd
--- Volume group ---
VG Name hd
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 20
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 5
Max PV 0
Cur PV 1
Act PV 1
VG Size 110.69 GB
PE Size 4.00 MB
Total PE 28337
Alloc PE / Size 22528 / 88.00 GB
Free PE / Size 5809 / 22.69 GB
VG UUID FBM2Pd-5yTa-iQIE-cJzO-2ZW1-bf2j-CrYymN
root@TreeHouse:~# lvdisplay hd
--- Logical volume ---
LV Name /dev/hd/home
VG Name hd
LV UUID ooX4NK-rScI-0ByG-tBmd-PALp-Y58V-iGCJuy
LV Write Access read/write
LV Status available
# open 1
LV Size 50.00 GB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:0
--- Logical volume ---
LV Name /dev/hd/kubuntu+var
VG Name hd
LV UUID Dg8Dfj-JWTY-6jlj-uER8-u311-5BQp-qTlRju
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:1
--- Logical volume ---
LV Name /dev/hd/kubuntu
VG Name hd
LV UUID P3Hf92-Fg2F-JX0Z-Oa2j-nffR-gQrn-dXUYQN
LV Write Access read/write
LV Status available
# open 1
LV Size 5.00 GB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:2
--- Logical volume ---
LV Name /dev/hd/swap
VG Name hd
LV UUID jHyLo5-AEdF-kESY-zKkS-BnbI-NRnZ-EUvwry
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GB
Current LE 1024
Segments 1
Allocation contiguous
Read ahead sectors 0
Block device 254:3
--- Logical volume ---
LV Name /dev/hd/media
VG Name hd
LV UUID aosr8H-zDav-aKhx-zlmx-BUc3-LWnW-glDMw0
LV Write Access read/write
LV Status available
# open 1
LV Size 25.00 GB
Current LE 6400
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:4
As you can see I kept ca. 20 GiB spare space (who needs 100+ GiB anyway…) which I didn’t allocate to any volume.
That saved my ass when yesterday suddenly my updates started to fail (after I installed Lazarus). With all those installed libraries, headers and development environments my system doesn’t really qualify as a standard desktop anymore. Now I can even think about installing the KDE 4.1 Beta packages
In case of less anticipatory planning, you might be interested in another article which explains how you shrink one of your volumes first.






Did you try resize2fs more than once on the same volume? I tried it today and i fails…
I tried with new disks to verify…
-> the second attemp fails allways…