华为公有云
如何挂载公有云服务器磁盘
操作步骤
- 查看已挂载磁盘信息。
如果不显示磁盘信息,请执行“reboot”命令重启服务器。
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
- 在数据盘上创建分区。
fdisk /dev/vdb
输入“n”,按“Enter”,开始新建分区。
Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions)
输入P,按enter创建主分区,分区号为1,按“Enter”。
Select (default p): p Partition number (1-4, default 1): 1
连续两次“回车”,选择默认初始与截止磁柱编号
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.
输入“p”,按“Enter”,查看新建分区的详细信息。
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
输入“w”,按“Enter”,将分区结果写入分区表中。
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
- 设置新建分区文件系统格式。
mkfs.ext4 /dev/vdb1
格式化需要等待一段时间,请观察系统运行状态,不要退出。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
- 挂载分区。
- 在根目录下创建“/opt”目录。
如果根目录下已经存在“opt”目录,可以不用创建。
mkdir opt
- 将“/dev/vdb1”挂载到“/opt”目录。
mount /dev/vdb1 /opt
df -lh|grep /opt
/dev/vdb1 591G 1.2G 590G 1% /opt
- 在根目录下创建“/opt”目录。
- 设置开机自动挂载磁盘。
如果您需要在云服务器系统启动时自动挂载磁盘,不能采用在“/etc/fstab”直接指定“/dev/vdb1”的方法,因为云中设备的顺序编码在关闭或者开启云服务器过程中可能发生改变,例如“/dev/vdb1”可能会变成“/dev/vdb2”。推荐使用UUID来配置自动挂载数据盘。
- 查询磁盘分区的UUID。
blkid /dev/vdb1
/dev/vdb1: UUID="1851e23f-1c57-40ab-86bb-5fc5fc606ffa" TYPE="ext4"
- 配置自动挂载。
vi /etc/fstab
将原有的“/opt”挂载信息注释掉,并在文件末尾增加如下内容。
UUID=1851e23f-1c57-40ab-86bb-5fc5fc606ffa /opt ext4 defaults 0 2
- 查询磁盘分区的UUID。
- 执行“reboot”命令,重启服务器。
重启成功后,查看分区是否正常挂载。