0
votes

I want to attach disk to an instance on Google Compute Engine, through commands below.

gcloud compute instances create pg-disk-formatter --image ubuntu-1604-lts --custom-cpu 1 --custom-memory 1
gcloud compute disks create pg-data-disk --size 50GB
gcloud compute instances attach-disk pg-disk-formatter --disk pg-data-disk

However, even I logged into the machine and cd to /dev/disk/by-id/, it doesn't show up on the list.

mkouhei0910@pg-data-disk:~$ cd /dev/disk/by-id/
google-persistent-disk-0                             scsi-0Google_PersistentDisk_persistent-disk-0
google-persistent-disk-0-part1                       scsi-0Google_PersistentDisk_persistent-disk-0-part1
google-pg-data-disk2                                 scsi-0Google_PersistentDisk_pg-data-disk2

I noticed it shows up after I attached new disk image from Google Platform Console, but how can I achieve it purely gloud command line?

1

1 Answers

0
votes

You first command is not correct. It should be:

gcloud compute instances create pg-disk-formatter --image-project ubuntu-os-cloud --image-family ubuntu-1604-lts --custom-cpu 1 --custom-memory 1

The second and third commands are good. They will create a disk and will attach it to the VM instance. The additional disk is listed in the output of ls command that your provided:

google-pg-data-disk2

If you want guest operating system sees a different name for attached disk, you can use --device-name flag with the command.