练习1:创建一个至少有两个PV组成的大小为20G的名为testing的VG,要求PE大小为16MB. 而后在卷组中创建大小为5GB的逻辑卷testlv,挂载至/users目录:
查看磁盘信息:
[root@localhost ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x648d3fea Device Boot Start End Blocks Id System /dev/sdb1 2048 10487807 5242880 8e Linux LVM /dev/sdb2 10487808 20973567 5242880 8e Linux LVM /dev/sdb3 20973568 31459327 5242880 8e Linux LVM /dev/sdb4 31459328 41943039 5241856 5 Extended /dev/sdb5 31461376 41943039 5240832 8e Linux LVM
检查当前系统有无PV
[root@localhost ~]# pvscan No matching physical volumes found #没有找到匹配的物理卷
创建分区1,2,3,5分区为PV:
[root@localhost ~]# pvcreate /dev/sdb{1,2,3,5} Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdb2" successfully created Physical volume "/dev/sdb3" successfully created Physical volume "/dev/sdb5" successfully created
利用PVS查看PV物理卷
[root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 --- 5.00g 5.00g /dev/sdb2 lvm2 --- 5.00g 5.00g /dev/sdb3 lvm2 --- 5.00g 5.00g /dev/sdb5 lvm2 --- 5.00g 5.00g
创建大小为20GB的名为testing的VG,选项“-s”指明创建PE的大小为16MB
[root@localhost ~]# vgcreate testing -s 16MB /dev/sdb{1,2,3,5} Volume group "testing" successfully created
显示VG的详细信息
[root@localhost ~]# vgdisplay testing --- Volume group --- VG Name testing #卷组名为“testing” System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 4 Act PV 4 VG Size 19.94 GiB #卷组的大小为20GB PE Size 16.00 MiB #卷组PE的大小为16MB Total PE 1276 Alloc PE / Size 0 / 0 Free PE / Size 1276 / 19.94 GiB VG UUID GRcIga-Tcg8-4yIW-r0UZ-PjgZ-vLI7-Vimebi
创建逻辑卷testlv
[root@localhost ~]# lvcreate -L 2G testing Logical volume "lvol0" created.
修改逻辑卷的名称为“testlv”
[root@localhost ~]# lvrename /dev/testing/lvol0 /dev/testing/testlv Renamed "lvol0" to "testlv" in volume group "testing"
查看逻辑卷的详细信息:
[root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/testing/testlv LV Name testlv #“逻辑组名为testlv” VG Name testing #“卷组名为testing” LV UUID nO09rU-yuv2-j328-Kx4m-Cb06-hMEg-GWHCXz LV Write Access read/write LV Creation host, time localhost.localdomain, 2016-01-01 23:08:55 -0800 LV Status available # open 0 LV Size 2.00 GiB #“逻辑卷为2GB” Current LE 128 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
格式化逻辑卷
[root@localhost ~]# mke2fs -t ext4 -b 2048 -L Mylv /dev/testing/testlv mke2fs 1.42.9 (28-Dec-2013) Filesystem label=Mylv OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 1048576 blocks 52428 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=269484032 64 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
挂载至/users目录
[root@localhost ~]# mount /dev/testing/testlv /users [root@localhost ~]# man mount
练习2:新建用户archlinux,要求其家目录为/users/archlinux,,而后su切换至archlinux用户,复制/etc/pam.d目录至自己的家目录:
创建用户archlinux, 家目录为:/users/archlinux
[root@localhost ~]# useradd -d /users/archlinux archlinux
切换至用户archlinux
[root@localhost ~]# su - archlinux Last login: Fri Jan 1 23:45:47 PST 2016 on pts/0
复制/etc/pam.d目录至用户家目录
[archlinux@localhost ~]$ cp -r /etc/pam.d/ /users/archlinux [archlinux@localhost ~]
练习3:对testlv创建快照,并尝试基于快照备份数据,验证快照的功能:
创建testlv的快照卷为”mylv_snap”
[root@localhost ~]# lvcreate -s -L 512M -n mylv_snap /dev/testing/testlv Logical volume "mylv_snap" created.