7.6.2 创建LVM卷
首先,用fdisk命令创建存储设备的物理分区,供创建逻辑分区之用。我们用的是一款32 MB的U盘,设备名为/dev/sdb:
- # fdisk /dev/sdb 启动管理磁盘分区的命令
- Command (m for help): p 显示当前分区(未分区)
- Disk /dev/sdb: 32 MB, 32112128 bytes
- 1 heads, 62 sectors/track, 1011 cylinders
- Units = cylinders of 62 * 512 = 31744 bytes
- Device Boot Start End Blocks Id System
- Command (m for help): n 创建新分区
- Command action
- e extended
- p primary partition (1-4)
- p 设置成主分区
- Partition number (1-4): 1 指定为分区1
- First cylinder (2-1011, default 2): Enter
- Using default value 2
- Last cylinder or +size or +sizeM or +sizeK (2-1011, default 1011): Enter
- Using default value 1011
- Command (m for help): t 指定分区类型
- Selected partition 1
- Hex code (type L to list codes): 8E 设成8E(LVM分区)
- Changed system type of partition 1 to 8e (Linux LVM)
- Command (m for help): p 键入p查看新建分区
- Disk /dev/sdb: 32 MB, 32112128 bytes
- 1 heads, 62 sectors/track, 1011 cylinders
- Units = cylinders of 62 * 512 = 31744 bytes
- Device Boot Start End Blocks Id System
- /dev/sdb1 2 1011 31310 8e Linux LVM
继续下一步操作之前,先确认对相应分区的修改正确无误。如果一切妥当,则写入新分区表,如下所示:
- Command (m for help): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- Syncing disks.
- #
回到shell提示符,使用sfdisk命令查看U盘分区情况:
- # sfdisk -l /dev/sdb 查看LVM分区
- Disk /dev/sdb: 1011 cylinders, 1 heads, 62 sectors/track
- Units = cylinders of 31744 bytes, blocks of 1024 bytes, counting from 0
- Device Boot Start End #cyls #blocks Id System
- /dev/sdb1 1 1010 1010 31310 8e Linux LVM
- /dev/sdb2 0 - 0 0 0 Empty
- /dev/sdb3 0 - 0 0 0 Empty
- /dev/sdb4 0 - 0 0 0 Empty
下一步,将/dev/sdb1制作成新的LVM物理卷,并使用pvs命令查看物理LVM卷相关信息:
- # pvcreate /dev/sdb1 将sdb1制作成LVM物理卷
- Physical volume "/dev/sdb1" successfully created
- # pvs 查看物理LVM分区
- PV VG Fmt Attr PSize PFree
- /dev/sdb1 vgusb lvm2 a- 28.00M 20.00M
- 下面使用vgcreate创建vgusb卷组,并列出当前活跃的卷组:
- $ vgcreate vgusb /dev/sdb1 创建vgusb卷组
- Volume group "vgusb" successfully created
- $ vgs 查看当前卷组
- VG #PV #LV #SN Attr VSize VFree
- vgusb 1 0 0 wz--n- 28.00M 28.00M
使用lvcreate在vgusb卷组里新建一个10M大小的LVM分区。然后,用lvs查看逻辑卷,用vgs查看空闲空间的大小变化:
- $ lvcreate --size 10M --name lvm_u1 vgusb
- Rounding up size to full physical extent 12.00 MB
- Logical volume "lvm_u1" created
- $ lvs 查看逻辑卷信息
- LV VG Attr LSize Origin Snap% Move Log Copy%
- lvm_u1 vgusb -wi-a- 12.00M
- $ vgs 发现卷组仍有16M空闲空间
- VG #PV #LV #SN Attr VSize VFree
- vgusb 1 1 0 wz--n- 28.00M 16.00M
使用mkfs.ext3命令在lvm分区上创建ext3文件系统,示例如下:
- $ mkfs.ext3 /dev/mapper/vgusb-lvm_u1
- mke2fs 1.38 (30-Jun-2005)
- Filesystem label=
- OS type: Linux
- Block size=1024 (log=0)
- Fragment size=1024 (log=0)
- 3072 inodes, 12288 blocks
- 614 blocks (5.00%) reserved for the super user
- First data block=1
- Maximum filesystem blocks=12582912
- 2 block groups
- 8192 blocks per group, 8192 fragments per group
- 1536 inodes per group
- Superblock backups stored on blocks:
- 8193
- Writing inode tables: done
- Creating journal (1024 blocks): done
- Writing superblocks and filesystem accounting information: done
- This filesystem will be automatically checked every 35 mounts or
- 180 days, whichever comes first. Use tune2fs -c or -i to override.
至此,ext3文件系统创建完毕,该LVM卷已准备就绪。