Centos7扩展系统磁盘大小
系统盘大小不足,需要扩展系统盘大小。需要添加一块硬盘作为要使用的系统盘的扩展。
我的是原来sda就有空间没有分配,所以不用单独再加磁盘了,直接使用sda的未分配的空间。
如果是单独新增的一个磁盘例如 /dev/sdb 也是类似的操作,先 fdisk /dev/sdb 分区,然后再操作。
#
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 17G 131M 100% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.4M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 1014M 143M 872M 15% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
# fdisk -l /dev/vda
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b908c
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 41943039 19921920 8e Linux LVM
系统分区所在的磁盘/vda实际有107.4G,当前系统分区/dev/vda2(/dev/mapper/centos-root)只划分了17G,系统磁盘占用满了,需要扩展系统分区的大小。
fdisk /dev/vda
n
p
默认值直接回车
指定Last sector,分区大小,使用全部空间可默认回车,如果指定大小则填写大小(例如:+50G)
t (修改分区类型为8e,即LVM的ID号,和系统盘分区保持一致)
默认回车,针对最后添加的分区编进行修改
8e
w
保存后,查看一下分区信息
# fdisk -l |grep dev/vda
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 sectors
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 41943039 19921920 8e Linux LVM
/dev/vda3 41943040 209715199 83886080 8e Linux LVM
或者
# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b908c
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 41943039 19921920 8e Linux LVM
/dev/vda3 41943040 209715199 83886080 8e Linux LVM
修改后需要重新读取(同步分区表)
# partprobe
Warning: Unable to open /dev/sr1 read-write (Read-only file system). /dev/sr1 has been opened read-only.
pvcreate创建新的物理卷
# pvcreate /dev/vda3
WARNING: xfs signature detected on /dev/vda3 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/vda3.
Physical volume "/dev/vda3" successfully created.
pvdisplay查看物理卷
# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size <19.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID pN3jzg-fRso-L8qx-ZYWv-6yQN-UyNq-axIAiT
"/dev/vda3" is a new physical volume of "80.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vda3
VG Name
PV Size 80.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID i2YN0t-DKJ4-Eypq-Bm0w-AtYs-9v8C-ft3tnO
#
vgextend扩展卷分组
# vgextend centos /dev/vda3
lvdisplay查看逻辑卷
# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID gMfAEL-vuax-iRFB-ejHs-CnN3-7Bxs-Ep9jmd
LV Write Access read/write
LV Creation host, time localhost, 2019-04-29 09:50:34 +0800
LV Status available
# open 1
LV Size <17.00 GiB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID u2lvRO-dXnY-48hT-UMeI-WY2r-cIal-cXEZgp
LV Write Access read/write
LV Creation host, time localhost, 2019-04-29 09:50:35 +0800
LV Status available
# open 0
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
扩展逻辑卷 & 查看结果
我是全部扩展进来,如果只扩展一部分大小,则大小可以指定小于80G
lvextend -L +80G /dev/centos/root
或
lvextend -l +100%FREE /dev/centos/root
参数说明:
-L:指定逻辑卷的大小,单位为“kKmMgGtT”字节
-l:指定逻辑卷的大小(LE数)
# lvextend -L +80G /dev/centos/root
Insufficient free space: 20480 extents needed, but only 20479 available
# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 96.99 GiB (24830 extents).
Logical volume centos/root successfully resized.
扩展成功 df -h 查看无变化
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 12G 5.3G 69% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 1014M 143M 872M 15% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
还需要执行 xfs_growfs 才能显示变化
# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, 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 4455424 to 25425920
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 97G 12G 86G 13% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 1014M 143M 872M 15% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0