• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

disks

GCP Backup Instance

April 3, 2022 by Ulysses

Here’s the script to backup GCP disks.

#!/bin/bash
now=$(date +%s)
disks=$(gcloud compute disks list --project project-id --filter="users:instance" --format="value(name)")
for disk in $disks
do
  gcloud compute disks snapshot $disk \
  --snapshot-names=$disk-$now \
  --zone=us-central1-a \
  --project=project-id \
  --async
done

#!/bin/bash now=$(date +%s) disks=$(gcloud compute disks list --project project-id --filter="users:instance" --format="value(name)") for disk in $disks do gcloud compute disks snapshot $disk \ --snapshot-names=$disk-$now \ --zone=us-central1-a \ --project=project-id \ --async done

Filed Under: Cloud, Linux Tagged With: backup, disks, gcp, manual, snapshots

GCP List Disk Types

December 22, 2021 by Ulysses

To list all disk types available in your project in all regions. Result is truncated.

$ gcloud compute disk-types list
NAME         ZONE                       VALID_DISK_SIZES
pd-balanced                             10GB-65536GB
pd-ssd                                  10GB-65536GB
pd-standard                             200GB-65536GB
pd-balanced                             10GB-65536GB
...

$ gcloud compute disk-types list NAME ZONE VALID_DISK_SIZES pd-balanced 10GB-65536GB pd-ssd 10GB-65536GB pd-standard 200GB-65536GB pd-balanced 10GB-65536GB ...

To list a specific region, use the filter option.

$ gcloud compute disk-types list --filter="zone~'us-central1'"
NAME         ZONE           VALID_DISK_SIZES
pd-balanced  us-central1-a  10GB-65536GB
pd-extreme   us-central1-a  500GB-65536GB
pd-ssd       us-central1-a  10GB-65536GB
pd-standard  us-central1-a  10GB-65536GB
pd-balanced  us-central1-b  10GB-65536GB
pd-extreme   us-central1-b  500GB-65536GB
pd-ssd       us-central1-b  10GB-65536GB
pd-standard  us-central1-b  10GB-65536GB
pd-balanced  us-central1-c  10GB-65536GB
pd-extreme   us-central1-c  500GB-65536GB
pd-ssd       us-central1-c  10GB-65536GB
pd-standard  us-central1-c  10GB-65536GB
pd-balanced  us-central1-f  10GB-65536GB
pd-extreme   us-central1-f  500GB-65536GB
pd-ssd       us-central1-f  10GB-65536GB
pd-standard  us-central1-f  10GB-65536GB
pd-balanced  us-central1-d  10GB-65536GB
pd-extreme   us-central1-d  500GB-65536GB
pd-ssd       us-central1-d  10GB-65536GB
pd-standard  us-central1-d  10GB-65536GB

$ gcloud compute disk-types list --filter="zone~'us-central1'" NAME ZONE VALID_DISK_SIZES pd-balanced us-central1-a 10GB-65536GB pd-extreme us-central1-a 500GB-65536GB pd-ssd us-central1-a 10GB-65536GB pd-standard us-central1-a 10GB-65536GB pd-balanced us-central1-b 10GB-65536GB pd-extreme us-central1-b 500GB-65536GB pd-ssd us-central1-b 10GB-65536GB pd-standard us-central1-b 10GB-65536GB pd-balanced us-central1-c 10GB-65536GB pd-extreme us-central1-c 500GB-65536GB pd-ssd us-central1-c 10GB-65536GB pd-standard us-central1-c 10GB-65536GB pd-balanced us-central1-f 10GB-65536GB pd-extreme us-central1-f 500GB-65536GB pd-ssd us-central1-f 10GB-65536GB pd-standard us-central1-f 10GB-65536GB pd-balanced us-central1-d 10GB-65536GB pd-extreme us-central1-d 500GB-65536GB pd-ssd us-central1-d 10GB-65536GB pd-standard us-central1-d 10GB-65536GB

To a list a specific region and local SSDs only.

