Bboysoul's Blog

首页 公告 RSS

vmware磁盘扩容

July 21, 2020 本文有 725 个字 需要花费 2 分钟阅读

简介

早上巡查监控的时候发现有一台虚拟机的磁盘容量不够了,因为数据都是有用的,所以准备扩容磁盘

操作

首先创建一个测试虚拟机

之后格式化磁盘

fdisk /dev/sdb

欢迎使用 fdisk (util-linux 2.23.2)
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0xd70609ad 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):o
使用磁盘标识符 0x24f7adcf 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1)起始 扇区 (2048-33554431,默认为 2048)将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-33554431,默认为 33554431)将使用默认值 33554431
分区 1 已设置为 Linux 类型,大小设为 16 GiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

之后创建文件系统

mkfs.ext4 /dev/sdb1

挂载

mount /dev/sdb1 /data/

创建测试文件

touch /data/helloworld

查看文件系统大小

/dev/sdb1 16G 45M 15G 1% /data

之后修改vmware上磁盘的大小为50g,然后重启系统

fdisk -l

发现磁盘大小已经改变

磁盘 /dev/sdb:53.7 GB, 53687091200 字节,104857600 个扇区

之后就是进行两步走,扩展分区和扩展文件系统

首先扩展分区

parted /dev/sdb

看下剩余的磁盘

print free

扩展第一个分区

resizepart 1

之后输入相关信息,具体如下

(parted) print free
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  标志
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  53.7MB  52.7MB  primary  ext4
        53.7MB  53.7GB  53.6GB           Free Space

(parted) resizepart 1
结束点?  [53.7MB]? 53.7GB
(parted) print free
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  标志
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  53.7GB  53.7GB  primary  ext4

(parted) quit

之后检查文件系统

e2fsck -f /dev/sdb1

扩展文件系统

resize2fs /dev/sdb1

挂载

mount /dev/sdb1 /data/

查看大小

df -h

/dev/sdb1 50G 52M 47G 1% /data

查看之前创建的文件是否存在

ls -al /data/

总用量 20
drwxr-xr-x   3 root root  4096 7月  21 11:38 .
dr-xr-xr-x. 18 root root   256 6月  30 15:33 ..
-rw-r--r--   1 root root     0 7月  21 11:37 helloworld
drwx------   2 root root 16384 7月  21 11:37 lost+found

欢迎关注我的博客www.bboy.app

Have Fun


Tags:

本站总访问量 本站总访客数