Skip to content

Instantly share code, notes, and snippets.

@yannvery
Last active August 29, 2015 14:22
Show Gist options
  • Save yannvery/b95ee11c3af28f24b610 to your computer and use it in GitHub Desktop.
Save yannvery/b95ee11c3af28f24b610 to your computer and use it in GitHub Desktop.
Mount GCP Disk

How to mount a disk on gcp compute instance

List all disks

df -k

Create directory where disk will be mount

sudo mkdir -p /data

Find hard drive to mount

You'll find it in this directory, this kind of disk is oftently call sdb

/dev/disk/by-id

or this directory

/dev

Format and mount your hard drive with google procedure

The last argument is your hard drive name, here we assume is sdb

sudo /usr/share/google/safe_format_and_mount -m "mkfs.ext4 -F" /dev/sdbs/data/

Create a default partition on your disk

sudo fdisk /dev/sdb
> p # show partions
> n # new partions, all by deault
> w #rewrite partion table
````

### Mount your disk on /data
`sudo mount /dev/sdb /data/`

### Check disk format
`df -T # check if it's ext4`

### Update fstab to mount your disk after server reboot
`sudo vi /etc/fstab` 

Add this line

`/dev/sdb  /data  ext4   defaults  0   1`

### Reboot your server
sudo shutdown -r now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment