分类: LINUX
2007-11-08 12:08:31
LVM Diary
Somehow I met a case about creating a new partition on LVM disk management machine.
I have to find resource and study it, below is my note.
LVM is a special file system which can extend or reduce its size easily by a command.
One or more physical partition such as /dev/sda1 (/dev/hda1) make up of LVM, you can add on more physical partition to extend the total size of the LVM file system. So it is really flexible for system administrator to manage system partitions.
Physical Volume, short for PV is a type of file system same as swap, ext3 or else, I think.
PV bases on physical partition /dev/sdax, and it has a unique ID 82. So if you want to make a partition become PV, you should use fdisk or parted change its ID to 82 first. Only when partitions become PV, LVM can make use of the partition.
Volume Group, short for VG which component is PV, one or more PV make up of a big VG. The big VG can be partition for
Logical Volume, short for
After clear the basic concepts, create a
1. fdisk /dev/hda2, make the ID to 82.
[root@allenlinux /]# fdisk -l
Disk /dev/hda: 40.0 GB, 40020664320 bytes
240 heads, 63 sectors/track, 5169 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 14 105808+ 83 Linux
/dev/hda2 15 5169 38971800 8e Linux LVM
[root@allenlinux /]#
[root@allenlinux /]# partprobe
[root@allenlinux /]#
Use partprobe rather than system reboot to make partitions available.
2. Create PV
[root@allenlinux /]#pvcreate /dev/hda2
[root@allenlinux /]# pvscan
PV /dev/hda2 VG vgroot lvm2 [37.16 GB / 8.00 GB free]
Total: 1 [37.16 GB] / in use: 1 [37.16 GB] / in no VG: 0 [0 ]
[root@allenlinux /]#
[root@allenlinux /]# pvdisplay
--- Physical volume ---
PV Name /dev/hda2
VG Name vgroot
PV Size 37.16 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 9514
Free PE 2047
Allocated PE 7467
PV UUID QN28tK-AOWu-G5KD-d71b-Bx2N-scaZ-Ti1TkH
3. Create VG
[root@allenlinux /]#vgcreate vgroot /dev/hda2
[root@allenlinux /]# vgdisplay
--- Volume group ---
VG Name vgroot
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 12
VG Access read/write
VG Status resizable
MAX
Cur
Open
Max PV 0
Cur PV 1
Act PV 1
VG Size 37.16 GB
PE Size 4.00 MB
Total PE 9514
Free PE / Size 2047 / 8.00 GB
VG UUID 9SKa2O-Q0yw-I3PD-e3P1-2D2x-hF3i-0GlAQW
[root@allenlinux /]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vgroot" using metadata type lvm2
[root@allenlinux /]#
Vgextend can be use to extend the VG to another PV.
Command: vgextend vgroot /dev/hda3
Hda3 should be PV already.
4. After all, you can create
Command: lvcreate –L size –n LVname VGname
If VGname didn’t specify the default one vgroot will be used here.
lvcreate -L
[root@allenlinux /]# lvscan
ACTIVE '/dev/vgroot/lvroot' [1.00 GB] inherit
ACTIVE '/dev/vgroot/lvopt' [2.00 GB] inherit
ACTIVE '/dev/vgroot/lvtmp' [1.00 GB] inherit
ACTIVE '/dev/vgroot/lvusr' [5.98 GB] inherit
ACTIVE '/dev/vgroot/lvvar' [3.00 GB] inherit
ACTIVE '/dev/vgroot/LogVol00' [1.00 GB] inherit
ACTIVE '/dev/vgroot/lvsvn' [15.19 GB] inherit
[root@allenlinux /]#
Lvextend is use to extend the size of the
Command: lvextend -L
5. Mkfs mke2fs and mount the lv partition
mkfs –t ext3 /dev/vgroot/lvsvn
mount /dev/vgroot/lvsvn /svn
[root@allenlinux /]# df -h /svn
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgroot-lvsvn
[root@allenlinux /]#
Note: /boot can’t be