How to Launch a New Disk, Attach it to a Virtual Machine Instance, and Mount the Volume on the Disk in the Google Cloud Platform

Author: Ayush Maggo


In Google Cloud Platform (GCP), launching a new disk, attaching it to an instance, and mounting the volume on the disk are essential operations for increasing storage capacity and improving resource utilization. This blog will provide a detailed step-by-step guide on how to perform these operations effectively.

  • A Google Cloud Platform account with a project set up.
  • Having basic knowledge of Google Cloud Platform.
What is a Virtual Machine?

A virtual machine in the cloud refers to a virtualized computing instance provided by cloud service providers. It allows users to run applications and operating systems remotely, accessing them through the internet.

Virtual machines have their own CPU, memory, network interface, and storage. They offer scalability, flexibility, and cost efficiency by enabling resource allocation on-demand.

In other terms, a virtual machine is a computing environment that utilizes software-defined hardware instead of specialized hardware.

What is a disk in the Google Cloud Platform’s Compute Engine?

In Google Cloud Platform (GCP), a disk in Compute Engine is a block-level storage device used for persistent storage. It can be attached to a virtual machine instance, allowing data to be stored and accessed even when the instance is stopped or restarted.

Disks in Compute Engine offer flexibility in storage and performance, and they can be created and managed separately from virtual machine instances.

Creating a Virtual Machine instance in Google Cloud Platform (GCP)
  • In the navigation menu, navigate to the Compute Engine section > VM instances.
  • Click on Create Instance to start creating a new VM instance.
  • Provide a specific name for the Virtual Machine instance.
  • Select the region and Zone based on your requirement.
  • Choose a machine type based on your requirement.
  • Under Boot Disk, click on Change to select an operating system image, such as a Linux Distribution or Windows Server. You can also customize disk size and type according to your requirements.
  • Set the desired boot disk size according to your requirements.
  • Configure the firewall settings by selecting “Allow HTTP traffic” (port 80) or “Allow HTTPS traffic” (port 443).
  • Leave the Advanced options as default.
  • Now, at last, click on Create to create the VM instance.
  • The process may take a few minutes. Once the Virtual Machine instance is successfully created, you will see it listed in the Compute Engine instance list.
Creating a disk in Google Cloud Platform
  • Navigate to the Compute Engine > Disks
  • Click on Create Disk to start creating a new disk.
  • Give a specific name for your disk and ensure that the Region and Zone of the disk are the same as the virtual machine’s Region and Zone.
  • Set the disk size as per your requirement, and leave everything else as default.
  • Now, click on Create, and your disk will be created.
Attaching the disk to an instance
  • Go to the VM instances, open your instance, and click on Edit.
  • Scroll down to Advanced options, and under Disks click on Attach Existing Disk.
  • Choose the disk that you made earlier and click on Save.
  • Now you can see your existing disk being added, and you can click on Save.
  • After adding the disk to your instance, click on Save to save the configuration of the virtual machine instance.
Format and Mount Disk Volume
  • Click on SSH to log into the instance.
  • Now run the lsblk command to list information about available block devices on the machine.

lsblk – list block devices

  • Run mkfs command to check what filesystem mkfs supports.

mkfs – Make File System

Type mkfs and press the tab button twice. It shows the supported filesystem. We choose mkfs.ext4

The mkfs command is used to create a filesystem on a disk or partition. When you attach a disk to a virtual machine, the disk is typically in a raw or unformatted state. To make it usable for storing data, you need to create a file system on the disk.

We use mkfs.ext4 because it is used to create an ext4 file system. Ext4 stands for the fourth extended file system, and it is widely used in Unix/Linux operating systems. Ext4 provides numerous features, such as a partition size limit, better performance, and faster file system checks.

  • Now put mkfs.ext4 into /dev/sdb
sudo mkfs.ext4 /dev/sdb

/dev – /dev’ is a directory that contains device files (hardware devices and virtual devices).

/sdb – This device represents the secondary disk (which we added) or partition on the system.

  • Now, using the below command, create a directory called ‘my’ inside the ‘mnt’ directory.
sudo mkdir /mnt/my

/mnt – It is a directory commonly used for mounting disks.

  • Now, we will mount the directory ‘/mnt/my’ onto our secondary disk, which is ‘/dev/sdb’, using the below command.
sudo mount /dev/sdb /mnt/my
  • By running the ‘lsblk’ command, you can check the mounted disk.

Now, the disk is successfully launched, attached to the instance, and mounted on the specified mount point. By following the step-by-step process outlined in this blog, users can effectively achieve their goals.

Important links:

Happy Learning!

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.