Public Cloud Server
How Do I Mount a Hard Disk to a Public Cloud Server?
Procedure
- View information about mounted hard disks.
If the disk information is not displayed, run the reboot command to restart the server.
fdisk -l
Disk /dev/vdb: 600 GiB, 644245094400 bytes, 1258291200 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
- Create a partition on the data disk.
fdisk /dev/vdb
Enter n and press Enter to start partition creation.
Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions)
Enter P and press Enter to create the primary partition numbered 1. Then, press Enter.
Select (default p): p Partition number (1-4, default 1): 1
Press Enter twice and select the default numbers of the first and last sectors.
First sector (2048-1258291199, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-1258291199, default 1258291199): Created a new partition 1 of type 'Linux' and of size 600 GiB.
Enter p and press Enter to view detailed information about the created partition.
Command (m for help): p Disk /dev/vdb: 600 GiB, 644245094400 bytes, 1258291200 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: 0x611f73db Device Boot Start End Sectors Size Id Type /dev/vdb1 2048 1258291199 1258289152 600G 83 Linu
Enter w and press Enter to write the new partition to the partition table.
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
- Set the file system format for the new partition.
mkfs.ext4 /dev/vdb1
Formatting takes a period of time. Observe the system running status and do not exit.Creating filesystem with 104857344 4k blocks and 26214400 inodes Filesystem UUID: 385f8294-b234-4b0f-8be9-f2738c4b5909 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
- Mount the partition.
- Create the /opt directory in the root directory.
If the opt directory already exists in the root directory, skip this step.
mkdir opt
- Mount /dev/vdb1 to the /opt directory.
mount /dev/vdb1 /opt
df -lh|grep /opt
/dev/vdb1 591G 1.2G 590G 1% /opt
- Create the /opt directory in the root directory.
- Set automount of hard disk upon power-on.
If you want the hard disk to be automatically mounted when the cloud server system starts, do not directly specify /dev/vdb1 under /etc/fstab. This is because the number of a device may change on the cloud when the cloud server is started or stopped. For example, /dev/vdb1 may change to /dev/vdb2. You are advised to configure automount of data disk based on the UUID.
- Query the UUID of the disk partition.
blkid /dev/vdb1
/dev/vdb1: UUID="1851e23f-1c57-40ab-86bb-5fc5fc606ffa" TYPE="ext4"
- Configure automount.
vi /etc/fstab
Comment out the existing /opt mounting information, and add the following content at the end of the file:
UUID=1851e23f-1c57-40ab-86bb-5fc5fc606ffa /opt ext4 defaults 0 2
- Query the UUID of the disk partition.
- Run the reboot command to restart the server.
After the server is successfully restarted, check whether the partition is correctly mounted.