拉取docker镜像的时候,镜像特别大,由于前期申请到云虚拟机硬盘资源只有100G,现在已经完全不够用,只能扩容。
查看硬盘使用情况,
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 26G 20G 6.6G 75% /
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 81M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 2.0G 188M 1.9G 10% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0
一、首先关闭虚拟机,硬盘扩容,扩容后,重启系统(centos)
[root@localhost ~]# fdisk -l
Disk /dev/vda3: 322.1 GB, 322122547200 bytes, 629145600 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: 0x000a44e0
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 4196351 2097152 83 Linux
/dev/vda2 4196352 62914559 29359104 8e Linux LVM
可以看到申请的300G已经到账,但是到账的300G还没有挂载,继续执行命令查看PV
(pv命令来自于英文词组”Pipe viewer“的缩写,其功能是用于管道查看器。pv命令能够通过管道显示数据处理进度信息,包含已经耗费的时间、完成百分比、当前速度、全部传输的数据以及预估剩余时间等信息。
原文链接:pv命令 – 管道查看器 – Linux命令大全(手册))
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda3(重点)
VG Name cl(重点)
PV Size <28.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 7167
Free PE 0
Allocated PE 7167
PV UUID 3KkOSC-vodd-plgR-0IlY-PjBm-lrJe-IiC0jA
二、创建新主分区
fdisk /dev/vda3
依次输入(n(新建分区)->p(创建一个主分区) ->Partition number (1-4)我这里是3:->回车(默认值)->回车(默认值)-> t(设置分区类型)—->8e(设置分区类型为8e) -> w(报错))
Command (m for help): n # 新建分区
Command action
e extended
p primary partition (1-4)
p # 创建一个主分区
Partition number (1-4): 3 #已经有/dev/sda1和/dev/sda2,所以从3开始
First cylinder (2611-6527, default 2611): #设置起始柱面,回车选择默认
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-6527, default 6527): #设置终止柱面,回车选择默认
Using default value 6527
Command (m for help): t #设置分区类型
Partition number (1-4): 3
Hex code (type L to list codes): 8e #设置分区类型为8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): w #保存
三.让内核立刻读取最新的分区表,而不需要重启系统
[root@localhost ~]# partprobe
[root@localhost ~]# fdisk -l
Disk /dev/vda: 322.1 GB, 322122547200 bytes, 629145600 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: 0x000a44e0
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 4196351 2097152 83 Linux
/dev/vda2 4196352 62914559 29359104 8e Linux LVM
/dev/vda3 62914560 629145599 283115520 8e Linux LVM
查看文件系统,/目录剩余空间没变。还需待扩展。
四、创建PV,扩容VG
[root@localhost ~]# pvcreate /dev/vda3
Physical volume "/dev/sda3" successfully created
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name cl
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
[root@localhost ~]# vgextend cl /dev/vda3 #( vgextend VG Name PV Name)
Volume group "/dev/vda3" successfully extended
再执行vgdisplay,可以看到VG已经增加到300G了。
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name cl
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
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 297.99 GiB
PE Size 4.00 MiB
Total PE 76286
Alloc PE / Size 69631 / <272.00 GiB
Free PE / Size 6655 / <26.00 GiB
VG UUID YwWvi2-WBW2-DhUM-RBId-idBn-kGMG-1TjRCT
五.扩容LV
每个PE大小4M,30G*1024/4= 7680. 最多有7680个PE。这个往大了敲,系统会提示可扩容的大小
[root@localhost ~]# lvresize -l 76790 /dev/mapper/cl-root(df -h 查看到的第一个)
刷新文件大小,报了新的错误
[root@localhost ~]# resize2fs /dev/mapper/cl-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/cl-root
Couldn't find valid filesystem superblock.
六、最终解决方法
检查 /dev/centos/root 文件系统,发现是xfs,如下;
[root@localhost ~]# mount |grep root /dev/mapper/cl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
xfs的文件系统重新定义大小用如下命令:
[root@localhost ~]# mount |grep root
/dev/mapper/cl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
[root@localhost ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=1703680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=6814720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3327, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 6814720 to 70777856
[root@localhost ~]#
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 270G 20G 251G 8% /
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 81M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 2.0G 188M 1.9G 10% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0