怎样给centos系统扩展磁盘分区的实现方法
程序员文章站
2022-06-02 13:00:12
问题/故障/场景/需求
eve-ng的虚拟机ova的硬盘只有38g,需要增加空间,在vmware直接扩展硬盘后,重启系统,使用fdisk -l可以看到硬盘扩大了,但文件系统并没有...
问题/故障/场景/需求
eve-ng的虚拟机ova的硬盘只有38g,需要增加空间,在vmware直接扩展硬盘后,重启系统,使用fdisk -l可以看到硬盘扩大了,但文件系统并没有扩大,还需要将这些新增的空间扩展分配到某个文件系统才行。下面记录了整个扩展过程
解决方法/步骤
在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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: 我是一个公主