Difference between revisions of "LVM"
From Briki
(→Resizing a physical volume) |
|||
Line 57: | Line 57: | ||
* Remount /dev/vg1/media | * Remount /dev/vg1/media | ||
+ | |||
+ | == Sample vgdisplay Output == | ||
+ | <pre> | ||
+ | --- Volume group --- | ||
+ | VG Name vg1 | ||
+ | System ID | ||
+ | Format lvm2 | ||
+ | Metadata Areas 1 | ||
+ | Metadata Sequence No 5 | ||
+ | VG Access read/write | ||
+ | VG Status resizable | ||
+ | MAX LV 0 | ||
+ | Cur LV 1 | ||
+ | Open LV 1 | ||
+ | Max PV 0 | ||
+ | Cur PV 1 | ||
+ | Act PV 1 | ||
+ | VG Size 170.10 GB | ||
+ | PE Size 4.00 MB | ||
+ | Total PE 43545 | ||
+ | Alloc PE / Size 43545 / 170.10 GB | ||
+ | Free PE / Size 0 / 0 | ||
+ | VG UUID TACrPR-xO6J-mHz0-hiMn-ax3G-R3a4-dv2ivp | ||
+ | </pre> |
Revision as of 10:48, 21 August 2007
Contents
Overview
- One or more Physical Volumes (eg. /dev/sda2) are joined together in a Volume Group (eg. /dev/vg1)
- A Volume Group is split into one or more Logical Volumes (eg. /dev/vg1/media)
Creating a new volume group & logical volume
To create a volume group (/dev/vg1) consisting of 1 physical volume (/dev/sda2), and split into only 1 logical volume (/dev/vg1/media):
- Setup partition as a physical volume:
sudo pvcreate /dev/sda2
- Create a volume group consisting of only this physical volume:
sudo vgcreate vg1 /dev/sda2
- Check volume group has been created successfully:
vgdisplay
This should show 1 volume group consisting of 0 LVs (see Cur LV and 1 PV (see Cur PV).
- Create a logical volume:
sudo lvcreate --size 30g --name media vg1
- Format the logical volume as ext3:
mkfs.ext3 /dev/vg1/media
- Mount the volume by adding the following line to /etc/fstab:
/dev/vg1/media /var/media ext3 defaults 0 2
Resizing a physical volume
For example, extending /dev/sda2. Note here that we are extending a physical volume, not just a logical one.
- Unmount any logical volumes which use /dev/sda2
- Use fdisk to delete old /dev/sda2 and recreate as a larger partition (this will not actually delete any data). If fdisk warns you that the partition table will not be written until the next reboot, you will need to reboot now. Remember to unmount relevant logical volumes again after rebooting.
- sudo pvresize /dev/sda2
- Check how many free extents exist using sudo vgdisplay - you should see extents corresponding to the increase in size of your physical partition.
- Add this many extents to /dev/vg1/media using sudo lvextend -l +<num-extents> /dev/vg1/media
- Resize the filesystem on /dev/vg1/media using sudo resize2fs /dev/vg1/media
- Check that the volumes look correct with sudo vgdisplay
- Remount /dev/vg1/media
Sample vgdisplay Output
--- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size 170.10 GB PE Size 4.00 MB Total PE 43545 Alloc PE / Size 43545 / 170.10 GB Free PE / Size 0 / 0 VG UUID TACrPR-xO6J-mHz0-hiMn-ax3G-R3a4-dv2ivp