天天看點

騰訊雲伺服器挂載雲硬碟

騰訊雲伺服器挂載雲硬碟

1、到騰訊雲伺服器購買一塊雲硬碟,然後直接挂載到你的伺服器下就可以了,如果伺服器不能識别,請看​​部分存量雲伺服器無法識别彈性雲盤的解決方法​​

2、挂載完雲硬碟之後,雲硬碟預設處于未加載狀态,使用df -h指令可以看見伺服器中硬碟的加載狀況,如下:

ubuntu@VM-164-254-ubuntu:/$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            414M     0  414M   0% /dev
tmpfs            87M  9.4M   78M  11% /run
/dev/vda1        20G  4.5G   15G  24% /
tmpfs           433M   48K  433M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           433M     0  433M   0% /sys/fs/cgroup
tmpfs            87M     0   87M   0% /run/user/500
ubuntu@VM-164-254-ubuntu:/$ cd etc/      

,沒有相關硬碟資訊,使用fdisk -l檢視所有硬碟資訊:

ubuntu@VM-164-254-ubuntu:/$ sudo fdisk -l
Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram1: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram2: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram3: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram4: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram5: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram6: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram7: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram8: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram9: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram10: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram11: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram12: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram13: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram14: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/ram15: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


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: 0x27921508

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 41943039 41940992  20G 83 Linux


Disk /dev/vdb: 30 GiB, 32212254720 bytes, 62914560 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
ubuntu@VM-164-254-ubuntu:/$      

根據最後一段disk可以看到事這塊30G的硬碟沒有加載,是以接下來使用

進行磁盤分區:

ubuntu@VM-164-254-ubuntu:/$ sudo fdisk /dev/vdb

Welcome to fdisk (util-linux 2.27.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 0x0d50e367.

Command (m for help): 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): 1
First sector (2048-62914559, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-62914559, default 62914559): 

Created a new partition 1 of type 'Linux' and of size 30 GiB.

Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

ubuntu@VM-164-254-ubuntu:/$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            414M     0  414M   0% /dev
tmpfs            87M  9.4M   78M  11% /run
/dev/vda1        20G  4.5G   15G  24% /
tmpfs           433M   48K  433M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           433M     0  433M   0% /sys/fs/cgroup
tmpfs            87M     0   87M   0% /run/user/500
ubuntu@VM-164-254-ubuntu:/$ mkfs.ext3 /dev/vdb1
mke2fs 1.42.13 (17-May-2015)
Could not open /dev/vdb1: Permission denied
ubuntu@VM-164-254-ubuntu:/$ sudo mkfs.ext3 /dev/vdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 7864064 4k blocks and 1966080 inodes
Filesystem UUID: 3b8757e2-f85a-41ed-b4c8-eceb1c10aa3f
Superblock backups stored on blocks: 
   32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
   4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

ubuntu@VM-164-254-ubuntu:/$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            414M     0  414M   0% /dev
tmpfs            87M  9.4M   78M  11% /run
/dev/vda1        20G  4.5G   15G  24% /
tmpfs           433M   48K  433M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           433M     0  433M   0% /sys/fs/cgroup
tmpfs            87M     0   87M   0% /run/user/500
ubuntu@VM-164-254-ubuntu:/$      

分區完成之後,進行挂載,首先建立一個待挂載的目錄:

ubuntu@VM-164-254-ubuntu:/var/www/html/test/adminweb$ mkdir tuijian      

挂載分區有兩種辦法:

1、直接使用mount指令:

ubuntu@VM-164-254-ubuntu:/var/www/html/test/adminweb$ sudo mount /dev/vdb1 ./tuijian      

2、寫入到/dev/fstab檔案中,作業系統開機啟動時會檢查這個檔案并自動加載

vi /dev/fstab
/dev/vdb1            /var/www/html/test/adminweb/tuijian exy3 defaults     0 0      

儲存之後就行了,使用

檢視:

ubuntu@VM-164-254-ubuntu:/var/www/html/test/adminweb$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            414M     0  414M   0% /dev
tmpfs            87M  9.4M   78M  11% /run
/dev/vda1        20G  4.5G   15G  24% /
tmpfs           433M   48K  433M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           433M     0  433M   0% /sys/fs/cgroup
tmpfs            87M     0   87M   0% /run/user/500
/dev/vdb1        30G   45M   28G   1% /var/www/html/test/adminweb/tuijian