如何给centos系统扩展磁盘分区
发表于:2024-11-24 作者:热门IT资讯网编辑
编辑最后更新 2024年11月24日,本篇内容主要讲解"如何给centos系统扩展磁盘分区",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"如何给centos系统扩展磁盘分区"吧!问题/故障/场景
本篇内容主要讲解"如何给centos系统扩展磁盘分区",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"如何给centos系统扩展磁盘分区"吧!
问题/故障/场景/需求
eve-ng的虚拟机ova的硬盘只有38g,需要增加空间,在vmware直接扩展硬盘后,重启系统,使用fdisk -l可以看到硬盘扩大了,但文件系统并没有扩大,还需要将这些新增的空间扩展分配到某个文件系统才行。下面记录了整个扩展过程
解决方法/步骤
在vm里扩大磁盘到250g重启系统后,查看当前的文件系统的情况
root@eve-ng:~# df -hfilesystem size used avail use% mounted onudev 7.9g 0 7.9g 0% /devtmpfs 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/shmtmpfs 5.0m 0 5.0m 0% /run/locktmpfs 7.9g 0 7.9g 0% /sys/fs/cgroup/dev/sda1 472m 83m 365m 19% /bootroot@eve-ng:~# fdisk -l...省略部分内容disk /dev/sda: 250 gib, 268435456000 bytes, 524288000 sectors //可以看到已经有250g了units: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisklabel type: dosdisk identifier: 0x3e3ca055device 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 lvmdisk /dev/mapper/eve--ng--vg-root: 38.6 gib, 41406169088 bytes, 80871424 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisk /dev/mapper/eve--ng--vg-swap_1: 980 mib, 1027604480 bytes, 2007040 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytes//下面执行分区root@eve-ng:~# fdisk /dev/sdawelcome 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): npartition type p primary (1 primary, 1 extended, 2 free) l logical (numbered from 5)select (default p): ppartition number (3,4, default 3): 3first 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): tpartition number (1-3,5, default 5): 3 3partition type (type l to list all types): 8echanged type of partition 'linux' to 'linux lvm'.command (m for help): wthe partition table has been altered.calling ioctl() to re-read partition table.re-reading the partition table failed.: device or resource busythe 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:~# rebootroot@eve-ng:~# pvcreate /dev/sda3 physical volume "/dev/sda3" successfully createdroot@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-q8zxkiroot@eve-ng:~# vgextend eve-ng-vg /dev/sda3 volume group "eve-ng-vg" successfully extendedroot@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-q8zxkiroot@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 -hfilesystem size used avail use% mounted onudev 7.9g 0 7.9g 0% /devtmpfs 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/shmtmpfs 5.0m 0 5.0m 0% /run/locktmpfs 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/rootresize2fs 1.42.13 (17-may-2015)filesystem at /dev/eve-ng-vg/root is mounted on /; on-line resizing requiredold_desc_blocks = 3, new_desc_blocks = 16the filesystem on /dev/eve-ng-vg/root is now 65159168 (4k) blocks long.root@eve-ng:~# df -hfilesystem size used avail use% mounted onudev 7.9g 0 7.9g 0% /devtmpfs 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/shmtmpfs 5.0m 0 5.0m 0% /run/locktmpfs 7.9g 0 7.9g 0% /sys/fs/cgroup/dev/sda1 472m 83m 365m 19% /boot
到此,相信大家对"如何给centos系统扩展磁盘分区"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!