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
  • While creating the vm instance in the same zone as the disk created above we can attach this disk to the vm
  • 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

  • To make this mount permanent, we need to know blkid
  • 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

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

  • 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 ReplyCancel reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%