在ESXi上添加新硬盘

ESXi部分

  • 首先将虚拟机关机,然后在网页端右键该虚拟机,选择“编辑”
  • 在打开的窗口中选择“添加硬盘”、“新标准硬盘”,然后输入想要扩充的硬盘空间大小
  • 保存后,重新开机

Ubuntu部分

  • 此处Ubuntu版本为18.04
  • 打开控制台,查看linux系统是否能找到挂载的未分区硬盘:
lemon@lemon-virtual-machine:~$ sudo hdparm -I /dev/sdb

/dev/sdb:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

ATA device, with non-removable media
Standards:
	Likely used: 1
Configuration:
	Logical		max	current
	cylinders	0	0
	heads		0	0
	sectors/track	0	0
	--
	Logical/Physical Sector size:           512 bytes
	device size with M = 1024*1024:           0 MBytes
	device size with M = 1000*1000:           0 MBytes 
	cache/buffer size  = unknown
Capabilities:
	IORDY not likely
	Cannot perform double-word IO
	R/W multiple sector transfer: not supported
	DMA: not supported
	PIO: pio0
  • 创建新的分区:
lemon@lemon-virtual-machine:~$ sudo fdisk /dev/sdb

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.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x19cf3d7f.

Command (m for help):
  • 注意,sda是第一块SCSI硬盘,sdb第二块,以此类推。物理分区使用a、b编号,每个物理硬盘最多有4个主逻辑分区(或扩展分区),所以自动分区中,扩展分区sda2下第一个逻辑分区编号从5开始
  • 输入m可以查看命令帮助
  • 输入p查看分区信息:
Command (m for help): p
  Disk /dev/sdb: 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: dos
  Disk identifier: 0x19cf3d7f
  • 输入n创建新分区:
Command (m for help): n
 Partition type
    p   primary (0 primary, 0 extended, 4 free)
    e   extended (container for logical partitions)
 Select (default p): e
 Partition number (1-4, default 1): 
 First sector (2048-209715199, default 2048): 
 Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199): 
  
 Created a new partition 1 of type 'Extended' and of size 100 GiB.
这里,extended表示扩展分区,primary表示主分区。此处选择了创建extended,所以后面还要进行其他操作。而且,此处只对该硬盘进行一个分区的操作,所以在输入`e`后,其余输入都是回车默认。
  • 输入p再次查看分区信息
Command (m for help): p
  Disk /dev/sdb: 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: dos
  Disk identifier: 0x19cf3d7f

  Device     Boot Start       End   Sectors  Size Id Type
  /dev/sdb1        2048 209715199 209713152  100G  5 Extended
  • 输入w保存:
Command (m for help): w
  Information: Don't forget to update /etc/fstab, if necessary.
  • 将新创建的硬盘分区格式化为ext3格式(后面也改成了ext4格式)
lemon@lemon-virtual-machine:~$ sudo mkfs -t ext3 /dev/sdb1
mke2fs 1.44.1 (24-Mar-2018)
Found a dos partition table in /dev/sdb1
Proceed anyway? (y,N) y
mkfs.ext4: inode_size (128) * inodes_count (0) too big for a
	filesystem with 0 blocks, specify higher inode_ratio (-i)
	or lower inode count (-N).
  • 这里提示报错了,原因是不能直接建立一个扩展分区,需要一个主分区,或者是在扩展分区上建立一个逻辑分区
  • 再次对sdb进行操作
lemon@lemon-virtual-machine:~$ sudo fdisk /dev/sdb

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.
  • 输入n创建一个逻辑分区
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (4096-209715199, default 4096): 
Last sector, +sectors or +size{K,M,G,T,P} (4096-209715199, default 209715199): 

Created a new partition 5 of type 'Linux' and of size 100 GiB.
  • 输入p查看分区信息
Command (m for help): p

Disk /dev/sdb: 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: dos
Disk identifier: 0x19cf3d7f

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 209715199 209713152  100G  5 Extended
/dev/sdb5        4096 209715199 209711104  100G 83 Linux

此处多了一个sdb5,接下来就对其进行操作

  • 输入w保存
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
  • 将新创建的硬盘分区格式化为ext4格式
lemon@lemon-virtual-machine:~$ sudo mkfs -t ext4 /dev/sdb5
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 26213888 4k blocks and 6553600 inodes
Filesystem UUID: 1347b2f3-872f-4692-b79c-b14038dd0e65
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done
  • 创建一个文件夹,将其设为硬盘的挂载点
lemon@lemon-virtual-machine:~$ mkdir ~/storage_1

此处选择了将挂载点置于当前用户的主目录下,因为直接放在根目录下,访问的时候需要root权限,比较麻烦

  • 将sdb5挂载到~/storage_1下
lemon@lemon-virtual-machine:~$ sudo mount /dev/sdb5 ~/storage_1

ps 如果想取消挂载

lemon@lemon-virtual-machine:~$ sudo unmount /dev/sdb5
  • 设置开机自动挂载,编辑/etc/fstab文件
lemon@lemon-virtual-machine:~$ vim /etc/fstab
  • 在文件的最后追加信息
/dev/sdb5            /home/lemon/storage_1     ext4  defaults  0  0

如下图所示

ESXI怎么硬盘虚拟化 esxi 加硬盘_3d

  • 保存退出
  • 重启计算机,查看分区空间,发现已经挂载上了
lemon@lemon-virtual-machine:~$ df -l

ESXI怎么硬盘虚拟化 esxi 加硬盘_Ubuntu_02

遇到的问题

  • 我在重启的时候发现无法开机,使用恢复模式,查看/etc/fstab文件,发现是将defaults写成了default造成的,所以如果无法开机,可以先删除新条件的条目,然后开机以后再寻找问题

参考资料

  • centos 7 新增硬盘挂载分区,及扩容
  • Ubuntu加挂新硬盘全套解决方案
  • Linux 格式化扩展分区(Extended)
  • Centos7.6进入挂载硬盘后,进入应急模式(emergency mode)而非图形模式解决方法