Install Custom LXC Image

Post Reply
Cygon
Starting out
Posts: 15
Joined: Sun Feb 19, 2017 5:31 pm

Install Custom LXC Image

Post by Cygon » Thu Mar 30, 2017 1:49 am

Hi!

My chosen flavor of Linux is Gentoo and if I run services on my NAS, that's the environment I'd like to run them in. I'm wavering between replacing QTS outright and just running a Gentoo system via Container Station.

I noticed that all the LXC images available in Container Station are published directly by QNAP. Is it possible to install an LXC image from another source?
The official LXC image repository has Gentoo images, for example.

Cygon
Starting out
Posts: 15
Joined: Sun Feb 19, 2017 5:31 pm

Re: Install Custom LXC Image

Post by Cygon » Thu Mar 30, 2017 2:09 am

Lo and behold, the standard LXC installation on my QNAP ships with a script to generate a Gentoo image:

Image

Perhaps I could... set up an LXC image normally in Container Station and then, via SSH, delete it and ninja a Gentoo image into its place? :D

Cygon
Starting out
Posts: 15
Joined: Sun Feb 19, 2017 5:31 pm

Re: Install Custom LXC Image

Post by Cygon » Wed Apr 05, 2017 4:04 am

Done.

Created an Ubuntu container in the QNAP UI, then replaced it with a Gentoo system from SSH.

Image

Appears to be working fine.

Cygon
Starting out
Posts: 15
Joined: Sun Feb 19, 2017 5:31 pm

Re: Install Custom LXC Image

Post by Cygon » Fri Apr 07, 2017 9:47 pm

In case anyone wants to do the same, here's how it works:

  • Log into your QNAP system via SSH (i.e. enable ssh, then 'ssh -l admin 192.168.0.123')
  • Create a new LXC container: 'lxc-create --template=download --name=mygentoo'
  • You'll be asked to pick an OS, Version and Architecture. In my case, I answered 'gentoo', 'current' and 'amd64'
  • Make a backup of /var/lib/lxc/mygentoo: 'cp -rp /var/lib/lxc/mygentoo /share/CACHEDEV1_DATA/'
  • Kill the LXC container again: 'lxc-destroy --name=mygentoo'
  • Create an LXC container of the same name via QNAP's container station normally
  • Replace the 'rootfs' folder with your backup: 'mv /var/lib/lxc/mygentoo/rootfs /var/lib/lxc/mygentoo/rootfs-old && mv /share/CACHEDEV1_DATA/mygentoo/rootfs /var/lib/lxc/mygentoo/'
  • Set 'gentoo.common.conf' as configuration master: 'vi /var/lib/lxc/mygentoo/config' (edit lxc.include to use '/usr/share/lxc/config/gentoo.common.conf')
  • Display the image as a gentoo container: 'vi /var/lib/lxc/mygentoo/qnap.json' (edit image to 'gentoo' and version to 'current').
  • Chroot into your Gentoo system: 'chroot /var/lib/lxc/mygentoo/rootfs /bin/bash'
  • Set the root password: 'passwd' (only when chrooting succeeds and you see the red/blue Gentoo bash)
  • Leave the chroot again: 'exit'

It may be possible to shorten steps 1-7 (after 'lxc-create', the container shows up in the QNAP UI), but I worried QNAP's Container Station might store additional configuration somewhere, so I went the long route and turned a normally created container into a Gentoo container. Been running this for a few days now and despite the ancient kernel used by QNAP, it runs stable (but then, so does Ubuntu 16 which also would be expecting a newer kernel).

Image

spammenot66
New here
Posts: 3
Joined: Mon Jan 20, 2020 2:09 pm

Re: Install Custom LXC Image

Post by spammenot66 » Sun Jul 26, 2020 8:25 am

Thanks Cygon for the detail write up. Based on the original write up, below is a simpler way to update the LXC image on your qnap container station.
  1. Log into your QNAP system via SSH (i.e. enable ssh, then 'ssh -l admin 192.168.0.123')
  2. Create a new LXC container. Its going to give you a list of all LXC image, Version and Architecture that you can choose. In this case, enter 'gentoo', 'current' and 'amd64': 'lxc-create --template=download --name=mygentoo'
  3. Its going to download and unpack it at /var/lib/lxc/mygentoo
  4. If you're already using container station, then a shared folder should already be avail. If you're using default setting, the shared folder name would be "container". The path where all of your LXC image would be /share/CACHEDEV1_DATA/container/container-station-data/image/lxc. Feel free to use file station to confirm.
    Go to the directory: 'cd /share/CACHEDEV1_DATA/container2/container-station-data/image/lxc/'
  5. copy any of the current image folder and create it for the new gentoo. I've followed the same pattern from qnap and used <package>-<version>: 'cp -rp debian-buster gentoo-current'
  6. remove the content in the image folder: 'cd /share/CACHEDEV1_DATA/container2/container-station-data/image/lxc/gentoo-current/image && rm -R config && rm -R rootf '
  7. Copy over the image to the containerstation image directory: 'mv /var/lib/lxc/mygentoo/config /share/CACHEDEV1_DATA/container2/container-station-data/image/lxc/gentoo-current/image && mv /var/lib/lxc/mygentoo/rootfs /share/CACHEDEV1_DATA/container2/container-station-data/image/lxc/gentoo-current/image'
  8. Update the configuration file: 'vi share/CACHEDEV1_DATA/container2/container-station-data/image/lxc/gentoo-current/control
    '
    I would update the following lines to match your package, architecture and version to ensure it matches up to what you've downloaded.

    Code: Select all

    Package: gentoo
    Architecture: amd64
    Version: current
    Q-AppName: LXC Gentoo image
  9. In the Qnap UI, stop the container station, and restart it

kjp2807
New here
Posts: 2
Joined: Wed Oct 14, 2020 7:08 am

Re: Install Custom LXC Image

Post by kjp2807 » Wed Oct 14, 2020 7:33 am

folks, step 2 is not working for me, can you help me? template does exist in /usr/share/lxc/templates dir

Code: Select all

# lxc-create -template=/usr/share/lxc/templates/lxc-centos --name=mycentos
[i]
Host CPE ID from /etc/os-release:
/usr/share/lxc/templates/lxc-centos: line 817: dnsdomainname: command not found
'yum' command is missing[/i]

Post Reply

Return to “Container Station”