虚拟机Linux磁盘扩容(扩展根目录“/“分区容量) 您所在的位置:网站首页 gparted扩容linux根目录 虚拟机Linux磁盘扩容(扩展根目录“/“分区容量)

虚拟机Linux磁盘扩容(扩展根目录“/“分区容量)

2024-06-15 05:20| 来源: 网络整理| 查看: 265

磁盘挂载如下图的可以按照一、扩展根目录分区的大小。

一、系统分区未使用LVM

1、有人创建虚拟机时没有选择自动配置硬盘(即官方推荐的默认硬盘设置),例如没有选LVM,选了标准分区,会导致系统创建的磁盘没有使用LVM逻辑卷管理。

2、这种情况下扩展磁盘可以挂载到新的linux目录,也可以选择扩展到根目录”/“的分区。扩展到根目录分区的方式如下:

虚拟机-设置-硬盘,输入想扩展到的大小-点击扩展。

3、查看磁盘情况

成功后启动虚拟机进入,执行分区操作命令fdisk -l,sda盘已经有40G。df -h查看磁盘情况,发现是磁盘的/dev/sda3分区挂载到了根目录/下。

如果创建虚拟机选择LVM,创建完的linux系统磁盘情况应该如下图,是该逻辑卷挂载到了根目录/下。

4、重建sda3分区

sda盘容量已经扩展了,下面给sda盘创建新分区。ls /dev查看sda有哪几个分区,默认是到sda3。刚好我们要扩展的也是挂载到根目录下的sda3。(如果操作过分区有sda4的请甄选方案)

方式为先删除sda3分区,再添加sda3分区。添加时扩大sda3的扇区,这样sda3分区就会把扩展的部分添加进去。我们以添加5G为例,使用分区操作命令fdisk操作磁盘/dev/sda:

[root@localhost ~]# 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 ##输入m,查看帮助 Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): d ##输入d,删除分区 Partition number (1-3, default 3): 3 ##输入3,删除sda3分区 Partition 3 is deleted ##sda3被成功删除 Command (m for help): n ##输入n,添加分区 Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p ##输入p,添加的分区为主分区 Partition number (3,4, default 3): 3 ##输入3,添加sda3分区 First sector (6293504-83886079, default 6293504): ##回车,起始扇使用默认值 Using default value 6293504 Last sector, +sectors or +size{K,M,G} (6293504-83886079, default 83886079): +25G ##由于我们删除过sda3分区了,sda3现在为0G,我们在之前20G的基础上扩展5G,所以输入+25G Partition 3 of type Linux and of size 25 GiB is set Command (m for help): w ##输入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) Syncing disks.

5、重启

添加好之后需要重启该服务器,新分区才会生效。重启后/dev/sda3分区的范围应该已经变大了。

6、扩容

查看sda3分区是xfs类型

因此可以执行因此可以xfs_growfs /dev/sda3对该分区进行扩容

7、查看挂载到根目录下的/dev/sda3分区扩容成功,变为25G



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有