字體:  

在Google GCP 上新增及掛載硬碟(add or mount disk)

htctouch 發表於: 2017-8-31 12:14 來源: ADJ網路控股集團


有時因為架構上的關係.需要使用 GCP 來掛載新的空間.這時後可以參考官方的步驟:

(一) Create and attach a persistent disk in the Google Cloud Platform Console:

(1)Go to the VM instances page.=> https://console.cloud.google.com/compute/instances
(2)Click the name of the instance where you want to add a disk.
(3)At the top of the instance details page, click Edit.
(4)Under Additional disks, click Add item.
(5)In the Name column for additional lists, click the Select a disk drop down menu and select Create disk.
(6)Configure the properties for your new disk. Specify a name for the disk and select the Blank disk option.
(7)Click Create to create the disk.
(8)At the bottom of the instance details page, click Save to apply your changes to the instance and attach the new disk.
(9)After you create and attach a new disk to an instance, you must format and mount the disk so that the operating system can use the available storage space.

(二) Formatting and mounting a persistent disk
# lsblk
[quote]
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   10G  0 disk
└─sda1   8:1    0   10G  0 part /
sdb      8:16   0  200G  0 disk
[/quote]
sdb is the device ID for the new persistent disk.

再來格式化磁區
# mkfs.ext4 -m 0 -F -E lazy_itable_init=0,discard /dev/sdb

建立預掛載的目錄
# mkdir -p /mnt/storage

# 掛載
# mount -o discard,defaults /dev/sdb /mnt/storage

寫入/etc/fstab 讓每次重開機都能自動掛載
# echo UUID=`sudo blkid -s UUID -o value /dev/sdb` /mnt/storage ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab

這樣就可以囉~

如果需要 resize 硬碟大小.也是可以的囉...
請參考資料:
https://cloud.google.com/compute/docs/disks/add-persistent-disk