作者:儒雅的活在当下 | 来源:互联网 | 2023-06-12 07:42
原始磁盘挂载情况[root@localhost~]#df-hFilesystemSizeUsedAvailUse%Mountedondevtmpfs126G0126G0%devtm
原始磁盘挂载情况
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 126G 0 126G 0% /dev
tmpfs 126G 0 126G 0% /dev/shm
tmpfs 126G 11M 126G 1% /run
tmpfs 126G 0 126G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 1.3G 49G 3% /
/dev/sda2 1014M 143M 872M 15% /boot
/dev/sda1 1022M 12M 1011M 2% /boot/efi
/dev/mapper/centos-home 10G 33M 10G 1% /home
/dev/mapper/centos-data 1.5T 33M 1.5T 1% /data
tmpfs 26G 0 26G 0% /run/user/0
添加分区的命令以及步骤
1.pvcreate 分区
2.vgcreate vg_name 分区
3.lvcreate -n lv_name size vg_name
4.mkfs.xxx 格式化
5./etc/fstab 添加挂载点
lvdisplay查看当前逻辑卷的信息
vgdisplay查看当前逻辑卷卷组的信息
pvdisplay查看当前物理卷的信息
扩展逻辑卷命令以及步骤
1.pvcreate 分区
2.vgextend 卷组名 /dev/sdb1(分区名)
3. lvextend -l+100%FREE /dev/centos/root (相应的逻辑卷名)
4.xfs_growfs /dev/centos/root 适用于xfs文件系统 resize2fs /dev/centos/root 适用于非xfs文件系统
缩小磁盘命令以及步骤
resize2fs 功能说明:调整ext2/ext3/ext4文件系统大小
resize2fs命令用于扩容或收缩未挂载的ext2/ext3/ext4文件系统。
在Linux2.6或更高版本的内核中,该命令还支持在线扩容已经挂载的文件系统,该命令常用来针对LVM扩容后的分区使用。
- 首先卸载卷
umount /dev/centos/data
- 检测文件系统,重设文件系统大小
e2fsck -f /dev/centos/data //注意此处设置的是减小到的目标大小
resize2fs /dev/centos/data 60G //将data这个文件系统减小到60
- 减小卷大小,重新挂载
4.lvreduce -L -200G /dev/centos/data //主要此处是减小卷的大小
5.mount -a
6.lvs 或 df -hT命令验证查看
删除逻辑卷然后挂到根目录
Path vgName lvname
/dev/centos/data centos data
/dev/centos/home centos home
umount 掉data home
[root@localhost ~]# umount /dev/centos/data
[root@localhost ~]# umount /dev/centos/home
查看当前的逻辑卷
[root@localhost ~]# lvscan
ACTIVE '/dev/centos/root' [50.00 GiB] inherit
ACTIVE '/dev/centos/home' [10.00 GiB] inherit
ACTIVE '/dev/centos/swap' [100.00 GiB] inherit
ACTIVE '/dev/centos/data' [<1.48 TiB] inherit
删除data和home逻辑卷
[root@localhost ~]# lvremove /dev/centos/data
Do you really want to remove active logical volume centos/data? [y/n]: y
Logical volume "data" successfully removed
[root@localhost ~]# lvremove /dev/centos/home
Do you really want to remove active logical volume centos/home? [y/n]: y
Logical volume "home" successfully removed
[root@localhost ~]#
删除根目录的逻辑卷
[root@localhost ~]# lvextend -l+100%FREE /dev/centos/root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to <1.54 TiB (402944 extents).
Logical volume centos/root successfully resized.
[root@localhost ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 s/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=a8c4fe18-39b6-4997-8226-aeaf3dea60d2 /boot xfs defaults 0 0
UUID=CB93-FA1B /boot/efi vfat umask=0077,shortname=winnt 0 0
/dev/mapper/centos-data /data xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
查看根目录验证
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 126G 0 126G 0% /dev
tmpfs 126G 0 126G 0% /dev/shm
tmpfs 126G 11M 126G 1% /run
tmpfs 126G 0 126G 0% /sys/fs/cgroup
/dev/mapper/centos-root 1.6T 1.3G 1.6T 1% /
/dev/sda2 1014M 143M 872M 15% /boot
/dev/sda1 1022M 12M 1011M 2% /boot/efi
tmpfs 26G 0 26G 0% /run/user/0