Creating a custom template, based on some existing LXC template after running the instance at least once

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












(Please note that this question is about LXC 1.x, whereas this one is about LXC 2.x/LXD)



I scoured the web for an answer to this one, but couldn't come up with any reasonably non-hacky answer.



What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.



So my current approach is to lxc launch ubuntu:lts CONTAINER and then use lxc exec CONTAINER -- ... to run a script I authored (after pushing it into the container) to perform my customizations.



What I get using this approach is a reasonably customized container. Alas, there's a catch. The container at this point has been primed by cloud-init and it's a container instance, not an image/template.



So this is where I'm at a loss now. What I would need is to turn my container back into an image (should be doable by using lxc publish) and either undo the changes done to it by cloud-init or at least "cock" cloud-init again so it triggers the next time the image is used as source for lxc init or lxc launch. Alternatively, maybe there's a way to completely disable cloud-init when I lxc launch from the upstream image?



Is there an authoritative way? Even though I looked through all kinds of documentation, including the Markdown documentation in the LXD repository as well as the blog series by Stéphane Graber (LXD project lead), especially [5/12], I was unable to find a suitable approach. Perhaps I just missed it (that's to say, I'll be happy to read through more documentation if you know some that describes what I need).



LXC version used is 2.20 (i.e. I'm using the LXD frontend).







share|improve this question
























    up vote
    1
    down vote

    favorite












    (Please note that this question is about LXC 1.x, whereas this one is about LXC 2.x/LXD)



    I scoured the web for an answer to this one, but couldn't come up with any reasonably non-hacky answer.



    What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.



    So my current approach is to lxc launch ubuntu:lts CONTAINER and then use lxc exec CONTAINER -- ... to run a script I authored (after pushing it into the container) to perform my customizations.



    What I get using this approach is a reasonably customized container. Alas, there's a catch. The container at this point has been primed by cloud-init and it's a container instance, not an image/template.



    So this is where I'm at a loss now. What I would need is to turn my container back into an image (should be doable by using lxc publish) and either undo the changes done to it by cloud-init or at least "cock" cloud-init again so it triggers the next time the image is used as source for lxc init or lxc launch. Alternatively, maybe there's a way to completely disable cloud-init when I lxc launch from the upstream image?



    Is there an authoritative way? Even though I looked through all kinds of documentation, including the Markdown documentation in the LXD repository as well as the blog series by Stéphane Graber (LXD project lead), especially [5/12], I was unable to find a suitable approach. Perhaps I just missed it (that's to say, I'll be happy to read through more documentation if you know some that describes what I need).



    LXC version used is 2.20 (i.e. I'm using the LXD frontend).







    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      (Please note that this question is about LXC 1.x, whereas this one is about LXC 2.x/LXD)



      I scoured the web for an answer to this one, but couldn't come up with any reasonably non-hacky answer.



      What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.



      So my current approach is to lxc launch ubuntu:lts CONTAINER and then use lxc exec CONTAINER -- ... to run a script I authored (after pushing it into the container) to perform my customizations.



      What I get using this approach is a reasonably customized container. Alas, there's a catch. The container at this point has been primed by cloud-init and it's a container instance, not an image/template.



      So this is where I'm at a loss now. What I would need is to turn my container back into an image (should be doable by using lxc publish) and either undo the changes done to it by cloud-init or at least "cock" cloud-init again so it triggers the next time the image is used as source for lxc init or lxc launch. Alternatively, maybe there's a way to completely disable cloud-init when I lxc launch from the upstream image?



      Is there an authoritative way? Even though I looked through all kinds of documentation, including the Markdown documentation in the LXD repository as well as the blog series by Stéphane Graber (LXD project lead), especially [5/12], I was unable to find a suitable approach. Perhaps I just missed it (that's to say, I'll be happy to read through more documentation if you know some that describes what I need).



      LXC version used is 2.20 (i.e. I'm using the LXD frontend).







      share|improve this question












      (Please note that this question is about LXC 1.x, whereas this one is about LXC 2.x/LXD)



      I scoured the web for an answer to this one, but couldn't come up with any reasonably non-hacky answer.



      What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.



      So my current approach is to lxc launch ubuntu:lts CONTAINER and then use lxc exec CONTAINER -- ... to run a script I authored (after pushing it into the container) to perform my customizations.



      What I get using this approach is a reasonably customized container. Alas, there's a catch. The container at this point has been primed by cloud-init and it's a container instance, not an image/template.



      So this is where I'm at a loss now. What I would need is to turn my container back into an image (should be doable by using lxc publish) and either undo the changes done to it by cloud-init or at least "cock" cloud-init again so it triggers the next time the image is used as source for lxc init or lxc launch. Alternatively, maybe there's a way to completely disable cloud-init when I lxc launch from the upstream image?



      Is there an authoritative way? Even though I looked through all kinds of documentation, including the Markdown documentation in the LXD repository as well as the blog series by Stéphane Graber (LXD project lead), especially [5/12], I was unable to find a suitable approach. Perhaps I just missed it (that's to say, I'll be happy to read through more documentation if you know some that describes what I need).



      LXC version used is 2.20 (i.e. I'm using the LXD frontend).









      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 27 '17 at 15:59









      0xC0000022L

      7,1101359107




      7,1101359107




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          On the linked page [5/12] by Stéphane Graber, you can find a second approach:




          Manually building an image



          Building your own image is also pretty simple.



          1. Generate a container filesystem. This entirely depends on the distribution you’re using. For Ubuntu and Debian, it would be by using
            debootstrap.

          2. Configure anything that’s needed for the distribution to work properly in a container (if anything is needed).

          3. Make a tarball of that container filesystem, optionally compress it.

          4. Write a new metadata.yaml file based on the one described above.

          5. Create another tarball containing that metadata.yaml file.

          6. Import those two tarballs as a LXD image with:



          This way, you don't have to start the container, before you publish the image. You can start with an existing image:



          $ lxc image copy ubuntu:16.04/amd64 local: --alias ubuntu
          $ mkdir export-directory
          $ lxc image export ubuntu export-directory
          $ cd export-directory
          $ ls
          5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.squashfs
          meta-5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.tar.xz

          $ mkdir meta squashfs
          $ tar -xf *.tar.xz -D meta
          $ sudo unsquashfs -f -d squash/ *squashfs


          Now you can adjust files or even chroot into the squash directory. Then you can tar both directories and import the adjusted image with:



          lxc image import <metadata tarball> <rootfs tarball> --alias my-adjusted-image





          share|improve this answer






















          • Thanks, but here's what I asked for: What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.
            – 0xC0000022L
            Nov 27 '17 at 21:35











          • I hope my update will address those requests.
            – ctx
            Nov 28 '17 at 10:07










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407315%2fcreating-a-custom-template-based-on-some-existing-lxc-template-after-running-th%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          On the linked page [5/12] by Stéphane Graber, you can find a second approach:




          Manually building an image



          Building your own image is also pretty simple.



          1. Generate a container filesystem. This entirely depends on the distribution you’re using. For Ubuntu and Debian, it would be by using
            debootstrap.

          2. Configure anything that’s needed for the distribution to work properly in a container (if anything is needed).

          3. Make a tarball of that container filesystem, optionally compress it.

          4. Write a new metadata.yaml file based on the one described above.

          5. Create another tarball containing that metadata.yaml file.

          6. Import those two tarballs as a LXD image with:



          This way, you don't have to start the container, before you publish the image. You can start with an existing image:



          $ lxc image copy ubuntu:16.04/amd64 local: --alias ubuntu
          $ mkdir export-directory
          $ lxc image export ubuntu export-directory
          $ cd export-directory
          $ ls
          5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.squashfs
          meta-5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.tar.xz

          $ mkdir meta squashfs
          $ tar -xf *.tar.xz -D meta
          $ sudo unsquashfs -f -d squash/ *squashfs


          Now you can adjust files or even chroot into the squash directory. Then you can tar both directories and import the adjusted image with:



          lxc image import <metadata tarball> <rootfs tarball> --alias my-adjusted-image





          share|improve this answer






















          • Thanks, but here's what I asked for: What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.
            – 0xC0000022L
            Nov 27 '17 at 21:35











          • I hope my update will address those requests.
            – ctx
            Nov 28 '17 at 10:07














          up vote
          0
          down vote













          On the linked page [5/12] by Stéphane Graber, you can find a second approach:




          Manually building an image



          Building your own image is also pretty simple.



          1. Generate a container filesystem. This entirely depends on the distribution you’re using. For Ubuntu and Debian, it would be by using
            debootstrap.

          2. Configure anything that’s needed for the distribution to work properly in a container (if anything is needed).

          3. Make a tarball of that container filesystem, optionally compress it.

          4. Write a new metadata.yaml file based on the one described above.

          5. Create another tarball containing that metadata.yaml file.

          6. Import those two tarballs as a LXD image with:



          This way, you don't have to start the container, before you publish the image. You can start with an existing image:



          $ lxc image copy ubuntu:16.04/amd64 local: --alias ubuntu
          $ mkdir export-directory
          $ lxc image export ubuntu export-directory
          $ cd export-directory
          $ ls
          5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.squashfs
          meta-5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.tar.xz

          $ mkdir meta squashfs
          $ tar -xf *.tar.xz -D meta
          $ sudo unsquashfs -f -d squash/ *squashfs


          Now you can adjust files or even chroot into the squash directory. Then you can tar both directories and import the adjusted image with:



          lxc image import <metadata tarball> <rootfs tarball> --alias my-adjusted-image





          share|improve this answer






















          • Thanks, but here's what I asked for: What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.
            – 0xC0000022L
            Nov 27 '17 at 21:35











          • I hope my update will address those requests.
            – ctx
            Nov 28 '17 at 10:07












          up vote
          0
          down vote










          up vote
          0
          down vote









          On the linked page [5/12] by Stéphane Graber, you can find a second approach:




          Manually building an image



          Building your own image is also pretty simple.



          1. Generate a container filesystem. This entirely depends on the distribution you’re using. For Ubuntu and Debian, it would be by using
            debootstrap.

          2. Configure anything that’s needed for the distribution to work properly in a container (if anything is needed).

          3. Make a tarball of that container filesystem, optionally compress it.

          4. Write a new metadata.yaml file based on the one described above.

          5. Create another tarball containing that metadata.yaml file.

          6. Import those two tarballs as a LXD image with:



          This way, you don't have to start the container, before you publish the image. You can start with an existing image:



          $ lxc image copy ubuntu:16.04/amd64 local: --alias ubuntu
          $ mkdir export-directory
          $ lxc image export ubuntu export-directory
          $ cd export-directory
          $ ls
          5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.squashfs
          meta-5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.tar.xz

          $ mkdir meta squashfs
          $ tar -xf *.tar.xz -D meta
          $ sudo unsquashfs -f -d squash/ *squashfs


          Now you can adjust files or even chroot into the squash directory. Then you can tar both directories and import the adjusted image with:



          lxc image import <metadata tarball> <rootfs tarball> --alias my-adjusted-image





          share|improve this answer














          On the linked page [5/12] by Stéphane Graber, you can find a second approach:




          Manually building an image



          Building your own image is also pretty simple.



          1. Generate a container filesystem. This entirely depends on the distribution you’re using. For Ubuntu and Debian, it would be by using
            debootstrap.

          2. Configure anything that’s needed for the distribution to work properly in a container (if anything is needed).

          3. Make a tarball of that container filesystem, optionally compress it.

          4. Write a new metadata.yaml file based on the one described above.

          5. Create another tarball containing that metadata.yaml file.

          6. Import those two tarballs as a LXD image with:



          This way, you don't have to start the container, before you publish the image. You can start with an existing image:



          $ lxc image copy ubuntu:16.04/amd64 local: --alias ubuntu
          $ mkdir export-directory
          $ lxc image export ubuntu export-directory
          $ cd export-directory
          $ ls
          5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.squashfs
          meta-5f364e2e3f460773a79e9bec2edb5e993d236f035f70267923d43ab22ae3bb62.tar.xz

          $ mkdir meta squashfs
          $ tar -xf *.tar.xz -D meta
          $ sudo unsquashfs -f -d squash/ *squashfs


          Now you can adjust files or even chroot into the squash directory. Then you can tar both directories and import the adjusted image with:



          lxc image import <metadata tarball> <rootfs tarball> --alias my-adjusted-image






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 28 '17 at 10:04

























          answered Nov 27 '17 at 17:11









          ctx

          1,547314




          1,547314











          • Thanks, but here's what I asked for: What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.
            – 0xC0000022L
            Nov 27 '17 at 21:35











          • I hope my update will address those requests.
            – ctx
            Nov 28 '17 at 10:07
















          • Thanks, but here's what I asked for: What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.
            – 0xC0000022L
            Nov 27 '17 at 21:35











          • I hope my update will address those requests.
            – ctx
            Nov 28 '17 at 10:07















          Thanks, but here's what I asked for: What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.
          – 0xC0000022L
          Nov 27 '17 at 21:35





          Thanks, but here's what I asked for: What I am looking for is an approach to fashion an existing template a way I'd like to. In particular what I'm after is to customize the upstream Ubuntu cloud image by making various changes in its root FS and adding/changing configuration.
          – 0xC0000022L
          Nov 27 '17 at 21:35













          I hope my update will address those requests.
          – ctx
          Nov 28 '17 at 10:07




          I hope my update will address those requests.
          – ctx
          Nov 28 '17 at 10:07

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407315%2fcreating-a-custom-template-based-on-some-existing-lxc-template-after-running-th%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay