1)预先创建2GiB的分区/dev/vdb1,并用于创建卷组testvg
2)创建大小为200MiB的逻辑卷/dev/testvg/vo,格式化为ext4文件系统,并挂载在/mnt/vo上
3)将逻辑卷/dev/testvg/vo及其文件系统大小调整到300MiB,确保文件系统内容保持不变。
准备工作
[root@serverb ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xae75bf0a.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759):
+2G
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@serverb ~]# pvcreate /dev/vdb1
[root@serverb ~]# vgcreate testvg /dev/vdb1
[root@serverb ~]# lvcreate -L 200M -n vo testvg
[root@serverb ~]# mkfs.ext4 /dev/testvg/vo
[root@serverb ~]# blkid /dev/testvg/vo
/dev/testvg/vo: UUID="fe323058-93db-428d-883c-2c0210cd10c6" TYPE="ext4"
[root@serverb ~]# vim /etc/fstab
/dev/testvg/vo /mnt/vo ext4 defaults 0 0
[root@serverb ~]# mount -a
[root@serverb ~]# df -hT /dev/testvg/vo # 查看文件系统的类型和大小
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/testvg-vo xfs 195M 12M 183M 6% /mnt/vo
实际操作
[root@serverb ~]# lvextend -L 300M /dev/testvg/vo
[root@serverb ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync
Convert
vo testvg -wi-ao---- 300.00m
# 扩展文件系统,xfs类型的文件系统用xfs_growfs /mnt/vo,后面接的是挂载点。
[root@serverb ~]# resize2fs /dev/testvg/vo # 后面接的是挂载点的路径
[root@serverb ~]# df -hT /dev/testvg/vo
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/testvg-vo ext4 295M 13M 283M 5% /mnt/vo