有時因為架構上的關係.需要使用 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引用:
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
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 硬碟大小.也是可以的囉...
可以先到 GCP 的後台 -> 在磁碟的地方 調整所需的大小
然後到機器下指令
首先透過 lsblk 指令列出所有硬碟及分割區
# lsblk
再透過 growpart 指令擴大分割區,用法為
# growpart /dev/sda 1
最後一個步驟,就是擴大作業系統的檔案系統
# resize2fs /dev/sda
最後再用 df 指令確認硬碟空間是否有增加
# df -h
就會看到硬碟空間已經調整囉~
參考資料:
https://cloud.google.com/compute/docs/disks/add-persistent-disk