查看一下,当前命令:
df -h
[root@server-10 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 990M 0 990M 0% /dev tmpfs 1001M 0 1001M 0% /dev/shm tmpfs 1001M 57M 944M 6% /run tmpfs 1001M 0 1001M 0% /sys/fs/cgroup/dev/mapper/centos-root 27G 5.8G 22G 22% / // 扩容后,再来看该项,作对比 /dev/sda1 1014M 154M 861M 16% /boot tmpfs 201M 0 201M 0% /run/user/0
[root@server-10 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 30G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 29G 0 part ├─centos-root 253:0 0 27G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 10G 0 disk // 新加的硬盘命名为sdb,已经存在,但是还没分区无法给系统使用 sr0 11:0 1 1024M 0 rom
3. 给新硬盘创建分区(此处就默认创建一个分区)
当前命令:
fdisk /dev/sdb
n p 回车 回车 wq
4. 再次查看分区,只是分区好,没挂载没加入系统根,无法使用
当前命令: (没有新分的就重启一下机器在继续)
lsblk
[root@server-10 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 30G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 29G 0 part ├─centos-root 253:0 0 27G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 10G 0 disk └─sdb1 8:17 0 10G 0 part sr0 11:0 1 1024M 0 rom
5. 把新的分区转换为物理卷
当前命令:
pvcreate /dev/sdb1
[root@server-10 ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created.
6. 查看现有的卷组名,这里为centos
当前命令:
vgdisplay
[root@server-10 ~]# vgdisplay --- Volume group --- VG Name centos // 这是Centos系统下默认的VG Name,RHEL系统显示为rhel System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <29.00 GiB //留意该值的变化 PE Size 4.00 MiB Total PE 7423 Alloc PE / Size 7422 / 28.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID RNpAgN-PLQm-M4vp-E37i-fhhp-mr2z-faLm3A
7. 把转换号的物理卷并到vg(卷组)中
当前命令:
vgextend centos /dev/sdb1
[root@server-10 ~]# vgextend centos /dev/sdb1 Volume group "centos" successfully extended
[root@server-10 ~]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 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 38.99 GiB //对比,变大了约10G PE Size 4.00 MiB Total PE 9982 Alloc PE / Size 7422 / 28.99 GiB Free PE / Size 2560 / 10.00 GiB VG UUID RNpAgN-PLQm-M4vp-E37i-fhhp-mr2z-faLm3A
8. 查看逻辑卷,默认系统分了2个,选择对应逻辑卷路径
当前命令:
lvdisplay
[root@server-10 ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/swap //系统默认分了2G给swap,不用管 LV Name swap VG Name centos LV UUID w8yxWk-Qrth-x16P-jVg3-1haX-lZUH-0r1SkV LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-03-21 02:10:16 +0800 LV Status available # open 2 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/root // 后面扩展该逻辑卷,记住该路径 LV Name root VG Name centos LV UUID ECEWl4-0AEW-W1Tn-acE2-GLpe-NxeD-v16tGb LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-03-21 02:10:16 +0800 LV Status available # open 1 LV Size 26.99 GiB Current LE 6910 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
9. 给逻辑卷扩展空间
当前命令:
lvextend /dev/centos/root /dev/sdb1
[root@server-10 ~]# lvextend /dev/centos/root /dev/sdb1 Size of logical volume centos/root changed from 26.99 GiB (6910 extents) to <36.99 GiB (9469 extents). Logical volume centos/root successfully resized.
10. 写入文件系统,使扩容生效。
当前命令:
xfs_growfs /dev/mapper/centos-root
[root@server-10 ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1768960 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=7075840, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=3455, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 7075840 to 9696256
如果是ext系统,可以使用resize2fs命令替换xfs_growfs命令。
11. 检查扩容效果
[root@server-10 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 990M 0 990M 0% /dev tmpfs 1001M 0 1001M 0% /dev/shm tmpfs 1001M 57M 944M 6% /run tmpfs 1001M 0 1001M 0% /sys/fs/cgroup/dev/mapper/centos-root 37G 5.8G 32G 16% / /dev/sda1 1014M 154M 861M 16% /boot tmpfs 201M 0 201M 0% /run/user/0
对比最初的显示,扩容成功。