Linux LVM逻辑卷管理(3)

TIPS:对于xfs文件系统,备份数据,解挂载,减少空间,强制格式化,重新挂载。需要注意xfs文件系统只能扩大,不能缩小,非要缩小的话,只有缩小后并强制格式化,但这么做数据就丢失了。

[root@localhost ~]# umount /mnt/stu01/ [root@localhost ~]# lvreduce -L -10G /dev/class/stu01 [root@localhost ~]# mkfs.xfs -f /dev/class/stu01 [root@localhost ~]# mount -a [root@localhost ~]# df -hT

TIPS:对于ext4这类文件系统,备份数据,解挂载,e2fsck -f检查文件系统完整性,resize2fs设置文件系统大小,lvreduce设置逻辑卷大小,重新挂载。

[root@localhost ~]# umount /mnt/stu02/ [root@localhost ~]# e2fsck -f /dev/class/stu02 [root@localhost ~]# resize2fs /dev/class/stu02 10G [root@localhost ~]# lvreduce -L 10G /dev/class/stu02 [root@localhost ~]# mount -a [root@localhost ~]# df -hT LVM 实验# 创建 LVM 逻辑卷#

1.添加两块20G的磁盘,重启机器,并对其进行分区,全部空间分为一个主分区,类型改为Linux LVM,ID为8e。分区过程省略,不清楚可参考上一篇博客。

[root@localhost ~]# fdisk -l /dev/sd{b,c} | grep -i "linux lvm" /dev/sdb1 2048 41943039 20970496 8e Linux LVM /dev/sdc1 2048 41943039 20970496 8e Linux LVM

2.将/dev/sdb1、/dev/sdc1转换为物理卷。

[root@localhost ~]# pvcreate /dev/sd{b,c}1 Physical volume "/dev/sdb1" successfully created. Physical volume "/dev/sdc1" successfully created.

3.创建名称为class的卷组,并将sdb1和sdc1添加进卷组。

[root@localhost ~]# vgcreate class /dev/sd{b,c}1 Volume group "class" successfully created

4.划分大小为15G,名称为stu01的逻辑卷,然后再扩容10G;剩下的空间创建名称为stu02的逻辑卷。

[root@localhost ~]# lvcreate -L 15G -n stu01 class Logical volume "stu01" created. [root@localhost ~]# lvextend -L +10G /dev/class/stu01 Size of logical volume class/stu01 changed from 15.00 GiB (3840 extents) to 25.00 GiB (6400 extents). Logical volume class/stu01 successfully resized. [root@localhost ~]# lvcreate -l 100%free -n stu02 class Logical volume "stu02" created.

5.格式化逻辑卷,stu01为xfs,stu02为ext4,设置自动挂载,挂载后就可以使用了。

[root@localhost ~]# mkfs.xfs /dev/class/stu01 meta-data=/dev/class/stu01 isize=512 agcount=4, agsize=1638400 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=6553600, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=3200, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@localhost ~]# mkfs.ext4 /dev/class/stu02 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 983040 inodes, 3930112 blocks 196505 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 120 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@localhost ~]# mkdir /mnt/stu0{1,2} [root@localhost ~]# vim /etc/fstab //最后面添加下面两行内容 /dev/class/stu01 /mnt/stu01 xfs defaults 0 0 /dev/class/stu02 /mnt/stu02 ext4 defaults 0 0 [root@localhost ~]# mount -a [root@localhost ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 17G 927M 17G 6% / devtmpfs devtmpfs 901M 0 901M 0% /dev tmpfs tmpfs 912M 0 912M 0% /dev/shm tmpfs tmpfs 912M 8.7M 904M 1% /run tmpfs tmpfs 912M 0 912M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 143M 872M 15% /boot tmpfs tmpfs 183M 0 183M 0% /run/user/0 /dev/mapper/class-stu01 xfs 25G 33M 25G 1% /mnt/stu01 /dev/mapper/class-stu02 ext4 15G 41M 14G 1% /mnt/stu02 扩容 LVM 逻辑卷#

1.再添加一块20G的磁盘,重启机器,并对其进行分区,全部空间分为一个主分区,类型改为Linux LVM,ID为8e。

[root@localhost ~]# fdisk -l /dev/sd{b..d} | grep -i "linux lvm" /dev/sdb1 2048 41943039 20970496 8e Linux LVM /dev/sdc1 2048 41943039 20970496 8e Linux LVM /dev/sdd1 2048 41943039 20970496 8e Linux LVM

2.将/dev/sdd1转换为物理卷。

[root@localhost ~]# pvcreate /dev/sdd1 Physical volume "/dev/sdd1" successfully created.

3.若是卷组剩余空间不够,就要先对class卷组进行扩容。

[root@localhost ~]# vgdisplay class --- Volume group --- VG Name class System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 10238 / 39.99 GiB Free PE / Size 0 / 0 VG UUID iB1h9h-2uQa-rD7o-GBVK-pOCA-ek2c-TXieLr [root@localhost ~]# vgextend class /dev/sdd1 Volume group "class" successfully extended [root@localhost ~]# vgdisplay class --- Volume group --- VG Name class System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 3 Act PV 3 VG Size <59.99 GiB PE Size 4.00 MiB Total PE 15357 Alloc PE / Size 10238 / 39.99 GiB Free PE / Size 5119 / <20.00 GiB VG UUID iB1h9h-2uQa-rD7o-GBVK-pOCA-ek2c-TXieLr

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/11717.html