1、挂载存储块
进入 Storage Volumes 后台,将 Block Storage 附加到(Attached To) 对应的VPS
2、磁盘挂载具体步骤
1)挂载到系统之前,先用fdisk -l 命令查看磁盘的基本信息,执行命令后,信息如下:
[root@prtg ~]# fdisk -l Disk /dev/vda: 10 GiB, 10737418240 bytes, 20971520 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: 0x508858de Device Boot Start End Sectors Size Id Type /dev/vda1 * 2048 19920511 19918464 9.5G 83 Linux /dev/vda2 19920512 20969087 1048576 512M 82 Linux swap / Solaris Disk /dev/sda: 256 GiB, 274877906944 bytes, 536870912 sectors #这里可以看到256G的硬盘 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
2)先对对新添加的磁盘进行分区
使用命令分区:fdisk /dev/sda (默认添加的存储块的磁盘信息是/dev/sda)
[root@prtg ~]# fdisk /dev/sda #分区命令 Welcome to fdisk (util-linux 2.32.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 0xb12d8bec. Command (m for help): n #这里输入n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 2 First sector (2048-536870911, default 2048): 2048 #这里就默认即可 Last sector, +sectors or +size{K,M,G,T,P} (2048-536870911, default 536870911): #默认即可 Created a new partition 2 of type 'Linux' and of size 256 GiB. Command (m for help): w #这里输入w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
3)查看新的分区:运行命令 fdisk -l
。如果出现以下信息,说明已经成功创建了新分区
[root@prtg ~]# fdisk -l Disk /dev/vda: 10 GiB, 10737418240 bytes, 20971520 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: 0x508858de Device Boot Start End Sectors Size Id Type /dev/vda1 * 2048 19920511 19918464 9.5G 83 Linux /dev/vda2 19920512 20969087 1048576 512M 82 Linux swap / Solaris Disk /dev/sda: 256 GiB, 274877906944 bytes, 536870912 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: 0xb12d8bec Device Boot Start End Sectors Size Id Type /dev/sda2 2048 536870911 536868864 256G 83 Linux
4)查看数据块编号(开通邮件里也有)
ls /dev/disk/by-id/
执行命令效果:
[root@prtg ~]# ls /dev/disk/by-id/ ata-QEMU_DVD-ROM_QM00004 scsi-0BUYVM_SLAB_VOLUME-2898
假设看到的结果是scsi-0BUYVM_SLAB_VOLUME-2898,那么2898就是数据块的id,或者后台也能直接看到。
5)格式化
分区创建好之后,就需要格式化分区了,命令如下:
mkfs.ext4 -F /dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-2898
6)创建文件夹
创建挂载的文件夹。因为用宝塔,所以就挂载www目录了。
mkdir /www
7)挂载
挂载到www下面,当然你可以挂载到别的文件夹,这里就是以www为例。注意,如果这个目录有文件,那么文件都会被清除。
mount -o discard,defaults /dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-2898 /www
8)设置开机/重启自动挂载
echo '/dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-2898 /www ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab
9)如果出现错误:mkfs: failed to execute mkfs.ext4: No such file or directory
解决方法如下,因为需要安装e4fsprogs,Centos下安装命令如下:
yum install e4fsprogs -y
执行完成之后,就可以执行:mkfs.ext4 -F /dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-2898
10)最后执行命令df -h就可以看到硬盘已经挂载好了。
[root@prtg ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 224M 0 224M 0% /dev tmpfs 239M 0 239M 0% /dev/shm tmpfs 239M 6.4M 233M 3% /run tmpfs 239M 0 239M 0% /sys/fs/cgroup /dev/vda1 9.3G 893M 8.0G 10% / tmpfs 48M 0 48M 0% /run/user/0 /dev/sda 251G 61M 239G 1% /www
继续阅读