查看完整版本: 在Google GCP 上新增及掛載硬碟(add or mount disk)


htctouch 2017-8-31 12:14

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

有時因為架構上的關係.需要使用 GCP 來掛載新的空間.這時後可以參考官方的步驟:<br><br>(一) Create and attach a persistent disk in the Google Cloud Platform Console:<br><br>(1)Go to the VM instances page.=&gt; https://console.cloud.google.com/compute/instances<br>(2)Click the name of the instance where you want to add a disk.<br>(3)At the top of the instance details page, click Edit.<br>(4)Under Additional disks, click Add item.<br>(5)In the Name column for additional lists, click the Select a disk drop down menu and select Create disk.<br>(6)Configure the properties for your new disk. Specify a name for the disk and select the Blank disk option.<br>(7)Click Create to create the disk.<br>(8)At the bottom of the instance details page, click Save to apply your changes to the instance and attach the new disk.<br>(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.<br><br>(二) Formatting and mounting a persistent disk<br># <font color="Blue">lsblk</font><br>[quote]<br>NAME&nbsp; &nbsp;MAJ:MIN RM&nbsp;&nbsp;SIZE RO TYPE MOUNTPOINT<br>sda&nbsp; &nbsp;&nbsp; &nbsp;8:0&nbsp; &nbsp; 0&nbsp; &nbsp;10G&nbsp;&nbsp;0 disk<br>└─sda1&nbsp; &nbsp;8:1&nbsp; &nbsp; 0&nbsp; &nbsp;10G&nbsp;&nbsp;0 part /<br>sdb&nbsp; &nbsp;&nbsp; &nbsp;8:16&nbsp; &nbsp;0&nbsp;&nbsp;200G&nbsp;&nbsp;0 disk<br>[/quote]<br>sdb is the device ID for the new persistent disk.<br><br>再來格式化磁區<br># <font color="Blue">mkfs.ext4 -m 0 -F -E lazy_itable_init=0,discard /dev/sdb</font><br><br>建立預掛載的目錄<br># <font color="Blue">mkdir -p /mnt/storage</font><br><br># 掛載<br># <font color="Blue">mount -o discard,defaults /dev/sdb /mnt/storage</font><br><br>寫入/etc/fstab 讓每次重開機都能自動掛載<br># <font color="Blue">echo UUID=`sudo blkid -s UUID -o value /dev/sdb` /mnt/storage ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab</font><br><br>這樣就可以囉~<br><br>如果需要 resize 硬碟大小.也是可以的囉...<br><div>可以先到 GCP 的後台 -&gt; 在磁碟的地方 調整所需的大小</div><div>然後到機器下指令<br></div><div><br></div><div>首先透過 lsblk 指令列出所有硬碟及分割區</div><div># lsblk</div><div><br></div><div>再透過 growpart 指令擴大分割區,用法為</div><div># growpart /dev/sda 1</div><div><br></div><div>最後一個步驟,就是擴大作業系統的檔案系統</div><div># resize2fs /dev/sda<br></div><div><br></div><div>最後再用 df 指令確認硬碟空間是否有增加</div><div># df -h</div><div><br></div><div>就會看到硬碟空間已經調整囉~<br></div><div>參考資料:</div><a href="https://cloud.google.com/compute/docs/disks/add-persistent-disk" target="_blank">https://cloud.google.com/compute/docs/disks/add-persistent-disk</a>
頁: [1]
查看完整版本: 在Google GCP 上新增及掛載硬碟(add or mount disk)