Esxi虚拟机一次错误的扩容记录

2020-06-07  本文已影响0人  阿乐_822e

原有磁盘空间为100G,在vsphere中为其修改到200G后,重新开机,执行fdisk命令时,由于不熟悉扩容过程,先删除了sda2分区,再新建分区,将所有空间都分配给它。

[root@k8s_templ ~]# fdisk   -l /dev/sda2
磁盘 /dev/sda2:213.7 GB, 213673574400 字节,417331200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

此时,虽然磁盘空间看着增加了,但多余的空间和原有的空间混在一起,无法格式化,因此也无法使用了。

[root@k8s_templ ~]#  mkfs.ext4 /dev/sda2
mke2fs 1.42.9 (28-Dec-2013)
/dev/sda2 is apparently in use by the system; will not make a 文件系统 here!

解决办法:重新划分分区。 按照原样将重建sda2分区,并新建sda3分区。(没有输入的都是使用推荐值)

[root@k8s_templ ~]# fdisk   /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
......
命令(输入 m 获取帮助):d
分区号 (1,2,默认 2):
分区 2 已删除

命令(输入 m 获取帮助):n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): 
Using default response p
分区号 (2-4,默认 2):
起始 扇区 (2099200-419430399,默认为 2099200):
将使用默认值 2099200
Last 扇区, +扇区 or +size{K,M,G} (2099200-419430399,默认为 419430399):209715199   # 这里的结束扇区位置一定不要错!
分区 2 已设置为 Linux 类型,大小设为 99 GiB

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

命令(输入 m 获取帮助):p

磁盘 /dev/sda:214.7 GB, 214748364800 字节,419430400 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e0085

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   209715199   103808000   83  Linux
/dev/sda3       209715200   419430399   104857600   83  Linux

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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@k8s_templ ~]# partprobe

现在,格式化sda3分区,sda2不用格式化!

[root@k8s_templ ~]# mkfs.ext4 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
...... 
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成   

接下来的操作就很简单了,参考https://www.jianshu.com/p/1f5c3b10ffaa 这篇文章操作,不再赘述。
这里仅帖出最后结果

[root@k8s_templ ~]#  df -hl /
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root  150G  2.3G  148G    2% /
[root@k8s_templ ~]# 

可以看到100G空间已经被成功添加了!

上一篇下一篇

猜你喜欢

热点阅读