Add a new hard disk on ESXi
ESXi part
-
First shut down the virtual machine, then right-click the virtual machine on the web page and select Edit
-
Select "add hard disk" and "new standard hard disk" in the open window, and then enter the hard disk space you want to expand
-
Restart after saving
Ubuntu section
-
Ubuntu version here is 18.04
-
Open the console and check whether the linux system can find the attached non partitioned hard disk:
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
-
Create a new partition:
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):
- Note that SDA is the first SCSI hard disk, sdb is the second, and so on. Physical partitions use a and b numbers. Each physical hard disk has at most 4 primary logical partitions (or extended partitions). Therefore, in automatic partitions, the first logical partition number under extended partition sda2 starts from 5
- Enter m to view command help
- Enter p to view partition information:
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
- Enter n to create a new partition:
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.
Here, extended Represents an extended partition, primary Represents the primary partition. Create selected here extended,So there are other operations to be performed later. In addition, there is only one partition for the hard disk here, so enter`e`After, the rest of the inputs are "enter" by default.
- Enter p to view partition information again
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
- Enter w to save:
Command (m for help): w Information: Don't forget to update /etc/fstab, if necessary.
-
Format the newly created hard disk partition to ext3 format (later it is also changed to ext4 format)
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).
-
An error is prompted here because you cannot directly create an extended partition. Instead, you need to create a primary partition or create a logical partition on the extended partition
-
Operate on sdb again
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.
- Enter n to create a logical partition
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.
- Enter p to view partition information
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
There is one more sdb5 here. Next, you can operate on it
- Enter w to save
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
-
Format the newly created hard disk partition to ext4 format
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
-
Create a folder and set it as the mounting point of the hard disk
lemon@lemon-virtual-machine:~$ mkdir ~/storage_1
The mount point is selected to be placed in the home directory of the current user, because it is directly placed in the root directory. Root permission is required for access, which is troublesome
-
Mount sdb5 to ~/storage_1 down
lemon@lemon-virtual-machine:~$ sudo mount /dev/sdb5 ~/storage_1
ps if you want to cancel the mount
lemon@lemon-virtual-machine:~$ sudo unmount /dev/sdb5
-
Set the boot auto mount and edit the /etc/fstab file
lemon@lemon-virtual-machine:~$ vim /etc/fstab
- Append information at the end of the file
/dev/sdb5 /home/lemon/storage_1 ext4 defaults 0 0
As shown in the following figure
- Save exit
-
Restart the computer, check the partition space, and find that it has been mounted
lemon@lemon-virtual-machine:~$ df -l
Problems encountered
- When I was rebooting, I found that I could not start the machine. Using the recovery mode, I checked the /etc/fstab file and found that it was caused by writing defaults as default. Therefore, if I could not start the machine, I could delete the entry of the new condition first, and then look for the problem after starting the machine