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?