gcloud compute disk-types list --filter="zone~'us-central1' AND name~'local-'"
NAME       ZONE           VALID_DISK_SIZES
local-ssd  us-central1-a  375GB-375GB
local-ssd  us-central1-b  375GB-375GB
local-ssd  us-central1-c  375GB-375GB
local-ssd  us-central1-f  375GB-375GB
local-ssd  us-central1-d  375GB-375GB

gcloud compute disk-types list --filter="zone~'us-central1' AND name~'local-'" NAME ZONE VALID_DISK_SIZES local-ssd us-central1-a 375GB-375GB local-ssd us-central1-b 375GB-375GB local-ssd us-central1-c 375GB-375GB local-ssd us-central1-f 375GB-375GB local-ssd us-central1-d 375GB-375GB

Filed Under: Cloud Tagged With: disks, filter, gcp, list, region, type

GCP Display Device Names on OS

August 18, 2021 by Ulysses

In GCP console you can see the VM’s Device Names. In this case, it’s boot and persistent-disk-1.

Name		          Device name
server-boot               boot	
server-data               persistent-disk-1

Name Device name server-boot boot server-data persistent-disk-1

To display the volume names on the OS, run this command.

$ ls -l /dev/disk/by-id
total 0
lrwxrwxrwx. 1 root root  9 Aug  2 01:12 google-boot -> ../../sda
lrwxrwxrwx. 1 root root 10 Aug  2 01:12 google-boot-part1 -> ../../sda1
lrwxrwxrwx. 1 root root  9 Aug 18 18:48 google-persistent-disk-1 -> ../../sdb
lrwxrwxrwx. 1 root root  9 Aug  2 01:12 scsi-0Google_PersistentDisk_boot -> ../../sda
lrwxrwxrwx. 1 root root 10 Aug  2 01:12 scsi-0Google_PersistentDisk_boot-part1 -> ../../sda1
lrwxrwxrwx. 1 root root  9 Aug 18 18:48 scsi-0Google_PersistentDisk_persistent-disk-1 -> ../../sdb

$ ls -l /dev/disk/by-id total 0 lrwxrwxrwx. 1 root root 9 Aug 2 01:12 google-boot -> ../../sda lrwxrwxrwx. 1 root root 10 Aug 2 01:12 google-boot-part1 -> ../../sda1 lrwxrwxrwx. 1 root root 9 Aug 18 18:48 google-persistent-disk-1 -> ../../sdb lrwxrwxrwx. 1 root root 9 Aug 2 01:12 scsi-0Google_PersistentDisk_boot -> ../../sda lrwxrwxrwx. 1 root root 10 Aug 2 01:12 scsi-0Google_PersistentDisk_boot-part1 -> ../../sda1 lrwxrwxrwx. 1 root root 9 Aug 18 18:48 scsi-0Google_PersistentDisk_persistent-disk-1 -> ../../sdb

As you can see, boot and persistent-disk-1 are displayed along with its device names /dev/sda and /dev/sdb.

Filed Under: Cloud, Linux Tagged With: disks, display, gcp, id, names, volumes

GCP Identify Your Disks

September 16, 2020 by Ulysses

Here’s how to identify your disks on the system to cross check with GCP Dashboard.

ls -l /dev/disk/by-id

ls -l /dev/disk/by-id

Result:

[root@servername ~]# ls -l /dev/disk/by-id
total 0
lrwxrwxrwx. 1 root root  9 Sep 15 05:30 google-boot -> ../../sda
lrwxrwxrwx. 1 root root 10 Sep 15 05:30 google-boot-part1 -> ../../sda1
lrwxrwxrwx. 1 root root  9 Sep 15 05:30 google-persistent-disk-1 -> ../../sdb
lrwxrwxrwx. 1 root root  9 Sep 15 05:30 scsi-0Google_PersistentDisk_boot -> ../../sda
lrwxrwxrwx. 1 root root 10 Sep 15 05:30 scsi-0Google_PersistentDisk_boot-part1 -> ../../sda1
lrwxrwxrwx. 1 root root  9 Sep 15 05:30 scsi-0Google_PersistentDisk_persistent-disk-1 -> ../../sdb

