4 Replies Latest reply on Dec 30, 2011 8:37 AM by gkho978

    Error with first boot script

    gkho978 Novice

      When the firstboot script is executed, it has problems with certain if statements and declares.

       

      Environment:

      VMware Studio Version - 2.5.0.0 Build 387333

      ubuntu-10.04.3-server-amd64.iso

       

       

      Example firstboot script

      #!/bin/bash

       

      exec > /opt/vmware/var/log/firstboot 2>&1

       

      if [[ "$(uname -m)" =~ x86_64 ]]; then

        ARCH="64"

      else

        ARCH="32"

      fi

       

      declare -a VARIABLES=(\

      "mercury"\

      "venus"\

      "earth"\

      )

       

       

      The appliance would choke on the script and the log file would show something like:

      /opt/vmware/etc/isv/firstboot: 9: [[: not found

      /opt/vmware/etc/isv/firstboot: 11: Syntax error: "(" unexpected

       

      When the script is executed manually after first boot, it works fine without errors.

       

      I'm not too sure why it would fail when executed during first boot, but when executed not manually.

        • 1. Re: Error with first boot script
          chorgeas Hot Shot

          1. Debug the script using -x option. Redirect everything to some log file.

          e.g.

          #!/bin/bash -x

          {

          stmt 1

          stmt 2

          stmt 3

          stmt 4

          } >> /root/test.log

           

          2. Insted of exec use full path like /bin/exec.

           

          3. Call your script from /etc/rc.local file and then delete it after firstboot. You can do it by writing another shell script.

           

          If this wont work then please upload /root/test.log so that we can debug more.

          • 2. Re: Error with first boot script
            rovermanter Lurker

            Hello gkho978!

             

            What is the status of your error now?

             

            Did you manage what was happened?

            • 3. Re: Error with first boot script
              gkho978 Novice

              Thanks for the suggestion chorgeas. I'm creating the build now with those tips and will have an output soon.

              • 4. Re: Error with first boot script
                gkho978 Novice

                After thinking about this overnight, I realized that the statements used are bash specific. The issue is reproducible if I were to execute with sh (e.g. /bin/sh /opt/vmware/etc/isv/firstboot). So it seems that even though the firstboot file starts with "!#/bin/bash", the shell executing it isn't bash.

                 

                I was misled by the templates default first boot script that starts with "!#/bin/bash."

                 

                As a workaround, I performed the following:

                - Created a script with the desired content

                - Packaged it via "mkpkg"

                - Saved the resulted deb package to default application repository (i.e. /opt/vmware/www/ISV/appliancePackages)

                - Edit the profile's first boot script to execute the script with the desired shell. (e.g. /bin/bash /root/customfirstbootscript)

                 

                Looks like most of VMWare Studio's builtin templates have "!#/bin/bash" in their first boot and subsequent boot script templates. As a follow up question, how is the first boot script being executed?