0
votes

I am trying to mount my external persistent disk using the command:

sudo mount -o discard, defaults /dev/sdb /mnt/working

what I want to do is to make it part of the startup script as I start my VM. I followed the instructions as per the link: https://cloud.google.com/compute/docs/startupscript#startupscriptrunninginstances

I added the script as follows:

custom metadata
key                       value
startup-script            #! /bin/bash
                           sudo mount -o discard,defaults /dev/sdb /mnt/working

However when I restart my VM , it does not execute it. What am I doing wrong here ?

EDITED to provide more information

Image: debian-10-buster-v20200910 I have not enabled error logging as I am not using the free version anymore but I am hoping that the default log viewer will show error logs. I don't see any. I also ran the script by logging into the vm instance:

sudo google_metadata_script_runner startup  

This also didn't help.

1
1) Check the logs for an error message for the mount command. 2) Does the Directory /mnt/working exist? 3) Is /dev/sdb formatted with a file system? 4) Normally you use /etc/fstab to mount file systems on startup. Edit your question with details on your investigation of this problem. Remember, commands can be distribution specific, include what OS you are using. - John Hanley
@JohnHanley, thanks for getting back. Let me answer your questions one-by-one. 1. I don't see any logs under the log viewer for the last 24hrs for mount command.2./mnt/working exists and I can mount this manually when running the above command 3. it is a formatted file system.4. I followed these steps from: cloud.google.com/compute/docs/disks/add-persistent-disk . I will edit the question and add these. - sunny
What log viewer? The mount command will write errors to /var/log/syslog or similar. You will also see the errors in the console output. help.ubuntu.com/community/LinuxLogFiles - John Hanley
@JohnHanley, thanks for your prompt response. Nothing in the syslog for sure I was following the same doc that you are mentioning. If you browse down to the section which says adding a startup script to your existing VM, it describes the steps. And yes, that is the script I want to execute. Looks like you found the problem . would love to hear that. I also took help from another stackoverflow response : stackoverflow.com/questions/30766912/… - sunny
you can also check the service logs when you SSH into the instance sudo journalctl -u google-startup-scripts.service - lukaszberwid

1 Answers

1
votes

Issue was primarily a newline character between /mnt/sdb /mnt/working. This prevented from the startup script from getting executed. Thanks to the tip from Lukaszberwid, I ran the

 sudo journalctl -u google-startup-scripts.service

was able to spot the issue. I was wondering if the metadata value field for the startup script can be expanded to the right or made little bigger to spot such cut and paste issues.