[root@servername ~]# ls -l /dev/disk/by-id total 0 lrwxrwxrwx. 1 root root 9 Sep 15 05:30 google-boot -> ../../sda lrwxrwxrwx. 1 root root 10 Sep 15 05:30 google-boot-part1 -> ../../sda1 lrwxrwxrwx. 1 root root 9 Sep 15 05:30 google-persistent-disk-1 -> ../../sdb lrwxrwxrwx. 1 root root 9 Sep 15 05:30 scsi-0Google_PersistentDisk_boot -> ../../sda lrwxrwxrwx. 1 root root 10 Sep 15 05:30 scsi-0Google_PersistentDisk_boot-part1 -> ../../sda1 lrwxrwxrwx. 1 root root 9 Sep 15 05:30 scsi-0Google_PersistentDisk_persistent-disk-1 -> ../../sdb

Filed Under: Cloud Tagged With: device, disks, gcp, identify, name, volume

GCP Disks Attach To An Instance

September 15, 2020 by Ulysses

Here’s how to display a list the disks attached to an instance.

gcloud compute instances describe instance-name \
--project project-id \
--zone us-central1-c \
--format='yaml(disks[].source)'

gcloud compute instances describe instance-name \ --project project-id \ --zone us-central1-c \ --format='yaml(disks[].source)'

Filed Under: Cloud Tagged With: compute, describe, disks, gcp, instances, list, yaml

Extend Regional Persistent Disks

September 12, 2020 by Ulysses

Here’s the command to extend your regional persistent disks.

gcloud compute disks resize disk-name \
--size 100 \
--project project-id \
--region us-central1

gcloud compute disks resize disk-name \ --size 100 \ --project project-id \ --region us-central1

Or you can specify by zone.

gcloud compute disks resize disk-name \
--size 100 \
--project project-id \
--zone us-central1-c

gcloud compute disks resize disk-name \ --size 100 \ --project project-id \ --zone us-central1-c

Display the updated disk details.

gcloud compute disks list \
--filter="name=disk-name" \
--project project-id

gcloud compute disks list \ --filter="name=disk-name" \ --project project-id

Although you’ve increased disk size, the file system doesn’t know the extra space. Run this (for XFS).

xfs_growfs /dev/sdb

xfs_growfs /dev/sdb

Filed Under: Cloud Tagged With: disks, gcloud, persistent disks, resize

GCP Move Instance to Another Project

December 11, 2019 by Ulysses

Here’s how to copy a disk from one project to another.

gcloud compute disks create lamp-server \
--source-snapshot https://www.googleapis.com/compute/v1/projects/project-id/global/snapshots/lamp-server \
--project next-project-id \
--zone us-central1-a

gcloud compute disks create lamp-server \ --source-snapshot https://www.googleapis.com/compute/v1/projects/project-id/global/snapshots/lamp-server \ --project next-project-id \ --zone us-central1-a

Once all the disks are copied. You can create a snapshot of the boot.

gcloud compute disks snapshot lamp-server

gcloud compute disks snapshot lamp-server

Create an instance from snapshot.

gcloud compute disks create "hostname-boot" \
--project "project-id" \
--zone "us-central1-a" \
--source-snapshot "snapshot-name" \
--type "pd-standard" \
--size "100"

gcloud compute disks create "hostname-boot" \ --project "project-id" \ --zone "us-central1-a" \ --source-snapshot "snapshot-name" \ --type "pd-standard" \ --size "100"

Filed Under: Cloud Tagged With: create, disks, gcp, instance, move, project, snapshots

GCP Lists Disk Per Project

August 9, 2019 by Ulysses

Here’s the Google Cloud Platform (GCP) GCloud command to list all disks in a specific project.

gcloud compute disks list --project yourprojectname

gcloud compute disks list --project yourprojectname

Filed Under: Cloud Tagged With: disks, gcloud, gcp, google, list, project

  • Go to page 1
  • Go to page 2
  • Go to Next Page »
  • Home
  • About
  • Archives

Copyright © 2012–2022