GCP Classroom Series – 07/Mar/2021

Attaching disks

  • We can attach disks to vm instance from the same availability zone
  • From disks we can create images, these images can be used as custom images while create a vm instance
  • Lets create one more disk Preview
  • While creating the vm instance in the same zone as the disk created above we can attach this disk to the vm Preview Preview Preview
  • Now lets format the sdb, mount the disk to some folder
sudo mkfs -t ext4 /dev/sdb
sudo mkdir /learning
sudo mount /dev/sdb /learning
sudo df -h

Preview Preview

  • To make this mount permanent, we need to know blkid Preview
  • Now add the below line to /etc/fstab
UUID=89fd5932-d285-4547-85f3-50cbf88dd45e   /learning  ext4 defaults,nofail 1 2
  • After this restart the vm instance and execute sudo df -h Preview

Startup Scripts

  • When creating the vm instance we can also set a startup script. This is the script that runwhen instance boots up or restarts.
  • So now lets write the startup script to install apache server
#!/bin/bash
sudo apt update
sudo apt install apache2 -y

Preview

  • Exercise: Create a vm instance to setup lamp stack on startup
#!/bin/bash
sudo apt update
sudo apt install apache2 -y
sudo apt install php libapache2-mod-php php-mysql php-cli -y
echo "<?php phpinfo(); ?>" | sudo tee -a /var/www/html/info.php

Next Steps:

  • Working with VM Meta data
  • Preventing Accidental vm deletion

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin