BuyVM 储存块挂载的方法

购买

请登录网站购买,此次不展开细说

管理

请登录控制面板,点击所购买的储存块,附加到已有的VPS上。
此次不展开细说。

储存块挂载

  • 使用 fdisk -l 查看储存块的基本信息

    root@localhost:~# fdisk -l
    Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 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: 0x21ca140c
    
    Device     Boot Start      End  Sectors Size Id Type
    /dev/vda1  *     2048 41940735 41938688  20G 83 Linux
    
    
    
    
    Disk /dev/sda: 512 GiB, 549755813888 bytes, 1073741824 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/sda 对新添加的储存块进行分区

    root@localhost:~# 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
    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 512 GiB. 
    Command (m for help): w    #这里输入w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    
  • 使用 fdisk -l 查看新的分区

    root@localhost:~# fdisk -l
    Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 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: 0x21ca140c
    
    Device     Boot Start      End  Sectors Size Id Type
    /dev/vda1  *     2048 41940735 41938688  20G 83 Linux
    
    
    
    
    Disk /dev/sda: 512 GiB, 549755813888 bytes, 1073741824 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
    
- 查看储存块ID

root@localhost:~# ls /dev/disk/by-id/
ata-QEMU_DVD-ROM_QM00004  scsi-0BUYVM_SLAB_VOLUME-12345

此处 scsi-0BUYVM_SLAB_VOLUME-xxxxx 为储存块ID,可以在控制面板 Storage Volumes 里,ID 查看到


- 格式化储存块

mkfs.ext4 -F /dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-12345
    
注意:请更改储存块ID为自己的


- 储存块挂载

mount -o discard,defaults /dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-12345 /gg

注意:请更改储存块ID为自己的 ,/gg 为系统中的目录,如果这个目录有文件,那么文件都会被清除。


- 设置开机/重启自动挂载

echo '/dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-12345 /gg ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab

测试是否挂载

- 输入 df -h 显示磁盘的相关信息

root@localhost:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            477M     0  477M   0% /dev
tmpfs           100M  3.9M   96M   4% /run
/dev/vda1        20G  915M   18G   5% /
tmpfs           497M     0  497M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           497M     0  497M   0% /sys/fs/cgroup
/dev/sda        504G  271G  208G  57% /gg

- 输入 reboot 重启 查看是否自动挂载