在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_1ps 如果想取消掛載
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 如下圖所示

- 保存退出
-
重啟計算機,查看分區空間,發現已經掛載上了
lemon@lemon-virtual-machine:~$ df -l

遇到的問題
- 我在重啟的時候發現無法開機,使用恢復模式,查看
/etc/fstab文件,發現是將defaults寫成了default造成的,所以如果無法開機,可以先刪除新條件的條目,然后開機以后再尋找問題
