0

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.

sunny
  • 643
  • 2
  • 11
  • 29
  • 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 Sep 21 '20 at 22:57
  • @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: https://cloud.google.com/compute/docs/disks/add-persistent-disk . I will edit the question and add these. – sunny Sep 22 '20 at 03:25
  • 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. https://help.ubuntu.com/community/LinuxLogFiles – John Hanley Sep 22 '20 at 03:35
  • @JohnHanley, please note that it works manually when I explicitly run the command as above from my VM instance. I was hoping to have the same executed as part of the startup script. Not sure what you mean console. If you meant google console - no errors came up. the VM was booted properly. /var/log/syslog didn't have any error message. I don't think the script ever got executed as part of the bootup. I could be wrong. – sunny Sep 22 '20 at 03:48
  • Console means serial port console where you can view the Linux console output. https://cloud.google.com/compute/docs/instances/viewing-serial-port-output If the mount command is not shown in syslog then the command did not run. This means an error with your startup script. That will also be in /var/log/syslog (search for warning or error). You have an error somewhere. In your question, you show your startup script. Is that your exact script? How are you adding that? It is not correct. https://cloud.google.com/compute/docs/startupscript – John Hanley Sep 22 '20 at 04:31
  • 1
    @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 : https://stackoverflow.com/questions/30766912/how-do-i-add-a-startup-script-to-an-existing-vm-from-the-developer-console – sunny Sep 22 '20 at 04:52
  • 1
    you can also check the service logs when you SSH into the instance `sudo journalctl -u google-startup-scripts.service` – lukaszberwid Sep 22 '20 at 10:43
  • @lukaszberwid, thanks - your tip worked!. There was a error parsing the command in the startup script. Somehow there was a newline feed btw /dev/sdb and /mnt/working. It was therefore treating them as 2 separate lines. Only after I expanded metadata value field , I found this mistake. Maybe an cut&paste issue from the ssh console. I was wondering if the value field can be extended to the right as there is lot of real estate. This may prevent such typo issues or someway to see a newline feed. – sunny Sep 22 '20 at 16:58
  • @lukaszberwid, to answer to the earlier question by John ,why I didn't add it to the /etc/fstab,I did try to add add to the fstab to make the device automatically mount again when instance restarts as per the instructions in https://cloud.google.com/compute/docs/disks/add-persistent-disk. However, it does not mount and disables my ssh login. The system did restart and came up with external IP, but I could not login via ssh. I had to remove the entry from the fstab via serial console to get me back into action. Not sure why. – sunny Sep 22 '20 at 17:18

1 Answers1

1

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.

sunny
  • 643
  • 2
  • 11
  • 29
  • you can create a feature request for compute engine in public google [issue tracker](https://issuetracker.google.com/issues/new?component=187134&template=1162898) – lukaszberwid Sep 23 '20 at 10:14
  • You might not want to cut and paste the script, but rather write the script locally, run any tests/linter, and upload the script file as is with these instructions: https://cloud.google.com/compute/docs/startupscript#startupscriptlocalfile – Jofre Oct 05 '20 at 09:14