Disk /dev/sda: 255 heads, 63 sectors, 1044 cylinders Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System /dev/sda1 1 13 104391 83 Linux /dev/sda2 14 804 6353707+ 83 Linux /dev/sda3 805 843 313267+ 82 Linux swap /dev/sda4 844 1044 1614532+ 83 Linux
Disk /dev/sdb: 128 heads, 32 sectors, 512 cylinders Units = cylinders of 4096 * 512 bytes
Device Boot Start End Blocks Id System /dev/sdb1 1 100 204784 83 Linux /dev/sdb2 101 200 204800 83 Linux
Disk /dev/sdc: 128 heads, 32 sectors, 512 cylinders Units = cylinders of 4096 * 512 bytes
Disk /dev/sdc doesn't contain a valid partition table 现在决定要使用磁盘分区/dev/sda4、/dev/sdb1、/dev/sdb2以及磁盘/dev/sdc建立卷组,需要先建立相应的物理卷。使用fdisk工具可以将分区指定为“Linux LVM”类型,具体操作如下: # fdisk /dev/sda
The number of cylinders for this disk is set to 1044. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): t Partition number (1-4): 4
3楼
Hex code (type L to list codes): 8e Changed system type of partition 4 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sda: 255 heads, 63 sectors, 1044 cylinders Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System /dev/sda1 1 13 104391 83 Linux /dev/sda2 14 804 6353707+ 83 Linux /dev/sda3 805 843 313267+ 82 Linux swap /dev/sda4 844 1044 1614532+ 8e Linux LVM
Command (m for help): w The partition table has been altered!
Calling ioctl() to re-read partition table. Re-read table failed with error 16: Device or resource busy. Reboot your system to ensure the partition table is updated.
WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Syncing disks. 对分区/dev/sdb1、/dev/sdb2做同样的操作后,就可以建立物理卷了。建立物理卷的命令是pvcreate,该命令的基本用法为: pvcreate [-d] [-f[f]] [-h] [-y] [-v] PhysicalVolumePath 各个选项的含义如下: -d:启用附加的调试输出。 -f:强制选项,对于已经属于某个卷组的物理卷,可以使用-ff选项进行重建。 -h:获取该命令的帮助信息。 -y:对于所有提问都以“yes”应答。 -v:显示详细的执行过程。 PhysicalVolumePath表示物理卷的设备路径。 例如要在之前准备的设备上建立物理卷,可以执行以下操作: # pvcreate /dev/sda4 /dev/sdb1 /dev/sdb2 /dev/sdc pvcreate -- physical volume "/dev/sda4" successfully created pvcreate -- physical volume "/dev/sdb1" successfully created pvcreate -- physical volume "/dev/sdb2" successfully created pvcreate -- physical volume "/dev/sdc" successfully created 接下来需要将这些物理卷添加到一个卷组中,卷组名为vg01,具体操作如下: # vgcreate vg01 /dev/sda4 /dev/sdb1 /dev/sdb2 /dev/sdc vgcreate -- INFO: using default physical extent size 4 MB vgcreate -- INFO: maximum logical volume size is 255.99 Gigabyte vgcreate -- doing automatic backup of volume group "vg01" vgcreate -- volume group "vg01" successfully created and activated 从上面的命令输出中可以看出,卷组vg01已经建立并且激活,物理分区的尺寸为4MB,单个逻辑卷的尺寸可以达到255.99GB。此外还可以通过vgdisplay命令查看卷组的信息,具体操作如下:
4楼
# vgdisplay /dev/vg01 --- Volume group --- VG Name g01 VG Access read/write VG Status available/resizable VG # 0 MAX LV 256 Cur LV 0 Open LV 0 MAX LV Size 255.99 GB Max PV 256 Cur PV 4 Act PV 4 VG Size 2.92 GB PE Size 4 MB Total PE 747 Alloc PE / Size 0 / 0 Free PE / Size 747 / 2.92 GB VG UUID Cq9FGt-ls34-Jc34-yH9Y-txyj-420P-H97Zhp 从上需信息中可以看到,卷组vg01中包含4个物理卷成员,可以容纳的物理卷和逻辑卷数量为256,物理分区尺寸为4MB,卷组上尚未建立逻辑卷。若要看到更详细的信息,可以使用vgdisplay -v /dev/vg01命令。 由于没有建立逻辑卷,因此还不能够使用该卷组进行数据存储。使用lvcreate命令可以建立逻辑卷,该命令的基本用法为: lvcreate [-A] [-C] [-d] [-h] [-i[-I]] {-l | -L]} [-n] [-p] [-r] [-v] [-Z] VolumeGroupName 其中常用选项的含义如下: -i:指定条带化逻辑卷的条带数,该数字为条带化逻辑卷占用的物理卷数目。 -I:指定条带化逻辑卷的条带尺寸,尺寸可以是2nKB(0<=n<=7)。 -l:指定逻辑卷尺寸,单位是逻辑分区数。 -L:指定逻辑卷尺寸,单位可以是k、m、g、t等。 -n:指定逻辑卷名称。 -p:设定逻辑卷的权限,可以是r(只读)或rw(读写)。 -s:创建镜像逻辑卷。 例如要在卷组vg01上建立一个尺寸为500MB的逻辑卷,可以执行以下操作:
5楼
# lvcreate -L 500M -n lv1 vg01 lvcreate -- doing automatic backup of "vg01" lvcreate -- logical volume "/dev/vg01/lv1" successfully created 已建立好的逻辑卷,可以通过lvdisplay命令进行查看。在该命令中使用-v选项,还可以看到逻辑分区(LE)和物理分区(PE)的映射关系。具体如下: # lvdisplay -v /dev/vg01/lv1 --- Logical volume --- LV Name /dev/vg01/lv1 VG Name vg01 LV Write Access read/write LV Status available LV # 1 # open 0 LV Size 500 MB Current LE 125 Allocated LE 125 Allocation next free Read ahead sectors 120 Block device 58:0 --- Distribution of logical volume on 1 physical volume --- PV Name PE on PV reads writes /dev/sda4 125 0 2 --- logical volume i/o statistic --- 0 reads 2 writes --- Logical extents --- LE PV PE reads writes 00000 /dev/sda4 00000 0 2