1、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录.
(1)查看分区大小
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 7.2G 0 rom /mnt/media sda 8:0 0 120G 0 disk ├─sda1 8:1 0 200M 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 2G 0 part [SWAP] ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 200M 0 part /testdir sdc 8:32 0 20G 0 disk ├─sdc1 8:33 0 10G 0 part └─sdc2 8:34 0 10G 0 part sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 10G 0 part └─sdb2 8:18 0 10G 0 part
(2)创建pv、vg、lv、挂载
[root@localhost ~]# pvcreate /dev/sd{b,c}1 //创建pv Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdc1" successfully created [root@localhost ~]# vgcreate -s 16M testvg /dev/sd{b,c}1 //创建卷组 Volume group "testvg" successfully created [root@localhost ~]# lvcreate -L 5G -n testlv testvg //创建lv,并指定大小为5G Logical volume "testlv" created. [root@localhost ~]# mke2fs -t ext4 /dev/testvg/testlv //格式化lv,(lv挂载之前必须要格式化才能使用) [root@localhost ~]# mkdir /users //创建挂载目录 [root@localhost ~]# mount /dev/testvg/testlv /users/ //挂载lv
(3)查看pv、vg、lv、挂载信息
[root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb1 testvg lvm2 a--u 10.00g 5.00g /dev/sdc1 testvg lvm2 a--u 10.00g 10.00g [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree testvg 2 1 0 wz--n- 20.00g 15.00g [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg -wi-ao---- 5.00g [root@localhost ~]# mount /dev/mapper/testvg-testlv on /users type ext4 (rw)
2、 新建用户archlinux,要求其家目录为/users/archlinux,而后su切换至archlinux用户,复制/etc/pam.d目录至自己的家目录
(1)创建用户,并指定家目录
[root@localhost ~]# useradd -d /users/archlinux archlinux [root@localhost ~]# ls /users/ archlinux lost+found [root@localhost ~]# su - archlinux [archlinux@localhost ~]$ cp -r /etc/pam.d/ . //此时在家目录 [archlinux@localhost ~]$ ls pam.d //文件已经复制过来
3、扩展testlv至7G,要求archlinux用户的文件不能丢失
(1)查看vg,lv信息,并进行扩展,查看文件大小是否变化
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree testvg 2 1 0 wz--n- 20.00g 15.00g [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg -wi-ao---- 5.00g [root@localhost ~]# lvextend -L +2G /dev/testvg/testlv Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents). Logical volume testlv successfully resized. [root@localhost ~]# resize2fs /dev/testvg/testlv resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/testvg/testlv is mounted on /users; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/testvg/testlv to 1835008 (4k) blocks. The filesystem on /dev/testvg/testlv is now 1835008 blocks long. [root@localhost ~]# df -TH ........ /dev/mapper/testvg-testlv ext4 7.3G 12M 6.9G 1% /users [root@localhost ~]# su - archlinux //切换用户 [archlinux@localhost ~]$ du -sh pam.d/ //计算archlinux用户当前的pam.d目录大小,为96k 96Kpam.d/ [archlinux@localhost ~]$ du -sh /etc/pam.d/ //计算/etc/pam.d目录大小,为96k,并无变化 96K/etc/pam.d/
4、收缩testlv至3G,要求archlinux用户的文件不能丢失
收缩5步骤:
(1)如已经挂载使用,则需要解挂载
(2)强制检测文件系统是否有问题
(3)缩小文件系统大小
(4)所有lv大小
(5)挂载使用
[root@localhost ~]# umount /users [root@localhost ~]# e2fsck -f /dev/testvg/testlv e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/testvg/testlv: 45/458752 files (0.0% non-contiguous), 64476/1835008 blocks [root@localhost ~]# resize2fs /dev/testvg/testlv 3G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/testvg/testlv to 786432 (4k) blocks. The filesystem on /dev/testvg/testlv is now 786432 blocks long. [root@localhost ~]# lvreduce -L 3G /dev/testvg/testlv WARNING: Reducing active logical volume to 3.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce testvg/testlv? [y/n]: y Size of logical volume testvg/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents). Logical volume testlv successfully resized. [root@localhost ~]# mount /dev/testvg/testlv /users/ [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext4 48G 894M 45G 2% / tmpfs tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 ext4 190M 31M 150M 17% /boot /dev/sda5 ext4 190M 1.6M 179M 1% /testdir /dev/sr0 iso9660 7.3G 7.3G 0 100% /mnt/media /dev/mapper/testvg-testlv ext4 2.9G 7.7M 2.7G 1% /users
5、对testlv创建快照,并尝试基于快照备份数据,验正快照的功能
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree testvg 2 1 0 wz--n- 20.00g 17.00g [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg -wi-ao---- 3.00g [root@localhost ~]# lvcreate -L 1G -s -n testsnapshot /dev/testvg/testlv Logical volume "testsnapshot" created. [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg owi-aos--- 3.00g testsnapshot testvg swi-a-s--- 1.00g testlv 0.00 [root@localhost ~]# su - archlinux [archlinux@localhost ~]$ cd pam.d/ [archlinux@localhost pam.d]$ ls chfn fingerprint-auth other remote smartcard-auth sshd sudo-i chsh fingerprint-auth-ac passwd run_init smartcard-auth-ac ssh-keycat su-l config-util login password-auth runuser smtp su system-auth crond newrole password-auth-ac runuser-l smtp.postfix sudo system-auth-ac [archlinux@localhost pam.d]$ du -sh 96K. [archlinux@localhost pam.d]$ rm -rf r* [archlinux@localhost pam.d]$ du -sh 80K. [archlinux@localhost pam.d]$ exit logout [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg owi-aos--- 3.00g testsnapshot testvg swi-a-s--- 1.00g testlv 0.01
原创文章,作者:Lii,如若转载,请注明出处:http://www.178linux.com/42553