Setting HOSTNAME on startup












0















Our lab group just purchased a dozen or so new workstations. They're Dells, so perhaps conveniently they report their service tag with dmidecode -s system-serial-number. We're thinking of using Clonezilla to easily deploy images across them all, but they each need to be set with a specific hostname and static IP address. So, combining the two seems straightforward using a lookup something like:



declare -A tags
tags=(["HKX321K"]="ws1name 10.32.54.10"
["HBZ321G"]="ws2name 10.32.54.11"
)
tag=$(sudo dmidecode -s system-serial-number)
read -a nameip <<< "${tags[$tag]}"
wsname=${nameip[0]}
wsip=${nameip[1]}


sed or the like could then make a /etc/hosts, hostname, and network/interfaces files from some templates. However, is modifying those files sufficient, and how do I execute the "personalization" script very early in boot before Ubuntu starts setting stuff up?



Is my plan bad for another unforeseen reason; what hidden pitfalls might await?










share|improve this question



























    0















    Our lab group just purchased a dozen or so new workstations. They're Dells, so perhaps conveniently they report their service tag with dmidecode -s system-serial-number. We're thinking of using Clonezilla to easily deploy images across them all, but they each need to be set with a specific hostname and static IP address. So, combining the two seems straightforward using a lookup something like:



    declare -A tags
    tags=(["HKX321K"]="ws1name 10.32.54.10"
    ["HBZ321G"]="ws2name 10.32.54.11"
    )
    tag=$(sudo dmidecode -s system-serial-number)
    read -a nameip <<< "${tags[$tag]}"
    wsname=${nameip[0]}
    wsip=${nameip[1]}


    sed or the like could then make a /etc/hosts, hostname, and network/interfaces files from some templates. However, is modifying those files sufficient, and how do I execute the "personalization" script very early in boot before Ubuntu starts setting stuff up?



    Is my plan bad for another unforeseen reason; what hidden pitfalls might await?










    share|improve this question

























      0












      0








      0








      Our lab group just purchased a dozen or so new workstations. They're Dells, so perhaps conveniently they report their service tag with dmidecode -s system-serial-number. We're thinking of using Clonezilla to easily deploy images across them all, but they each need to be set with a specific hostname and static IP address. So, combining the two seems straightforward using a lookup something like:



      declare -A tags
      tags=(["HKX321K"]="ws1name 10.32.54.10"
      ["HBZ321G"]="ws2name 10.32.54.11"
      )
      tag=$(sudo dmidecode -s system-serial-number)
      read -a nameip <<< "${tags[$tag]}"
      wsname=${nameip[0]}
      wsip=${nameip[1]}


      sed or the like could then make a /etc/hosts, hostname, and network/interfaces files from some templates. However, is modifying those files sufficient, and how do I execute the "personalization" script very early in boot before Ubuntu starts setting stuff up?



      Is my plan bad for another unforeseen reason; what hidden pitfalls might await?










      share|improve this question














      Our lab group just purchased a dozen or so new workstations. They're Dells, so perhaps conveniently they report their service tag with dmidecode -s system-serial-number. We're thinking of using Clonezilla to easily deploy images across them all, but they each need to be set with a specific hostname and static IP address. So, combining the two seems straightforward using a lookup something like:



      declare -A tags
      tags=(["HKX321K"]="ws1name 10.32.54.10"
      ["HBZ321G"]="ws2name 10.32.54.11"
      )
      tag=$(sudo dmidecode -s system-serial-number)
      read -a nameip <<< "${tags[$tag]}"
      wsname=${nameip[0]}
      wsip=${nameip[1]}


      sed or the like could then make a /etc/hosts, hostname, and network/interfaces files from some templates. However, is modifying those files sufficient, and how do I execute the "personalization" script very early in boot before Ubuntu starts setting stuff up?



      Is my plan bad for another unforeseen reason; what hidden pitfalls might await?







      boot hostname






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 22 '14 at 4:11









      Nick TNick T

      1,63721227




      1,63721227






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Yes, changing those files is sufficient. You can use the hostnamectl command to change the hostname easily. These changes need to be made only once. So you can make the changes via rc.local or something similar to run once, remove itself from whatever caused it to run at boot and then reboot one before going on to do other things.



          If a reboot is too much extra work, you can try scheduling an Upstart job. An Upstart job which has a start on startup condition will run this as early as possible. Better yet, a job with start on local-filesystems will run early enough to be sure necessary filesystems are mounted.






          share|improve this answer


























          • Are you saying that I would need to let it boot all the way to login prompt (I don't know when rc.local runs exactly), let that config script run (which could self-destruct or otherwise inactivate itself) then reboot for changes to take effect? Is there a way to do it in one go?

            – Nick T
            Jul 22 '14 at 4:43











          • @NickT you don't need to do that, it's just the simplest way, and pretty much automated, so all it really does is add a couple of minutes to your installation time. You can create an upstart job which has a start on startup condition to achieve this as early as possible or better start on local-filesystems early enough to be sure necessary filesystems are mounted .

            – muru
            Jul 22 '14 at 4:47













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f500916%2fsetting-hostname-on-startup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Yes, changing those files is sufficient. You can use the hostnamectl command to change the hostname easily. These changes need to be made only once. So you can make the changes via rc.local or something similar to run once, remove itself from whatever caused it to run at boot and then reboot one before going on to do other things.



          If a reboot is too much extra work, you can try scheduling an Upstart job. An Upstart job which has a start on startup condition will run this as early as possible. Better yet, a job with start on local-filesystems will run early enough to be sure necessary filesystems are mounted.






          share|improve this answer


























          • Are you saying that I would need to let it boot all the way to login prompt (I don't know when rc.local runs exactly), let that config script run (which could self-destruct or otherwise inactivate itself) then reboot for changes to take effect? Is there a way to do it in one go?

            – Nick T
            Jul 22 '14 at 4:43











          • @NickT you don't need to do that, it's just the simplest way, and pretty much automated, so all it really does is add a couple of minutes to your installation time. You can create an upstart job which has a start on startup condition to achieve this as early as possible or better start on local-filesystems early enough to be sure necessary filesystems are mounted .

            – muru
            Jul 22 '14 at 4:47


















          0














          Yes, changing those files is sufficient. You can use the hostnamectl command to change the hostname easily. These changes need to be made only once. So you can make the changes via rc.local or something similar to run once, remove itself from whatever caused it to run at boot and then reboot one before going on to do other things.



          If a reboot is too much extra work, you can try scheduling an Upstart job. An Upstart job which has a start on startup condition will run this as early as possible. Better yet, a job with start on local-filesystems will run early enough to be sure necessary filesystems are mounted.






          share|improve this answer


























          • Are you saying that I would need to let it boot all the way to login prompt (I don't know when rc.local runs exactly), let that config script run (which could self-destruct or otherwise inactivate itself) then reboot for changes to take effect? Is there a way to do it in one go?

            – Nick T
            Jul 22 '14 at 4:43











          • @NickT you don't need to do that, it's just the simplest way, and pretty much automated, so all it really does is add a couple of minutes to your installation time. You can create an upstart job which has a start on startup condition to achieve this as early as possible or better start on local-filesystems early enough to be sure necessary filesystems are mounted .

            – muru
            Jul 22 '14 at 4:47
















          0












          0








          0







          Yes, changing those files is sufficient. You can use the hostnamectl command to change the hostname easily. These changes need to be made only once. So you can make the changes via rc.local or something similar to run once, remove itself from whatever caused it to run at boot and then reboot one before going on to do other things.



          If a reboot is too much extra work, you can try scheduling an Upstart job. An Upstart job which has a start on startup condition will run this as early as possible. Better yet, a job with start on local-filesystems will run early enough to be sure necessary filesystems are mounted.






          share|improve this answer















          Yes, changing those files is sufficient. You can use the hostnamectl command to change the hostname easily. These changes need to be made only once. So you can make the changes via rc.local or something similar to run once, remove itself from whatever caused it to run at boot and then reboot one before going on to do other things.



          If a reboot is too much extra work, you can try scheduling an Upstart job. An Upstart job which has a start on startup condition will run this as early as possible. Better yet, a job with start on local-filesystems will run early enough to be sure necessary filesystems are mounted.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 22 '14 at 5:54

























          answered Jul 22 '14 at 4:34









          murumuru

          1




          1













          • Are you saying that I would need to let it boot all the way to login prompt (I don't know when rc.local runs exactly), let that config script run (which could self-destruct or otherwise inactivate itself) then reboot for changes to take effect? Is there a way to do it in one go?

            – Nick T
            Jul 22 '14 at 4:43











          • @NickT you don't need to do that, it's just the simplest way, and pretty much automated, so all it really does is add a couple of minutes to your installation time. You can create an upstart job which has a start on startup condition to achieve this as early as possible or better start on local-filesystems early enough to be sure necessary filesystems are mounted .

            – muru
            Jul 22 '14 at 4:47





















          • Are you saying that I would need to let it boot all the way to login prompt (I don't know when rc.local runs exactly), let that config script run (which could self-destruct or otherwise inactivate itself) then reboot for changes to take effect? Is there a way to do it in one go?

            – Nick T
            Jul 22 '14 at 4:43











          • @NickT you don't need to do that, it's just the simplest way, and pretty much automated, so all it really does is add a couple of minutes to your installation time. You can create an upstart job which has a start on startup condition to achieve this as early as possible or better start on local-filesystems early enough to be sure necessary filesystems are mounted .

            – muru
            Jul 22 '14 at 4:47



















          Are you saying that I would need to let it boot all the way to login prompt (I don't know when rc.local runs exactly), let that config script run (which could self-destruct or otherwise inactivate itself) then reboot for changes to take effect? Is there a way to do it in one go?

          – Nick T
          Jul 22 '14 at 4:43





          Are you saying that I would need to let it boot all the way to login prompt (I don't know when rc.local runs exactly), let that config script run (which could self-destruct or otherwise inactivate itself) then reboot for changes to take effect? Is there a way to do it in one go?

          – Nick T
          Jul 22 '14 at 4:43













          @NickT you don't need to do that, it's just the simplest way, and pretty much automated, so all it really does is add a couple of minutes to your installation time. You can create an upstart job which has a start on startup condition to achieve this as early as possible or better start on local-filesystems early enough to be sure necessary filesystems are mounted .

          – muru
          Jul 22 '14 at 4:47







          @NickT you don't need to do that, it's just the simplest way, and pretty much automated, so all it really does is add a couple of minutes to your installation time. You can create an upstart job which has a start on startup condition to achieve this as early as possible or better start on local-filesystems early enough to be sure necessary filesystems are mounted .

          – muru
          Jul 22 '14 at 4:47




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Ask Ubuntu!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f500916%2fsetting-hostname-on-startup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Category:香港粉麵

          List *all* the tuples!

          Channel [V]