Let’s say you’re like me. And if you’re exactly like me, you have a vmware server running on your Windows XP box on which you have a linux system running.
Mine is Debian Etch. Don’t shoot me.
When I installed Debian Etch, I chose to use LVM as it allows me to easily increase the size of any partition I have when it’s starting to fill up. I can’t be bothered with many partitions; I’m not running a production server here, so I just have one partition for the entire system. It works for me; honest. Anyway, when the disk starts to fill up and I’ve nothing I want to delete, I need to increase the disk size, and I always forget how to do it. But it’s really easy.
First off, you need to create a new disk, which you do within the vmware server console. After that, the basic commands I run to add a new hard disk to an existing LVM are:
pvcreate /dev/hdb
vgextend blackline-2 /dev/hdb
lvextend -l+511 /dev/blackline-2/root
resize2fs /dev/blackline-2/root
Honest; that is it (well, you might need to run these using ‘sudo’ if you are not the su first). First off, if you don’t know what these commands mean, then look at the man page; for example:
man pvcreate
I needed to display various pieces of information so I could work out some of those values in my above example. Let’s take those commands one at a time.
pvcreate /dev/hdb
To work out /dev/hdb, I needed to go in to the vmware server console from where I added the physical drive. I needed to look to see what the configuration said that disk was called – it was called IDE 0:1 when I did it, therefore that mapped to /dev/hdb. If it had been IDE 0:2 then it would be /dev/hdc, and so on. If it hadn’t been IDE and had instead been SCSI, such as SCSI 0:1, then I’m reasonably sure /dev/sdb would be the one you want.
vgextend blackline-2 /dev/hdb
To work out blackline-2, I needed to display the details of the volume group. The vgdisplay command is the one you want here:
root@blackline-2:~# vgdisplay
--- Volume group ---
VG Name blackline-2
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 6.25 GB
PE Size 4.00 MB
Total PE 1600
Alloc PE / Size 1600 / 6.25 GB
Free PE / Size 0 / 0
VG UUID WBkTAA-ueCR-BGVV-3Rv2-voFa-A3Ep-tLYYYx
That, incidentally, is the output after I added the disk and did all the above commands, just in case you’re wondering. Anyway, the “VG Name” value is all you’re needing.
lvextend -l+511 /dev/blackline-2/root
This looks tricky, but really isn’t. The last parameter is the easiest one to explain, so I’ll do that first. All we’re looking for is the logical volume name, so let’s just display them all:
root@blackline-2:~# lvdisplay
--- Logical volume ---
LV Name /dev/blackline-2/root
VG Name blackline-2
LV UUID eAP1nx-32Z3-W4bO-V57q-aOGM-RNld-PnPKR6
LV Write Access read/write
LV Status available
# open 1
LV Size 6.03 GB
Current LE 1544
Segments 3
Allocation inherit
Read ahead sectors 0
Block device 254:0
--- Logical volume ---
LV Name /dev/blackline-2/swap_1
VG Name blackline-2
LV UUID sFTHXf-1OfG-ataF-Y6Eg-MW43-csxZ-NpxX1M
LV Write Access read/write
LV Status available
# open 2
LV Size 224.00 MB
Current LE 56
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:1
Here you’ll notice I have 2 logical volumes, and one is clearly for root and the other for swap. Therefore, the logical volume name I needed to know when I was deciding which volume to extend was /dev/blackline-2/root. And as you can see, the VG Name that we got earlier is here too, just to confirm that the LV is part of that VG.
The other parameter is simply telling the command how many “units” of new hard disk space we want to add to this partition. Assuming you’ve done the other commands by now, running vgdisplay is what you’re wanting to do, and you need to look at the values of the “Total PE” and “Alloc PE / Size” keys. Or, indeed, just look at the “Free PE / Size” key, which should just be the same as the total less the allocated PE. I just ran it the now and here’s what I got:
Total PE 3390
Alloc PE / Size 2111 / 8.25 GB
Free PE / Size 1279 / 5.00 GB
So, we have 1279 units to add. And I’m going to add them all, so my command will be:
lvextend -l+1279 /dev/blackline-2/root
Let’s see what happens when I run that plus the final command (resize2fs /dev/blackline-2/root), and I’ll run df -h before and after doing all that:
root@blackline-2:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/blackline--2-root
8.0G 5.9G 1.7G 78% /
tmpfs 63M 0 63M 0% /lib/init/rw
udev 10M 72K 10M 1% /dev
tmpfs 63M 0 63M 0% /dev/shm
/dev/sda1 236M 32M 193M 15% /boot
root@blackline-2:~# lvextend -l+1279 /dev/blackline-2/root
Extending logical volume root to 13.02 GB
Logical volume root successfully resized
root@blackline-2:~# resize2fs /dev/blackline-2/root
resize2fs 1.40-WIP (14-Nov-2006)
Filesystem at /dev/blackline-2/root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/blackline-2/root to 3414016 (4k) blocks.
The filesystem on /dev/blackline-2/root is now 3414016 blocks long.
root@blackline-2:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/blackline--2-root
13G 5.9G 6.4G 48% /
tmpfs 63M 0 63M 0% /lib/init/rw
udev 10M 72K 10M 1% /dev
tmpfs 63M 0 63M 0% /dev/shm
/dev/sda1 236M 32M 193M 15% /boot
All done! My hard disk is now 5GB larger. Sweet!