• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

boot

GCP Find Instance Boot Disk

April 13, 2022 by Ulysses

How to find a boot disk from an instance.

gcloud compute instances describe servername \
--format='get(disks[0].source)' \
--zone=us-central1-c \
--project project-id

gcloud compute instances describe servername \ --format='get(disks[0].source)' \ --zone=us-central1-c \ --project project-id

Result

https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-f/disks/servername-boot

https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1-f/disks/servername-boot

Filed Under: Cloud Tagged With: boot, disk, find, gcp

GCP Compute add startup-script to metadata

February 2, 2022 by Ulysses

How to add a startup-script to metadata. The script executes every time VM is started.

gcloud compute instances add-metadata instance-name \
--project your-project-id \
--zone us-central1-c \
--metadata=startup-script='#! /bin/bash
sudo -i
echo "Time: $(date)" >> /tmp/date.txt'

gcloud compute instances add-metadata instance-name \ --project your-project-id \ --zone us-central1-c \ --metadata=startup-script='#! /bin/bash sudo -i echo "Time: $(date)" >> /tmp/date.txt'

Filed Under: Cloud Tagged With: add, boot, compute, gcp, metadata, startup-script

Resizing XFS root partition in GCP

July 16, 2021 by Ulysses

How to resize a root partition in GCP.

Increase disk size.

gcloud compute disks resize server-boot-disk-name \
--size=50GB \
--zone us-central1-c \
--project your-project-id

gcloud compute disks resize server-boot-disk-name \ --size=50GB \ --zone us-central1-c \ --project your-project-id

Run growpart.

growpart /dev/sda 1

growpart /dev/sda 1

Run xfs_growfs.

xfs_growfs /dev/sda1

xfs_growfs /dev/sda1

To verify, run these.

lsblk
df -Th

lsblk df -Th

Filed Under: Cloud, Linux Tagged With: boot, extend, gcp, growpart, root, xfs, xfs_growfs

GRUB Fixes

February 15, 2020 by Ulysses

This are grub fixes to servers that are not booting up due to improper entries in the grub menu.

grub --batch <<END
root (hd0,0)
setup (hd0,0)
quit
END
#
sed -i 's/dev\/sda/dev\/hda/' /boot/grub/device.map
sed -i 's/(hd0)/(hd0,0)/' /boot/grub/menu.lst

grub --batch <<END root (hd0,0) setup (hd0,0) quit END # sed -i 's/dev\/sda/dev\/hda/' /boot/grub/device.map sed -i 's/(hd0)/(hd0,0)/' /boot/grub/menu.lst

The fix includes replacing (hd0) with (hd0,0) and /dev/sda with /dev/hda.

Filed Under: Linux Tagged With: boot, fix, grub, issues, menu

Windows Boot Time

December 2, 2019 by Ulysses

Here’s how to find when a Windows server was last rebooted.

systeminfo | find /i "boot time"

systeminfo | find /i "boot time"

Filed Under: Windows Tagged With: boot, cmd, last, server, windows

Add nofail

May 1, 2019 by Ulysses

The /etc/fstab file allow volumes to be automatically mounted on bootup. Add nofail in your automated mounts to prevent instances from hanging on boot. Nofail makes the instance to boot even if there are errors with the mounted volume.

UUID=aebf131c-6957-451e-8d34-ec978d9581ae  /data  xfs  defaults,nofail  0  2

UUID=aebf131c-6957-451e-8d34-ec978d9581ae /data xfs defaults,nofail 0 2

Filed Under: Cloud, Linux Tagged With: boot, errors, fstab, nofail

Extend Linux Boot

February 6, 2019 by Ulysses

The following commands will extend Linux Boot drive without a reboot.

List block devices. Check disk sizes.

lsblk
df -h

lsblk df -h

Determine file system type: xfs, ext2, ext3 or ext4.

file -s /dev/xvda1
# or
df -Th

file -s /dev/xvda1 # or df -Th

Extend volume from the console or command line.

aws ec2 modify-volume --region us-east-1 \
--volume-id vol-xxxxxxxxxxxx --size 10 \
--volume-type gp2

aws ec2 modify-volume --region us-east-1 \ --volume-id vol-xxxxxxxxxxxx --size 10 \ --volume-type gp2

Resize Linux partition.

# for /dev/xvda1
growpart /dev/xvda 1
# for /dev/xvda2
growpart /dev/xvda 2
# for ext2, ext3, ext4
resize2fs /dev/xvda1
# for xfs 
xfs_growfs /dev/mapper/root
xfs_growfs /dev/xvda1

# for /dev/xvda1 growpart /dev/xvda 1 # for /dev/xvda2 growpart /dev/xvda 2 # for ext2, ext3, ext4 resize2fs /dev/xvda1 # for xfs xfs_growfs /dev/mapper/root xfs_growfs /dev/xvda1

Check if new file size is being displayed.

lsblk
df -Th

lsblk df -Th

Filed Under: Linux Tagged With: boot, extend, partition

GCP Attach Detach Disks

December 23, 2018 by Ulysses

Google Cloud Platform just recently released a beta feature called detaching and attaching boot disks. Previously, boot disks were permanently attached to their VM instances. Now you have the ability to detach boot disk from your instance and attach it to another instance without deleting the original instance. You can also replace the boot disks for an instance rather than recreating the entire instance. I’ve tested it on my test account, and it works quite nicely.

I have 2 servers called blue-server and red-server. I’m detaching the disks on blue-server and attaching it to the red-server.

gcloud compute instances detach-disk blue-server --disk=blue-server-disk --zone us-central1-c
gcloud compute instances attach-disk cyan-server --disk=blue-server-disk --zone us-central1-c
gcloud compute instances detach-disk cyan-server --disk=blue-server-disk --zone us-central1-c
gcloud compute instances attach-disk blue-server --disk=blue-server-disk --zone us-central1-c

gcloud compute instances detach-disk blue-server --disk=blue-server-disk --zone us-central1-c gcloud compute instances attach-disk cyan-server --disk=blue-server-disk --zone us-central1-c gcloud compute instances detach-disk cyan-server --disk=blue-server-disk --zone us-central1-c gcloud compute instances attach-disk blue-server --disk=blue-server-disk --zone us-central1-c

Results:

GCP: Attach and Detach Disks

This new GCP feature is still beta. There might be a few quirks here and there, but overall, it’s a must have feature if you are managing OS.

Filed Under: Cloud Tagged With: attach, boot, detach, disks, gcp

  • Home
  • About
  • Archives

Copyright © 2012–2022