• 7

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Although I'm sure the overall operation can be accomplished, see detach and re-attach part for example, it might not be possible to do that as just one, let's say, operation.

The use case here is, a RHEL image boots into emergency mode and root access is disabled, or some other issue that makes it so that you can't enter the machine now, but with operations on the file system this could be fixed (edit fstab for example).

Say instance0 won't boot. We'll need a second instance (instance1) to attach and mount the boot disk of instance0. Assuming both instances are in the same zone (modify accordingly), let's set some variables:

project= #TODO fill
zone= #TODO fill
instance0= #TODO fill
instance1= #TODO fill
instance0_bootdisk=$(gcloud compute instances describe $instance0 --format "value(disks[0].deviceName)")

We're assuming that instance1 has only only one disk attached to it (the boot disk), so /dev/sdb1 works (modify accordingly).

For convenience, issue:

gcloud config set project $project
gcloud config set compute/zone $zone

To get the proceedings proceeding, let's stop instance0, create a snapshot of its boot disk, detach the boot disk and create a new disk from the mentioned snapshot:

gcloud compute instances stop $instance0

gcloud compute disks snapshot $instance0_bootdisk --snapshot-names $instance0_bootdisk_snapshot --zone $zone

gcloud compute instances detach-disk $instance0 --device-name $instance0_bootdisk

gcloud compute disks create $instance0_bootdisk_clone --source-snapshot $instance0_bootdisk_snapshot

Now, we attach the newly created disk as a data disk to the instance1, rw mount it, write to it, unmount it, and optionally detach it

gcloud compute instances attach-disk $instance1 --disk $instance0_bootdisk_clone --device-name $instance0_bootdisk_clone

gcloud compute ssh $instance1 --command "sudo mkdir -p $instance1_mntpath && sudo mount $instance1_mntdev $instance1_mntpath"

gcloud compute ssh $instance1  -- sudo vi $instance1_mntpath/etc/fstab" #for example
gcloud compute scp $instance1:/var/log/syslog . #for another example 

gcloud compute ssh $instance1 --command "sudo umount $instance1_mntpath"

gcloud compute instances detach-disk $instance1 --device-name $instance0_bootdisk_clone #not mandatory

Finally we attach the modified version of the created disk as the boot disk to instance0 in the hopes that the operating system boots.

gcloud compute instances attach-disk $instance0 --disk $instance0_bootdisk_clone --device-name $instance0_bootdisk --boot

gcloud compute instances start $instance0 #wait for completion
gcloud compute ssh $instance0 --command "ps 1"
  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags