ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

如何正确使用Gentoo Linux作为现有发行版的补充?

2019-08-13 04:51:27  阅读:277  来源: 互联网

标签:rc linux system-installation chroot init-script


虽然我原本想要entirely replace the Linux distribution my NAS uses,但我同时得出的结论是,最好让现有系统尽可能不修改,只需通过Gentoo(或Arch)Linux补充它 – 这基本上就是the answer to the previous question suggested.所以目前唯一的修改到原始系统包含一个/ gentoo目录,我通过以下脚本chroot到:

#!/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

现在我可以通过端口22222简单地进入主机并最终进入chroot环境,它基本上就像Gentoo Linux一样,这个脚本可以从主机的/etc/init.d/rcS运行.

但是我当然不希望最终启动我想以这种方式手动使用的每个Gentoo服务 – 这就是OpenRC(或者systemd,如果愿意的话)毕竟是好的.所以我的主要问题是

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?

尽可能减少干扰,我的意思是它不应该尝试重新安装文件系统(但同时如果Gentoo的挂载工作正常会很好) – 所以简单地运行init可能不正确,对OpenRC配置的一些修改将会可能是必要的,但哪些?

另外,还有主机守护进程的问题 – 我应该使用它们还是让Gentoo运行它自己的例如crond和syslogd(以及如何设置它们以便不干扰主机实例?),还是应该进一步完全虚拟化Gentoo?正如in another question所提到的那样,让Gentoo实例拥有自己的IP并且或多或少的行为就像一个独立的系统一样,但另一方面,由于系统资源有限,我希望尽可能减少开销.主机系统正在运行这些守护进程,加上我的想法到目前为止:

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

最后,我想知道在关机/重启时我应该考虑什么 – 我可以简单地让主机的关机脚本在它自己的序列之前运行chroot / gentoo / bin / init,或者可能导致Gentoo在关闭之前断电主机的实际关机顺序?

解决方法:

如果你想在chroot中运行服务:那不是真正的chroot构建的.

你最好将你的Gentoo系统隔离在Docker容器中.

您可以通过从chroot创建一个新的baseimage来轻松地创建一个Docker镜像:

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

然后build a proper Docker image在它顶部使用这个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"]

使用此命令构建基于Dockerfile的正确容器(Dockerfile需要位于运行此命令的同一目录中,并且需要将其命名为Dockerfile):

docker build -t gentoo:latest .

现在您应该可以使用启动此容器了

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

使用docker inspect ${GENTOO_CONTAINER},您现在可以看到此容器的所有详细信息(IP,哪些端口用于将容器内部运行的服务公开给外部等).

使用docker ps可以看到当前正在运行的容器.

使用docker ps -a,您可以看到所有已运行的容器,包括当前正在运行的容器.

还要确保执行Docker tutorial,这对理解Docker基础知识非常有帮助.

标签:rc,linux,system-installation,chroot,init-script
来源: https://codeday.me/bug/20190813/1647246.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有