{"id":780,"date":"2021-07-20T01:35:00","date_gmt":"2021-07-20T01:35:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=780"},"modified":"2021-07-20T01:35:00","modified_gmt":"2021-07-20T01:35:00","slug":"mount-extra-disks-on-google-cloud","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=780","title":{"rendered":"How To Mount Extra Disks on Google Cloud VM Instance"},"content":{"rendered":"<p>By default, the new disks attached during the instance creation cannot be used directly. You need to format and mount it to your instance to put that in use.<\/p>\n<p>In this article, I will explain how to format and mount an extra disk to your google compute engine VM instance.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-35-20.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"780\" height=\"487\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-35-20.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-35-20.png 780w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"create-and-attach-a-disk-to-vm\">Create and Attach a Disk to VM<\/h2>\n<p>If you don&#8217;t have an existing disk attached to the VM, you can create and attach one using gcloud CLI or the google cloud console.<\/p>\n<p>In this example, I will use the gcloud CLI to create and attach the disk. If you don&#8217;t have gcloud installed, refer to this <a href=\"https:\/\/devopscube.com\/setup-google-cloud-clisdk\/\" rel=\"noreferrer noopener\">gcloud CLI setup guide<\/a> for beginners.<\/p>\n<p>Create a disk named <code>data-disk<\/code> in the <code>us-central1-a<\/code> zone. Ensure you create the disk in the same zone as your instance.<\/p>\n<pre><code>gcloud compute disks create data-disk \\\n      --zone=us-central1-a \\\n      --size=50GB \\\n      --type=pd-standard<\/code><\/pre>\n<p>Attach the disk to the VM named demo-mount<\/p>\n<pre><code>gcloud compute instances attach-disk demo-mount \\\n  --disk data-disk \\\n  --zone=us-central1-a <\/code><\/pre>\n<h2 id=\"formatting-and-mounting-extra-disk-on-vm-instance\">Formatting and Mounting Extra Disk on VM Instance<\/h2>\n<p><strong>Step 1:<\/strong> Log in to the instance and list the available extra disk using the following command.<\/p>\n<pre><code>sudo lsblk<\/code><\/pre>\n<p>An example output is shown below. All the extra disks will not have any entry under the <code>MOUNTPOINT tab<\/code>. Here, <code>sdb is<\/code> the extra disk that has to be formatted and mounted.<\/p>\n<pre><code>[devopscube@demo-mount ~]$ lsblk\nNAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT\nsda      8:0    0  10G  0 disk \n\u2514\u2500sda1   8:1    0  10G  0 part \/\nsdb      8:16   0  20G  0 disk<\/code><\/pre>\n<p><strong>Step 2:<\/strong> Next, we should format the disk to <code>ext4<\/code> using the following command. In the command below we are mentioning <code>\/dev\/sdb<\/code> as that is the extra disk available.<\/p>\n<pre><code>sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard \/dev\/sdb<\/code><\/pre>\n<p><strong>Step 3:<\/strong> Next, create a mount directory on the instance as shown below. You can replace the <code>\/data-mount<\/code> with a custom name and path, you prefer.<\/p>\n<pre><code>sudo mkdir -p \/data-mount<\/code><\/pre>\n<p><strong>Step 4: <\/strong>Now, mount the disk to the directory we created using the following command.<\/p>\n<pre><code>sudo mount -o discard,defaults \/dev\/sdb \/data-mount<\/code><\/pre>\n<p>If you list the block devices, you will see the mounted disk as shown below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-34-18.png\" class=\"kg-image\" alt=\"google cloud list extra disks\" loading=\"lazy\" width=\"479\" height=\"217\"><\/figure>\n<p><strong>Step 5:<\/strong> If you want write permissions to this disk for all the users, you can execute the following command. Or, based on the privileges you need for the disk, you can apply the user permissions.<\/p>\n<pre><code>sudo chmod a+w \/data-mount<\/code><\/pre>\n<p><strong>Step 6: <\/strong>Check the mounted disk using the following command.<\/p>\n<pre><code>df -h<\/code><\/pre>\n<p>A sample output,<\/p>\n<pre><code>[devopscube@demo-mount]$ df -h\nFilesystem      Size  Used Avail Use% Mounted on\n\/dev\/sda1        10G  2.3G  7.8G  23% \/\ndevtmpfs        842M     0  842M   0% \/dev\ntmpfs           849M     0  849M   0% \/dev\/shm\ntmpfs           849M  8.4M  840M   1% \/run\ntmpfs           849M     0  849M   0% \/sys\/fs\/cgroup\ntmpfs           170M     0  170M   0% \/run\/user\/1001\ntmpfs           170M     0  170M   0% \/run\/user\/0\n\/dev\/sdb         20G   45M   20G   1% \/demo-data<\/code><\/pre>\n<h2 id=\"automount-gcp-disk-on-reboot\">Automount GCP Disk On Reboot<\/h2>\n<p>To automount the disk on system start or reboots, you need to add the mount entry to the <code>fstab<\/code>. Follow the steps given below for adding the mount to <code>fstab<\/code>.<\/p>\n<p><strong>Step 1:<\/strong> First, back up the <code>fstab<\/code> file.<\/p>\n<pre><code>sudo cp \/etc\/fstab \/etc\/fstab.backup<\/code><\/pre>\n<p><strong>Step 2:<\/strong> Execute the following command to make a <code>fstab<\/code> entry with the UUID of the disk.<\/p>\n<pre><code>noatime<\/code><\/pre>\n<p><strong>Step 3:<\/strong> Check the UUID of the extra disk<\/p>\n<pre><code>sudo blkid -s UUID -o value \/dev\/sdb<\/code><\/pre>\n<p><strong>Step 4:<\/strong> Open <code>fstab<\/code> file and check for the new entry for the UUID of the extra disk<\/p>\n<pre><code>sudo cat \/etc\/fstab<\/code><\/pre>\n<p>Now, on every reboot, the extra disk will automatically mount to the defined folder based on the <code>fstab<\/code> entry.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/mount-extra-disks-on-google-cloud\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Mount Extra Disks on Google Cloud VM Instance \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/mount-extra-disks-on-google-cloud\/<\/p>\n","protected":false},"author":1,"featured_media":781,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-780","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=780"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/780\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/781"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}