4

While I originally wanted to entirely replace the Linux distribution my NAS uses, I meanwhile came to the conclusion that it would be better to leave the existing system as unmodified as possible and merely supplement it via Gentoo (or Arch) Linux - which is basically what the answer to the previous question suggested. So currently the only modification to the original system consist of a /gentoo directory that I chroot into via the following script:

#!/bin/bash
set -e

cp -L /etc/resolv.conf etc/ # for internet access
cp -P /etc/localtime etc/   # to keep the timezones consistent
cp -d /etc/mtab etc/        # to check mounted systems
# cp /etc/{mdadm.conf,hosts,fstab} etc  # Maybe?
mount --rbind /mnt mnt      # use host's mounts
mkdir host; mount --bind / host
mount --bind /var/log var/log # or run own syslogd?

mount --bind /dev dev
mount -t devpts devpts dev/pts
mount --bind /proc proc  # or mount -t procfs proc proc?
mount --bind /sys sys    # or mount -t sysfs sysfs sys?
chroot . /usr/sbin/sshd -p 22222
# chroot . /bin/env -i TERM=$TERM /bin/bash

Now I can simply ssh into the host via port 22222 and end up in the chroot environment, which basically behaves like Gentoo Linux, and this script can be run from the host's /etc/init.d/rcS.

But of course I don't want to end up starting every Gentoo service I'd like to use manually that way - that's what OpenRC (or systemd, if preferred) is good for after all. So my major question is

What Gentoo command should chroot execute in order to properly "boot" the Gentoo Linux on top of the host Linux with as little interference as possible?

With as little interference as possible I mean it should not attempt to remount the filesystem (but at the same time it would be nice if Gentoo's mount would work correctly) - so simply running init is probably not correct, some modifactions to the OpenRC configuration will probably be necessary, but which ones?

Additionally, there's the question of host daemons - should I use them or have Gentoo run it's own instances of e.g. crond and syslogd (and how would they need to be set up in order to not interfere with the host instances?), or should I go even further and entirely virtualize Gentoo? As mentioned in another question it would be neat to have the Gentoo instance have its own IP and more or less behave like an independent system, but on the other hand I'd like to have as little overhead as possible due to the system's limited resources. The host system is running these daemons, plus my thoughts so far:

Daemon           | Use Gentoo's own?
-----------------+---------------------------------------------------------------
udevd            | N bind-mount /dev
klogd, k*        | N using host kernel (although UML might be interesting...)
dhcpd, inetd     | ? depends on using own IP or not
syslogd          | ? bind-mount /var/log or use Gentoo's more versatile settings?
mdadm --monitor  | ? should Gentoo bother with the RAID configuration?
smbd, nmbd       | ? disable host's samba in favour of Gentoo's one? maybe with a
                 |   maintenance-only share on the host
crond            | Y to minimize interference with host's maintenance scripts
sshd             | Y to directly SSH into the chrooted Gentoo system
daemonwatch      | ? maybe use host instance to watch Gentoo instance?
logchkd, errormon| ? unknown

Finally, I'd like to know what I should consider on shutdown/reboot - can I simply have the host's shutdown script run chroot /gentoo /bin/init shutdown before its own sequence, or could that cause a power off by Gentoo before the host's actual shutdown sequence?

4

If you want to run services in a chroot: that's not really what a chroot is built for.

You'd be better off to isolate your Gentoo system in a Docker container.

You can easily create a Docker image from your chroot by creating a new baseimage from it:

tar --numeric-owner -cf- /gentoo | docker import - gentoo:base

Then build a proper Docker imageon top of it using this Dockerfile:

FROM gentoo:base
EXPOSE 22 # make SSH accessible, repeat for any port you're running a service on in this container
ENTRYPOINT ["/usr/lib/systemd/systemd"]

Use this command to build a proper container based on the Dockerfile (the Dockerfile needs to be in the same directory from which you're running this command and it needs to be named Dockerfile):

docker build -t gentoo:latest .

Now you should be able to start this container using

GENTOO_CONTAINER=$(docker run -d gentoo:base)

Using docker inspect ${GENTOO_CONTAINER} you can see now all the details of this container (IP, which ports are used to expose the services of running inside your container to the outside, etc.).

Using docker ps you can see the containers which are currently running.

Using docker ps -a you can see all containers which have ever been run, including the currently running ones.

Also make sure to do the Docker tutorial which is really helpful in understanding Docker basics.

  • I haven't heard of Docker before, thanks for your answer! Though I'm a bit worried by "* Please note Docker is currently under heavy developement. It should not be used in production (yet)." Anyway, the NAS is below the requirements (kernel is 3.3, which I really don't want to compile especially due to the lack of information what modifications Buffalo made) and I'd need to compile Docker to armv5te first :/ But nonetheless, thanks for your answer, hopefully others can apply it! – Tobias Kienzler Nov 7 '13 at 7:57
  • Sorry, didn't see your ARMv5 requirement. Docker is currently x86/AMD64 only, but this might change in the future. Regarding the stability: it is by far stable enough as it just wraps around LXC which has matured greatly throughout the last years. The only thing to be considered probably unstable IMHO is the feature-set which still changes every now and then a bit before the final 1.0 release (see also the 0.6.5 announcement) – Elias Probst Nov 7 '13 at 8:24
  • I'm looking forward to it :) Actually I forgot to mention ARM in this question, only implicitly via the other one... – Tobias Kienzler Nov 7 '13 at 8:25
  • 1
    Instead of Docker, you could use systemd-nspawn which also uses LXC, but uses systemd itself instead for controlling the container instances. The great thing about it: the systemd instance of your host is now the supervisor for all your "chroots" and it's services, although you can also access the container itself just like and independent OS and control everything below the container's namespace from there. – Elias Probst Nov 8 '13 at 15:03
  • 1
    Although this might not really help in your case, but probably anyways an interesting read… it looks like Docker is being ported to ARM to be able to run it on a Raspberry Pi. – Elias Probst Nov 11 '13 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.