1

For some reasons, the boot disk of my VM instance was no longer enough to use. And I wanted to move the whole /home directory to the new disk.

I followed the GCP guide to create and mount the disk to /data/diks-1/. Then I moved /home to /data/disk-1/home, and create a soft link to /home. Everything worked well just like what I expected.

However, I forgot to modify the fstab file for automatic mounting. And I restarted the VM instance...

Now, I cannot connect the instance via ssh, and have no idea about how to solve this. The whole /data/disk-1 directory must be unmounted, which include settings of all users. Are there any ways to remount the disk ?

6
  • Create a startup script to mount the disk. Then log in and modify fstab. I wrote an article that shows various recovery methods for a different problem that should help you: jhanley.com/google-cloud-recovering-from-ufw-lockout Commented Dec 12, 2021 at 7:25
  • Hi @JohnHanley. Thanks for your reply. I did try the method 1 with following value, but still could not log in with ssh. Also tried the method 2, it responded "Login incorrect". Could you please give me more help for this ? #!/bin/bash mount -o discard,defaults /dev/sdb /data/disk-1 ln -s /data/disk-1/home/ home Commented Dec 12, 2021 at 8:12
  • 1
    Enable serial console and boot with it. When the boot loader asks for kernel parameters, add init=/bin/bash. So nothing will be executed, just /bin/bash. That will give you a prompt (no password as login wont be executed either). Then you can remount / read-writable, e.g. with the command mount -o rw,remount /dev/sda1 /. Then you can do your changes. Commented Dec 12, 2021 at 9:55
  • To know what is going wrong, I need to see the error. The Serial Console can provide the boot logs. Edit your question with the script that you tried and the error result so that I can read it. Commented Dec 12, 2021 at 18:14
  • 1
    Hi @JohnHanley, I found out that I typed the wrong disk name into the startup-script. Thanks for your help and apologize for my newbie behavior. Commented Dec 13, 2021 at 14:49

1 Answer 1

2

Followings are the ways I re-mount the disk. Hope these could help anyone has the same problem like me.

  1. Click the EDIT button on the VM instance page.
  2. Click the Enable connecting to serial ports checkbox.
  3. Click SAVE button
  4. Build startup-script through the gcloud command Google Doc. (I used the console to build it, like @John Hanley's article wrote. But the UI seemed changed.)
  5. Key = startup-script, Value =

#! /bin/bash mount -o discard,defaults /dev/sdb /data/disk-1

  1. Reboot the VM instance, and you can ssh to instance now.
  2. Edit fstab after login and remove the startup-script then.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.