实验课题:Linux根目录扩容.
系统:CentOS 7.9
1、扩容前数据
[root@prometheus ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.7G 0 4.7G 0% /dev
tmpfs 4.7G 0 4.7G 0% /dev/shm
tmpfs 4.7G 13M 4.7G 1% /run
tmpfs 4.7G 0 4.7G 0% /sys/fs/cgroup
/dev/mapper/centos-root 89G 23G 67G 26% /
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 959M 32K 959M 1% /run/user/1001
/dev/sr0 4.4G 4.4G 0 100% /run/media/oracle/CentOS 7 x86_64
tmpfs 959M 0 959M 0% /run/user/0
[root@prometheus ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 89G 0 lvm /
└─centos-swap 253:1 0 10G 0 lvm [SWAP]
sr0 11:0 1 4.4G 0 rom /run/media/oracle/CentOS 7 x86_64
2、磁盘处理
a、将磁盘/dev/sda由100g扩展到120g;b、新增加1块10g磁盘.
重启虚拟机,查看磁盘情况.
[root@prometheus ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 120G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 89G 0 lvm /
└─centos-swap 253:1 0 10G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
sr0 11:0 1 4.4G 0 rom /run/media/oracle/CentOS 7 x86_64
说明:磁盘/dev/sda已成功扩展到120G,磁盘/dev/sdb为新添加磁盘.
3、根目录扩容
3.1、扩展sda
先处理磁盘/dev/sda扩容的20g,将其扩容到根目录下.
3.1.1、逻辑卷信息
[root@prometheus ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <99.00g 0
[root@prometheus ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <99.00g 0
[root@prometheus ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <89.00g
swap centos -wi-ao---- 10.00g
3.1.2、磁盘分区
[root@prometheus ~]# fdisk /dev/sda
……
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (209715200-251658239, default 209715200):
Using default value 209715200
Last sector, +sectors or +size{K,M,G} (209715200-251658239, default 251658239):
Using default value 251658239
Partition 3 of type Linux and of size 20 GiB is set
Command (m for help): w
……
[root@prometheus ~]# fdisk /dev/sdb
……
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w
……
[root@prometheus ~]# partprobe
[root@prometheus ~]# lsblk -p
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
/dev/sda 8:0 0 120G 0 disk
├─/dev/sda1 8:1 0 1G 0 part /boot
├─/dev/sda2 8:2 0 99G 0 part
│ ├─/dev/mapper/centos-root 253:0 0 89G 0 lvm /
│ └─/dev/mapper/centos-swap 253:1 0 10G 0 lvm [SWAP]
└─/dev/sda3 8:3 0 20G 0 part
/dev/sdb 8:16 0 10G 0 disk
└─/dev/sdb1 8:17 0 10G 0 part
/dev/sr0 11:0 1 4.4G 0 rom /run/media/oracle/CentOS 7 x86_64
3.1.3、扩容/dev/sda3
[root@prometheus ~]# pvcreate /dev/sda3
[root@prometheus ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <99.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25343
Free PE 0
Allocated PE 25343
PV UUID 8WWbt6-7STK-pURR-5Ecr-2mmd-VCfe-LZ8SKd
"/dev/sda3" is a new physical volume of "20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID HC8yf3-yh5Y-Fb8K-SQMq-qesL-DGWw-tsXV5w
[root@prometheus ~]# vgdisplay
--- Volume group ---
VG Name centos
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 <99.00 GiB
PE Size 4.00 MiB
Total PE 25343
Alloc PE / Size 25343 / <99.00 GiB
Free PE / Size 0 / 0
VG UUID z8TIkl-r75D-sUeo-7l9h-hMiV-TJtA-RYqeu2
[root@prometheus ~]# vgextend centos /dev/sda3
[root@prometheus ~]# lvdisplay
……
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID Bz91v2-z4T4-JrJm-XSeq-O335-gO01-qLzPE3
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-06-29 15:06:54 +0800
LV Status available
# open 1
LV Size <89.00 GiB
Current LE 22783
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@prometheus ~]# lvextend -l +100%free /dev/centos/root /dev/sda3
[root@prometheus ~]# cat /etc/fstab |grep centos-root
/dev/mapper/centos-root / xfs defaults 0 0
[root@prometheus ~]# xfs_growfs /dev/centos/root
[root@prometheus ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.7G 0 4.7G 0% /dev
tmpfs tmpfs 4.7G 0 4.7G 0% /dev/shm
tmpfs tmpfs 4.7G 13M 4.7G 1% /run
tmpfs tmpfs 4.7G 0 4.7G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 109G 24G 86G 22% /
/dev/sda1 xfs 1014M 185M 830M 19% /boot
tmpfs tmpfs 959M 40K 959M 1% /run/user/1001
/dev/sr0 iso9660 4.4G 4.4G 0 100% /run/media/oracle/CentOS 7 x86_64
tmpfs tmpfs 959M 0 959M 0% /run/user/0
说明:如上所示,根目录空间已由89G成功扩容到109G.
3.2、扩展sdb
现在扩展新增磁盘/dev/sdb,前面已分区.
[root@prometheus ~]# pvcreate /dev/sdb1
[root@prometheus ~]# vgextend centos /dev/sdb1
[root@prometheus ~]# lvextend -l +100%free /dev/centos/root /dev/sdb1
[root@prometheus ~]# xfs_growfs /dev/centos/root
[root@prometheus ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.7G 0 4.7G 0% /dev
tmpfs tmpfs 4.7G 0 4.7G 0% /dev/shm
tmpfs tmpfs 4.7G 13M 4.7G 1% /run
tmpfs tmpfs 4.7G 0 4.7G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 119G 24G 96G 20% /
/dev/sda1 xfs 1014M 185M 830M 19% /boot
tmpfs tmpfs 959M 40K 959M 1% /run/user/1001
/dev/sr0 iso9660 4.4G 4.4G 0 100% /run/media/oracle/CentOS 7 x86_64
tmpfs tmpfs 959M 0 959M 0% /run/user/0
[root@prometheus ~]# lsblk -p
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
/dev/sda 8:0 0 120G 0 disk
├─/dev/sda1 8:1 0 1G 0 part /boot
├─/dev/sda2 8:2 0 99G 0 part
│ ├─/dev/mapper/centos-root 253:0 0 119G 0 lvm /
│ └─/dev/mapper/centos-swap 253:1 0 10G 0 lvm [SWAP]
└─/dev/sda3 8:3 0 20G 0 part
└─/dev/mapper/centos-root 253:0 0 119G 0 lvm /
/dev/sdb 8:16 0 10G 0 disk
└─/dev/sdb1 8:17 0 10G 0 part
└─/dev/mapper/centos-root 253:0 0 119G 0 lvm /
/dev/sr0 11:0 1 4.4G 0 rom /run/media/oracle/CentOS 7 x86_64
结论:sda与sdb成功扩容到根目录,该目录已由此前89G增长到119G.
指导网址:https://cloud.tencent.com/developer/article/2047943