官术网_书友最值得收藏!

Creating and attaching a persistent disk

As we discussed in the previous sections, a persistent disk is the storage option that is associated with the VM instances in GCE, by default. This section will walk you through creating and attaching a persistent disk.

Let's say we have already created a VM instance called test-instance in the US zone central1-f. We now want to expand the storage that is available to this VM instance, which can be done by creating a new persistent disk. We will use the command line for this:

gcloud compute disks create test-disk --size=100GB --zone us-central1-f  
  • gcloud compute disks create is the command
  • test-disk is the name of our disk
  • The size is 100GB
  • The zone is us-central1-f

The persistent disk that you set up has to be in the same zone as your instance. You can't create a persistent disk in another zone and attach it to an instance that lives in a completely different zone, because persistent disks have to be connected to the instance with really high-speed connections—and that is only possible in the same zone. Note that ideally when you are creating a persistent disk, there should be at least 200 GB in size for optimal read and write performance or you'll get a warning.

  1. Click on your test instance VM to edit your settings and let's attach this particular disk to your VM instance.
  2. Click on add item under Additional disks and, in the drop-down list, you will find test-disk, the standard persistent disk that we set up.
  1. Let us use the command line to attach this disk to our instance. The command line is especially preferable if this is a repeated operation. Use the gcloud compute instances attach-disk command to specify the instance and the disk you want attached and the instance and the zone where they both live and hit Enter:
gcloud compute instances attach-disk test-instance --disk test-disk --zone us-central1-f  
  1. Once the command has returned, hit REFRESH on your web console and go into the test-instance to see whether the disk has indeed been attached. Note that test-disk is now attached to this VM instance.
  1. You can also SSH into your test instance to confirm that the disk is indeed part of the instance now. You can view all the hard disks that are associated with this instance by running ls -l /dev/disk/by-id. This will give you the list of hard disks attached. You will see an SCSI disk called Google persistent disk-1, which is the new disk that we just attached.
  1. Once the status of your disk creation is ready, the disk needs to be formatted.
主站蜘蛛池模板: 龙门县| 贵州省| 江永县| 崇左市| 德格县| 鹿泉市| 专栏| 怀安县| 万载县| 乐业县| 昌邑市| 龙海市| 罗源县| 恩平市| 义马市| 镶黄旗| 北碚区| 苏尼特右旗| 兴仁县| 延吉市| 西安市| 湘潭县| 商南县| 井陉县| 石景山区| 洪江市| 保靖县| 诏安县| 巴彦淖尔市| 武义县| 托克逊县| 乌恰县| 梨树县| 洛川县| 廉江市| 卢湾区| 喜德县| 长岭县| 湘潭市| 高雄市| 章丘市|