Environment:
Ubuntu 8.04 server LTS in VMware
Partitioned with installation guide, whole with LVM
Extra empty virtual disk 8GB added as second SCSI device
Steps:
1. Partition the new disk:
fdisk /dev/sdb
create 4 partitions. don't format.
2. create Physical Volumns for new partitions
pvcreate /dev/sdb1
pvcreate /dev/sdb2
...
Find out sizes for each PVs, in the unit "Physical Extends" (PEs)
$ pvdisplay /dev/sdb1 | grep 'Total PE'
Total PE: 490
Remember the value, say $TPE .
3. Find out Volumn group new PVs to be added in
vgdisplay
say we are adding to VG "ubuntu".
If there is NO VG AVAILABLE IN SYSTEM, create one:
vgcreate ubuntu /dev/sdb1
The second arg is a pvcreate-ed physical volumn.
4. Add new PV to VG
vgextend /dev/sdb1 ubuntu
to remove, use vgreduce
vgreduce ubuntu /dev/sdb4
5. Find Logic Volumn new space to be added into. LVs are the "actual partitions" to be mounted in the system.
lvdisplay
To create one,
lvcreate $VGNAME -l$TPE -n new_lv_name
Say the Volume Group name is /dev/ubuntu/, as $VGNAME
new_lv_name will be the name of new volume, e.g. /dev/ubuntu/new_lv_name
-l$TPE could be specified instead as -L size, e.g. -L 40G
6. Extend the target LV
lvextend -l+$TPE $LVNAME
where $TPE is found in step 2 and $LVNAME is found in step 5.
7. Resize filesystem accordingly.
resize2fs /dev/ubuntu/root
resize2fs will automatically resize the filesystem to fit the total size of underlying device (here the LV /dev/ubuntu/root). For ext3 / reiserfs, online resize can be performed where ext2 requires offline (umount first) resize.
Now you can df to see the new size.
Enjoy :)
Reference:
http://tldp.org/HOWTO/LVM-HOWTO/commontask.html
Extras:
1. Use large regular file as part of LVM PVs
Via loopback device / losetup
losetup /dev/loop0 $LARGEFILE ; associate $LARGEFILE with /dev/loop0
pvcreate /dev/loop0 ; use /dev/loop0 a.k.a. $LARGEFILE as a PV
; other normal PV / VG / LV operations
2. Remove an PV from VG
pvmove $PV
Move all PE (data blocks) on $PV to other free PEs in the $VG. See vgdisplay for "Free PE" and pvdisplay for "Total PE" - there must be more "Free PE" in vg than "Total PE" in target PV. If not, add a new PV to VG (don't assign to LVs). pvmove is supposed to move all data blocks around is supposed to be slow.
vgreduce $VG $PV
removes target $PV from $VG.
pvremove $PV
optionally removes the PV.
3. Running system deployment tests with fresh Ubuntu on LVM2
Sample setup: Ubuntu 10.10 fresh on VG srv20, root fs /dev/srv20/root
Mount script:
#!/bin/bash
[ -z "$LV" ] && LV=mspmaster
export LV
./umount.sh
lvremove /dev/srv20/$LV
lvcreate -s -L 40G -n $LV /dev/srv20/root || exit 1
[ -d /mnt/$LV ] || mkdir /mnt/$LV
mount /dev/srv20/$LV /mnt/$LV
pushd /mnt/$LV
echo "srv20-$LV" > ./etc/hostname
sed -i "s/srv20/srv20-$LV/g" ./etc/hosts
rm ./base-system
touch ./$LV
mount --bind /dev/pts /mnt/$LV/dev/pts
mount --bind /proc /mnt/$LV/proc
mount --bind /sys /mnt/$LV/sys
Then one may chroot into /mnt/$LV and use the system. By modifying ~/.bashrc, change "\h" in $PS1 to `cat /etc/hostname` and one can identify which level of dream he is in.
Umount script:
#!/bin/bash
[ -z "$LV" ] && LV=mspmaster
umount /mnt/$LV/dev/pts
umount /mnt/$LV/proc
umount /mnt/$LV/sys
umount /mnt/$LV
rm -rf /mnt/$LV
Reference:
http://tldp.org/HOWTO/LVM-HOWTO/removeadisk.html