我的操作系统是centos7,硬盘使用的是vsan。
我把硬盘从40G扩容到100G。但是df -h后发现linux文件系统并没有识别到这新增加的60G。
[hyongtao@hyt-centos7-wdc ~]$ 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 39G 0 part
├─centos-root 253:0 0 37G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
[hyongtao@hyt-centos7-wdc ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 36K 7.8G 1% /dev/shm
tmpfs 7.8G 18M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 37G 7.9G 30G 22% /
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 1.6G 32K 1.6G 1% /run/user/1000
tmpfs 1.6G 0 1.6G 0% /run/user/1002
我们观察一下sda,发现还有整整60G没有识别到。
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 39G 0 part
考虑新增加一个分区,把剩下60G用上。主要使用命令fdisk。
[hyongtao@hyt-centos7-wdc ~]$ sudo fdisk /dev/sda
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): m
Command action
p print the partition table
n add a new partition
w write table to disk and exit (省略若干help信息,不同系统不一样。)
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 (83886080-209715199, default 83886080):
Using default value 83886080
Last sector, +sectors or +size{K,M,G} (83886080-209715199, default 209715199):
Using default value 209715199
Partition 3 of type Linux and of size 60 GiB is set
Command (m for help): p
Disk /dev/sda: 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: 0x000ac2dc
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
/dev/sda3 83886080 209715199 62914560 83 Linux (识别到了sda3)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8) (实测centos8上可以立即生效,不需要重启。)
Syncing disks.
[hyongtao@hyt-centos7-wdc ~]$
重启后,lsblk能识别到新的sda3,但是df-h还是没有识别到新的空间。
[hyongtao@hyt-centos7-wdc ~]$ 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 39G 0 part
│ ├─centos-root 253:0 0 37G 0 lvm /
│ └─centos-swap 253:1 0 2G 0 lvm [SWAP]
└─sda3 8:3 0 60G 0 part (新加的sd3,60G)
sr0 11:0 1 1024M 0 rom
[hyongtao@hyt-centos7-wdc ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 9.8M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 37G 7.9G 30G 22% /
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 1.6G 20K 1.6G 1% /run/user/1000
tmpfs 1.6G 0 1.6G 0% /run/user/1002
随后的步骤可以参考这篇非常详细的博文:https://www.redhat.com/sysadmin/resize-lvm-simple ,以下内容是这篇博文的简单复现。
使用pvcreate和vgextend创建和扩大对应的物理卷
[hyongtao@hyt-centos7-wdc ~]$ sudo pvcreate /dev/sda3
[sudo] password for hyongtao:
Physical volume "/dev/sda3" successfully created.
[hyongtao@hyt-centos7-wdc ~]$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <39.00g 4.00m
[hyongtao@hyt-centos7-wdc ~]$ sudo vgextend centos /dev/sda3
Volume group "centos" successfully extended
[hyongtao@hyt-centos7-wdc ~]$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz--n- 98.99g 60.00g
使用lvextend扩容逻辑卷
[hyongtao@hyt-centos7-wdc ~]$ sudo lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from 36.99 GiB (9470 extents) to 96.99 GiB (24830 extents).
Logical volume centos/root successfully resized.
使用xfs_growfs命令对xfs文件系统进行自动增容。
[hyongtao@hyt-centos7-wdc ~]$ sudo xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2424320 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=9697280, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4735, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 9697280 to 25425920
最后用df -h检查磁盘。
[hyongtao@hyt-centos7-wdc ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 9.8M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 97G 7.9G 90G 9% / (生效了)
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 1.6G 20K 1.6G 1% /run/user/1000
tmpfs 1.6G 0 1.6G 0% /run/user/1002
我对linux内核几乎毫无了解,这些东西都是这个大佬教我的,https://new.qq.com/rain/a/20201227A06AIT00 感谢,respect。现在做个记录怕忘了。
TODO:回头再鼓捣鼓捣这几个命令到底搞了什么鬼:pvcreate和vgextend和lvextend和xfs_growfs。还有物理卷和逻辑卷分别是什么意思?
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




