怎样给centos系统扩展磁盘分区
admin
2023-02-22 12:40:05
0

问题/故障/场景/需求

eve-ng的虚拟机ova的硬盘只有38G,需要增加空间,在vmware直接扩展硬盘后,重启系统,使用fdisk -l可以看到硬盘扩大了,但文件系统并没有扩大,还需要将这些新增的空间扩展分配到某个文件系统才行。下面记录了整个扩展过程

解决方法/步骤

  1. 在VM里扩大磁盘到250G重启系统后,查看当前的文件系统的情况
root@eve-ng:~# df -h
Filesystem                    Size  Used Avail Use% Mounted on
udev                          7.9G     0  7.9G   0% /dev
tmpfs                         1.6G   19M  1.6G   2% /run
/dev/mapper/eve--ng--vg-root   38G   13G   23G  36% /
tmpfs                         7.9G     0  7.9G   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                         7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sda1                     472M   83M  365M  19% /boot

root@eve-ng:~# fdisk -l
...省略部分内容
Disk /dev/sda: 250 GiB, 268435456000 bytes, 524288000 sectors   //可以看到已经有250G了
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3e3ca055

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048   999423   997376  487M 83 Linux
/dev/sda2       1001470 83884031 82882562 39.5G  5 Extended
/dev/sda5       1001472 83884031 82882560 39.5G 8e Linux LVM

Disk /dev/mapper/eve--ng--vg-root: 38.6 GiB, 41406169088 bytes, 80871424 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 /dev/mapper/eve--ng--vg-swap_1: 980 MiB, 1027604480 bytes, 2007040 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

//下面执行分区
root@eve-ng:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (999424-524287999, default 999424): 83884032 //注意,这里是之前分配的最后一块(sda5 end)加一(83884031+1)
Last sector, +sectors or +size{K,M,G,T,P} (83884032-524287999, default 524287999): //注意看这是不是最后一块

Created a new partition 3 of type 'Linux' and of size 210 GiB.

Command (m for help): t
Partition number (1-3,5, default 5): 3 3
Partition type (type L to list all types): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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).

root@eve-ng:~# reboot

root@eve-ng:~# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
root@eve-ng:~# vgdisplay
  --- Volume group ---
  VG Name               eve-ng-vg
  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               39.52 GiB
  PE Size               4.00 MiB
  Total PE              10117
  Alloc PE / Size       10117 / 39.52 GiB
  Free  PE / Size       0 / 0
  VG UUID               EvwUbc-nfsg-dHqA-znxB-U3gv-V782-Q8ZxkI

root@eve-ng:~# vgextend eve-ng-vg /dev/sda3
  Volume group "eve-ng-vg" successfully extended
root@eve-ng:~# vgdisplay
  --- Volume group ---
  VG Name               eve-ng-vg
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  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               249.52 GiB
  PE Size               4.00 MiB
  Total PE              63877
  Alloc PE / Size       10117 / 39.52 GiB
  Free  PE / Size       53760 / 210.00 GiB
  VG UUID               EvwUbc-nfsg-dHqA-znxB-U3gv-V782-Q8ZxkI

root@eve-ng:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/eve-ng-vg/root
  LV Name                root
  VG Name                eve-ng-vg
  LV UUID                ktUpR0-VpqS-rJJv-a1FC-u6Gd-U8yN-2WYQ53
  LV Write Access        read/write
  LV Creation host, time eve-ng, 2018-03-21 02:25:21 +0200
  LV Status              available
  # open                 1
  LV Size                38.56 GiB
  Current LE             9872
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

//扩展逻辑卷
root@eve-ng:~# lvextend -l +100%FREE /dev/eve-ng-vg/root
  Size of logical volume eve-ng-vg/root changed from 38.56 GiB (9872 extents) to 248.56 GiB (63632 extents).
  Logical volume root successfully resized.

root@eve-ng:~# df -h
Filesystem                    Size  Used Avail Use% Mounted on
udev                          7.9G     0  7.9G   0% /dev
tmpfs                         1.6G   19M  1.6G   2% /run
/dev/mapper/eve--ng--vg-root   38G   13G   23G  36% /
tmpfs                         7.9G     0  7.9G   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                         7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sda1                     472M   83M  365M  19% /boot

//在线扩容,要先查看当前的文件系统的类型,可以通过cat /etc/fstab来查看
root@eve-ng:~# resize2fs /dev/eve-ng-vg/root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/eve-ng-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 16
The filesystem on /dev/eve-ng-vg/root is now 65159168 (4k) blocks long.

root@eve-ng:~# df -h
Filesystem                    Size  Used Avail Use% Mounted on
udev                          7.9G     0  7.9G   0% /dev
tmpfs                         1.6G   19M  1.6G   2% /run
/dev/mapper/eve--ng--vg-root  245G   13G  222G   6% /
tmpfs                         7.9G     0  7.9G   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                         7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sda1                     472M   83M  365M  19% /boot

参考

在线扩容

使用 resize2fs或xfs_growfs 对挂载目录在线扩容

  • resize2fs 针对文件系统ext2 ext3 ext4
  • xfs_growfs 针对文件系统xfs

相关内容

热门资讯

谷歌被罚9亿欧元后,特朗普称欧... 当地时间7月23日,欧盟委员会指控美国谷歌公司违反欧盟《数字市场法》,对其处以8.9亿欧元罚款。这一...
14对14,中国反击欧盟,干净... 对于欧盟的指手画脚,中国第一时间反击了。14:14。干净利落,来而不往非礼也。国际博弈,从来如此:没...
风未到,人已行!凌晨不眠!一场... 7月24日晚,台风“红霞”持续逼近,市应急管理局五楼会议室灯火通明,市应急管理局党委书记、局长李见秋...
省自然资源厅部署12号台风“红... 受今年第12号台风“红霞”影响,我省中部和南部地区有一轮强降雨过程,部分地区有较高的地质灾害风险。自...
长虹美菱获得发明专利授权:“一... 证券之星消息,根据天眼查APP数据显示长虹美菱(000521)新获得一项发明专利授权,专利名为“一种...
女童毕业照走光维权反遭辱骂,是... 毛乐然(南京传媒学院)杭州一家摄影机构拍摄的女童毕业照出现走光问题,家长维权反遭恶语相向,令人愤慨。...
给“AI”发身份证!国内首个智... 《人工智能 智能体互联》系列国家标准应用推进专题会议近日在北京中关村展示中心召开。现场发布GB/Z1...
探秘科技殿堂 点亮科学梦想—中... 为拓宽青少年科学视野,丰富课外实践内容,激发学生科技创新思维与探索精神,7月23日,原州区中河乡中心...
小米申请音频处理方法专利,能够... 国家知识产权局信息显示,北京小米移动软件有限公司申请一项名为“音频处理方法、装置、电子设备、存储介质...
中纪委最新通报:上半年立案省部... △图1:全国纪检监察机关处分人员按职级划分图△图2:全国纪检监察机关运用“四种形态”占比图2026年...