虚拟机linux系统扩容根分区,记VM虚拟机Ubuntu根分区扩容

使用fdisk

这里将/dev/sda2 由66G扩容到100G

# 查看当前存储空间占用情况

dev@dev:~$ df -h

Filesystem Size Used Avail Use% Mounted on

udev 1.9G 0 1.9G 0% /dev

tmpfs 393M 1.1M 392M 1% /run

/dev/sda2 65G 53G 9.0G 86% /

tmpfs 2.0G 0 2.0G 0% /dev/shm

tmpfs 5.0M 0 5.0M 0% /run/lock

tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup

tmpfs 393M 0 393M 0% /run/user/1000

关闭虚拟机后,在虚拟机硬盘设置界面进行虚拟硬盘的扩容操作。启动虚拟机进行系统内根分区扩容操作

dev@dev:~$ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.31.1).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

# 打印查看分区划分情况

Command (m for help): p

Disk /dev/sda: 100 GiB, 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

Disklabel type: gpt

Disk identifier: 0976B291-839E-463D-BD05-936253587234

Device Start End Sectors Size Type

/dev/sda1 2048 4095 2048 1M BIOS boot

/dev/sda2 4096 138409983 138405888 66G Linux filesystem

# 删除需要扩容的分区,这里是2,完成后不要执行 w 写入

Command (m for help): d

Partition number (1,2, default 2): 2

Command (m for help): p

Disk /dev/sda: 100 GiB, 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

Disklabel type: gpt

Disk identifier: 0976B291-839E-463D-BD05-936253587234

Device Start End Sectors Size Type

/dev/sda1 2048 4095 2048 1M BIOS boot

# 创建新分区,First和Last sector直接回车默认值,因为我是把剩下所有空闲的空间全部分配到扩容的新分区内

# 若是部分分配,请在Last sector输入对应的值

Command (m for help): n

Partition number (2-128, default 2):

First sector (4096-209715166, default 4096):

Last sector, +sectors or +size{K,M,G,T,P} (4096-209715166, default 209715166):

Created a new partition 2 of type 'Linux filesystem' and of size 100 GiB.

Partition '#2' contains a ext4 signature.

# No

Do you want to remove the signature? [Y]es/[N]o: n

# 查看新分区

Command (m for help): p

Disk /dev/sda: 100 GiB, 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

Disklabel type: gpt

Disk identifier: 0976B291-839E-463D-BD05-936253587234

Device Start End Sectors Size Type

/dev/sda1 2048 4095 2048 1M BIOS boot

/dev/sda2 4096 209715166 209711071 100G Linux filesystem

# 确认无误后 w 写入操作

Command (m for help): w

The partition table has been altered.

Syncing disks.

# 需要重启

dev@dev:~$ sudo reboot

# 执行扩容操作

dev@dev:~$ sudo resize2fs /dev/sda2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值