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

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.
主站蜘蛛池模板: 修武县| 台中县| 巨鹿县| 都兰县| 临清市| 嘉义县| 开封市| 双流县| 邢台市| 聊城市| 西平县| 平利县| 原平市| 永嘉县| 青田县| 平远县| 龙陵县| 天水市| 卢龙县| 靖宇县| 明溪县| 崇明县| 彭阳县| 宣威市| 南郑县| 天全县| 东明县| 双城市| 南投市| 封丘县| 牡丹江市| 方正县| 平和县| 长武县| 英山县| 丰宁| 开平市| 海城市| 宝应县| 措美县| 都昌县|