centos7 给根目录扩容

Author Avatar
doubledna 3 月 25 日

新建拓展分区就不解释了

1. 格式后的 sdb4 分区添加为物理卷
[root@linuxidc ~]# pvcreate /dev/sdb4
Physical volume "/dev/sdb4" successfully created

2. 查看当前系统的物理卷(PV)情况
[root@linuxidc ~]# pvdisplay

3.
[root@localhost ~]# pvdisplay 查看当前系统的物理卷(PV)情况
--- Physical volume ---
PV Name /dev/sda3
VG Name centos
PV Size 16.89 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4323
Free PE 1
Allocated PE 4322
PV UUID ZLhmSZ-shEB-1cZi-FTgm-yVlW-UMxT-qIg2kO

"/dev/sda5" is a new physical volume of "<2.11 GiB" 可以看到添加的新物理卷 sda5,大小都符合我们添加时的设置
--- NEW Physical volume ---
PV Name /dev/sda5
VG Name
PV Size <2.11 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID BxlFfG-LYdF-oz75-vne3-Bibo-9DLp-HquCYQ

[root@localhost ~]# vgdisplay 查看当前卷组情况
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <16.89 GiB
PE Size 4.00 MiB
Total PE 4323
Alloc PE / Size 4322 / 16.88 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID 54jLnu-7q8K-JQAW-ml74-3OHQ-AoUo-Ujy8cS

[root@localhost ~]# vgextend centos /dev/sda5 将分区 sda5 转换为扩展分区
Volume group "centos" successfully extended
[root@localhost ~]# lvdisplay 查看当前的逻辑卷
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID 4jefaj-3aRS-gRyT-0dGo-OoWl-4NKu-vv5BDL
LV Write Access read/write
LV Creation host, time localhost, 2018-03-25 16:26:44 -0400
LV Status available
# open 1
LV Size 4.88 GiB
Current LE 1250
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 8192
    Block device 253:2

--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID OKT1PM-C7N5-W2r3-2TqW-KXvl-yTXB-KqnzoJ
LV Write Access read/write
LV Creation host, time localhost, 2018-03-25 16:26:44 -0400
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 这里可以看到“/”根分区的路径名称为:/dev/centos/root
LV Name root
VG Name centos
LV UUID b2tY0u-wTAN-Mnbw-hQnm-hAh5-OQLp-scCCuc
LV Write Access read/write
LV Creation host, time localhost, 2018-03-25 16:26:45 -0400
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 8192
    Block device 253:0

[root@localhost ~]# df -Ph
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 10G 979M 9.1G 10% /
devtmpfs 484M 0 484M 0% /dev
tmpfs 495M 0 495M 0% /dev/shm
tmpfs 495M 6.9M 488M 2% /run
tmpfs 495M 0 495M 0% /sys/fs/cgroup
/dev/sda2 1014M 125M 890M 13% /boot
/dev/mapper/centos-home 4.9G 33M 4.9G 1% /home
tmpfs 99M 0 99M 0% /run/user/0
[root@localhost ~]# vgdisplay 查看扩展后的卷组情况
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size <18.99 GiB
PE Size 4.00 MiB
Total PE 4861
Alloc PE / Size 4322 / 16.88 GiB
Free PE / Size 539 / <2.11 GiB 拓展多出的空间
VG UUID 54jLnu-7q8K-JQAW-ml74-3OHQ-AoUo-Ujy8cS

[root@localhost ~]# lvextend -L +2.0G /dev/centos/root 将新增的逻辑卷全部扩展到“/”分区中
Size of logical volume centos/root changed from 10.00 GiB (2560 extents) to 12.00 GiB (3072 extents).
Logical volume centos/root successfully resized.
[root@localhost ~]# df -Ph
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 10G 979M 9.1G 10% /
devtmpfs 484M 0 484M 0% /dev
tmpfs 495M 0 495M 0% /dev/shm
tmpfs 495M 6.9M 488M 2% /run
tmpfs 495M 0 495M 0% /sys/fs/cgroup
/dev/sda2 1014M 125M 890M 13% /boot
/dev/mapper/centos-home 4.9G 33M 4.9G 1% /home
tmpfs 99M 0 99M 0% /run/user/0
[root@localhost ~]# e2fsck -f /dev/centos/root 查看“/”根分区格式,并重新刷新根分区的大小
e2fsck 1.42.9 (28-Dec-2013)
/dev/centos/root is mounted.
e2fsck: Cannot continue, aborting.

[root@localhost ~]# resize2fs /dev/centos/root 若不是 xfs 我们可以用 resize2fs,这里报错了
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/centos/root
Couldn't find valid filesystem superblock.
[root@localhost ~]# df -Ph
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 10G 979M 9.1G 10% /
devtmpfs 484M 0 484M 0% /dev
tmpfs 495M 0 495M 0% /dev/shm
tmpfs 495M 6.9M 488M 2% /run
tmpfs 495M 0 495M 0% /sys/fs/cgroup
/dev/sda2 1014M 125M 890M 13% /boot
/dev/mapper/centos-home 4.9G 33M 4.9G 1% /home
tmpfs 99M 0 99M 0% /run/user/0

[root@localhost ~]# xfs_growfs /dev/centos/root 刷新根分区“/dev/centos/root”的容量
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=655360 blks

     =                       sectsz=512   attr=2, projid32bit=1
     =                       crc=1        finobt=0 spinodes=0

data = bsize=4096 blocks=2621440, imaxpct=25

     =                       sunit=0      swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2

     =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2621440 to 3145728
[root@localhost ~]# df -Ph
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 12G 979M 12G 8% /
devtmpfs 484M 0 484M 0% /dev
tmpfs 495M 0 495M 0% /dev/shm
tmpfs 495M 6.9M 488M 2% /run
tmpfs 495M 0 495M 0% /sys/fs/cgroup
/dev/sda2 1014M 125M 890M 13% /boot
/dev/mapper/centos-home 4.9G 33M 4.9G 1% /home
tmpfs 99M 0 99M 0% /run/user/0