Erwan T
Erwan T

Reputation: 11

GCE persistent disk data management

GCE beginner here...Basic question : How can I send data to a persistent disk?

I have attached a persistent disk to an instance and tried sending files through the instance using the copy-file instruction. The disk seems correctly mounted (see below)

$ sudo fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000935ca
Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    20969472    10483712+  83  Linux
Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

I was able to send files to the instance itself - targetting the /tmp directory on the instance. I haven't succeeded however in sending the files to the persistent disk. Should I send the data to the instance first, then move the data to the attached drive? Or can that be done directly? Either way some directions would help.

Thanks in advance

Upvotes: 1

Views: 528

Answers (1)

BeardedBarbarian
BeardedBarbarian

Reputation: 11

You have to mount and format the Disk before usage:

Formatting disks

Before you can use non-root persistent disks in Compute Engine, you need to format and mount them. Compute Engine provides a tool, safe_format_and_mount, that can be used to assist in this process. The tool can be found at the following location on your virtual machine instance:

/usr/share/google/safe_format_and_mount

The tool performs the following actions:

Format the disk (only if it is unformatted) Mount the disk This can be helpful if you need to use a non-root persistent disk from a startup script, because the tool prevents your script from accidentally reformatting your disks and erasing your data.

safe_format_and_mount works much like the standard mount tool:

$ sudo mkdir MOUNT_POINT
$ sudo /usr/share/google/safe_format_and_mount -m "mkfs.ext4 -F" DISK_LOCATION MOUNT_POINT

Alternatively, you can format and mount disks using standard tools such as mkfs and mount.

Caution: If you are formatting disks from a startup script, you risk data loss if you do not take precautions to prevent reformatting your data on boot. Make sure to back up all important data and set up data recovery systems.

Source: https://cloud.google.com/compute/docs/disks/persistent-disks

Then you can copy Data to the folder you mounted the Disk to :)

Upvotes: 1

Related Questions