从新磁盘扩容(PV)
假设我们再增加一块硬盘为 /dev/sdd1
[root@192 /]# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created.
[root@192 /]# pvdisplay
--- Physical volume ---
PV Name /dev/sdd1
VG Name data
PV Size 465.76 GiB / not usable 3.02 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 119234
Free PE 0
Allocated PE 119234
PV UUID 2JuybS-xzUQ-h7q5-hzLF-fFqv-UzU3-G3ZozC
如果在虚拟机中添加SCSI格式的磁盘做PV时出现如下报错:
root@host1:~# pvcreate /dev/sdb
Device /dev/sdb excluded by a filter.
导致问题的原因是添加的磁盘是在另一个虚拟机中新建的,已经有了分区表,现在的虚拟机并不能识别磁盘的分区表,运行parted命令重做分区表,中途需要输入三次命令。
root@host1:~# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) quit
Information: You may need to update /etc/fstab.
再次运行pvcreate,问是否擦除dos签名,输入y,就可以将磁盘创建为PV了。
root@host1:~# pvcreate /dev/sdb
WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y
Wiping dos signature on /dev/sdb.
Physical volume "/dev/sdb" successfully created.
将新磁盘加入一个分组
[root@192 /]# vgextend data /dev/sdd1
Volume group "data" successfully extended
[root@192 /]# vgdisplay
--- Volume group ---
VG Name data
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 4
Act PV 4
VG Size <1.82 TiB //这里会发现容量已经增大了
PE Size 4.00 MiB
Total PE 476936
Alloc PE / Size 348160 / <1.33 TiB
Free PE / Size 128776 / 503.03 GiB
VG UUID hqdEd1-03aQ-zMsd-fPeV-JluL-0joY-jXhdGu
为现有磁盘扩充容量
[root@192 /]# lvextend -l +100%FREE /dev/data/mylv
Size of logical volume data/mylv changed from <1.33 TiB (348160 extents) to <1.82 TiB (476936 extents).
Logical volume data/mylv successfully resized.
[root@192 /]# lvdisplay
--- Logical volume ---
LV Path /dev/data/mylv
LV Name mylv
VG Name data
LV UUID jGXCJR-HdxT-XXQx-Yhyb-0vM0-VyN2-8gRweb
LV Write Access read/write
LV Creation host, time 192.168.0.104, 2019-02-14 10:30:47 +0800
LV Status available
# open 1
LV Size <1.82 TiB //逻辑卷的容量也扩容了
Current LE 476936
Segments 4
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
查看磁盘容量以及刷新磁盘容量
[root@192 /]# df -Th
[root@192 /]# resize2fs /dev/data/mylv #CentOS7中报错
[root@192 /]# xfs_growfs /dev/data/mylv #CentOS7中可使用
单块硬盘调整默认分区
centos7在安装时若是自动分区,“/”分区默认只有50G,大部分空间会分给”/home”,安装完系统可以将“/home”删掉全部挂在/下,首先解除/home的挂载
umount /home
删除home所在LV
lvremove /dev/centos/home
扩容“/”所在LV
lvextend -l +100%FREE /dev/centos/root
扩展root文件系统(只能扩容,不能缩容)
xfs_growfs /dev/centos/root
修改fstab(这一步非常重要,千万不要漏了)
vim /etc/fstab
注释或者删除/dev/mapper/centos-home /home
#
# /etc/fstab
# Created by anaconda on Thu Jul 16 22:43:55 2020
#
# Accessible filesystems, by reference, are maintained under '/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=de0e00f9-c956-46bb-bcf4-e2d057b9c0d4 /boot xfs defaults 0 0
UUID=7AB3-D1FB /boot/efi vfat umask=0077,shortname=winnt 0 0
# /dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
就是记个笔记参考博客链接:
https://blog.csdn.net/qq_37467907/article/details/78321832
https://blog.csdn.net/weixin_41558061/article/details/87286680
https://blog.csdn.net/lhl3620/article/details/104792408/