第 21.7 节 Linux 兼容层——基于 Gentoo Linux
构建基本系统
# sysrc linux_enable="YES"
# sysrc kld_list+="linux linux64"
# kldload linux64
# service linux start
# service dbus enable #一般桌面已经配置
# service dbus start #一般桌面已经配置
# wget https://mirrors.ustc.edu.cn/gentoo/releases/amd64/autobuilds/20230101T164658Z/stage3-amd64-systemd-20230101T164658Z.tar.xz #该链接不固定!自己找。
# mkdir -p /compat/gentoo
# tar xpvf stage3-amd64-systemd-20230101T164658Z.tar.xz -C /compat/gentoo --numeric-owner
编辑 ee /etc/fstab
,加入:
# Device Mountpoint FStype Options Dump Pass#
devfs /compat/gentoo/dev devfs rw,late 0 0
tmpfs /compat/gentoo/dev/shm tmpfs rw,late,size=1g,mode=1777 0 0
fdescfs /compat/gentoo/dev/fd fdescfs rw,late,linrdlnk 0 0
linprocfs /compat/gentoo/proc linprocfs rw,late 0 0
linsysfs /compat/gentoo/sys linsysfs rw,late 0 0
/tmp /compat/gentoo/tmp nullfs rw,late 0 0
#/home /compat/gentoo/home nullfs rw,late 0 0
# mount -al # 检查有无编写错误
编辑:
ee /compat/gentoo/etc/portage/make.conf
加入:
MAKEOPTS="-j2"
GENTOO_MIRRORS="https://mirrors.ustc.edu.cn/gentoo"
FEATURES="-ipc-sandbox -mount-sandbox -network-sandbox -pid-sandbox -xattr -sandbox -usersandbox"
进行常见配置:
# mkdir -p /compat/gentoo/etc/portage/repos.conf # 此时位于 FreeBSD!
# cp /compat/gentoo/usr/share/portage/config/repos.conf /compat/gentoo/etc/portage/repos.conf/gentoo.conf # 此时位于 FreeBSD!
# cp /etc/resolv.conf /compat/gentoo/etc/ # 此时位于 FreeBSD!复制 DNS 解析。
Gentoo 换源
# ee /compat/gentoo/etc/portage/repos.conf/gentoo.conf # 此处位于 FreeBSD!
把 sync-uri = rsync://rsync.gentoo.org/gentoo-portage
修改为 sync-uri = rsync://mirrors.tuna.tsinghua.edu.cn/gentoo-portage
。
# chroot /compat/gentoo /bin/bash # 此处位于 Gentoo!
获取 Gentoo ebuild 数据库快照
# emerge-webrsync
换源后操作
测试安装 screenfetch:
ykla / # emerge -v screenfetch
* IMPORTANT: 10 news items need reading for repository 'gentoo'.
* Use eselect news read to view new items.
These are the packages that would be merged, in order:
Calculating dependencies... done!
Dependency resolution took 2.51 s.
[ebuild N ] app-misc/screenfetch-3.9.1::gentoo USE="-X -curl" 76 KiB
……省略一部分……
>>> Recording app-misc/screenfetch in "world" favorites file...
>>> Completed (1 of 1) app-misc/screenfetch-3.9.1::gentoo
可以正常安装软件。
ykla / # screenfetch
grep: warning: stray \ before "
grep: warning: stray \ before "
-/oyddmdhs+:. ykla@ykla
-odNMMMMMMMMNNmhy+-` OS: Gentoo
-yNMMMMMMMMMMMNNNmmdhy+- Kernel: x86_64 Linux 6.2.10
`omMMMMMMMMMMMMNmdmmmmddhhy/` Uptime: 1h 26m
omMMMMMMMMMMMNhhyyyohmdddhhhdo` Packages: 295
.ydMMMMMMMMMMdhs++so/smdddhhhhdm+` Shell: bash 5.1.16
oyhdmNMMMMMMMNdyooydmddddhhhhyhNd. Resolution: No X Server
:oyhhdNNMMMMMMMNNNmmdddhhhhhyymMh WM: Not Found
.:+sydNMMMMMNNNmmmdddhhhhhhmMmy Disk: 8.9G / 45G (20%)
/mMMMMMMNNNmmmdddhhhhhmMNhs: CPU: Intel Core i5-3230M @ 2x 2.594GHz
`oNMMMMMMMNNNmmmddddhhdmMNhs+` RAM: 3209MiB / 4038MiB
`sNMMMMMMMMNNNmmmdddddmNMmhs/.
/NMMMMMMMMNNNNmmmdddmNMNdso:`
+MMMMMMMNNNNNmmmmdmNMNdso/-
yMMNNNNNNNmmmmmNNMmhs+/-`
/hMMNNNNNNNNMNdhs++/-`
`/ohdmmddhys+++/:.`
`-//////:--.
ykla / #
shell 脚本
脚本内容:
#/bin/sh
rootdir=/compat/gentoo
fetch https://mirrors.ustc.edu.cn/gentoo/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt
gentoodownload=$(echo |sed -n '3p' latest-stage3-amd64-systemd.txt|awk -F ' ' '{print $1}')
rm latest-stage3-amd64-systemd.txt
url="https://mirrors.ustc.edu.cn/gentoo/releases/amd64/autobuilds/"
echo "Begin to install latest Gentoo Linux ..."
echo "check modules ..."
# check linux module
if [ "$(sysrc -n linux_enable)" = "NO" ]; then
echo "linux module should be loaded. Continue?(Y|n)"
read answer
case $answer in
[Nn][Oo]|[Nn])
echo "linux module not loaded"
exit 1
;;
[Yy][Ee][Ss]|[Yy]|"")
sysrc linux_enable=YES
;;
esac
fi
echo "start linux"
service linux start
# check dbus
if ! /usr/bin/which -s dbus-daemon;then
echo "dbus-daemon not found. install it [Y|n]"
read answer
case $answer in
[Nn][Oo]|[Nn])
echo "dbus not installed"
exit 2
;;
[Yy][Ee][Ss]|[Yy]|"")
pkg install -y dbus
;;
esac
fi
if [ "$(sysrc -n dbus_enable)" != "YES" ]; then
echo "dbus should be enable. Continue?(Y|n)"
read answer
case $answer in
[Nn][Oo]|[Nn])
echo "dbus not running"
exit 2
;;
[Yy][Ee][Ss]|[Yy]|"")
sysrc dbus_enable=YES
;;
esac
fi
echo "start dbus"
service dbus start
echo "now we will bootstrap gentoo"
fetch ${url}/$gentoodownload
mkdir -p ${rootdir}
tar zxvf stage3-amd64-systemd*.tar.xz -C ${rootdir} --numeric-owner
rm stage3-amd64-systemd*.tar.xz
if [ ! "$(sysrc -f /boot/loader.conf -qn nullfs_load)" = "YES" ]; then
echo "nullfs_load should load. continue? (Y|n)"
read answer
case $answer in
[Nn][Oo]|[Nn])
echo "nullfs not load"
exit 3
;;
[Yy][Ee][Ss]|[Yy]|"")
sysrc -f /boot/loader.conf nullfs_load=yes
;;
esac
fi
if ! kldstat -n nullfs >/dev/null 2>&1;then
echo "load nullfs module"
kldload -v nullfs
fi
echo "mount some fs for linux"
echo "devfs ${rootdir}/dev devfs rw,late 0 0" >> /etc/fstab
echo "tmpfs ${rootdir}/dev/shm tmpfs rw,late,size=1g,mode=1777 0 0" >> /etc/fstab
echo "fdescfs ${rootdir}/dev/fd fdescfs rw,late,linrdlnk 0 0" >> /etc/fstab
echo "linprocfs ${rootdir}/proc linprocfs rw,late 0 0" >> /etc/fstab
echo "linsysfs ${rootdir}/sys linsysfs rw,late 0 0" >> /etc/fstab
echo "/tmp ${rootdir}/tmp nullfs rw,late 0 0" >> /etc/fstab
#echo "/home ${rootdir}/home nullfs rw,late 0 0" >> /etc/fstab
mount -al
echo "for Gentoo Linux, we should change 'compat.linux.osrelease' to upgrade Linux kernel version, continue? (Y|n)"
read answer
case $answer in
[Nn][Oo]|[Nn])
echo "close to success"
exit 4
;;
[Yy][Ee][Ss]|[Yy]|"")
echo "compat.linux.osrelease=6.2.10" >> /etc/sysctl.conf
sysctl compat.linux.osrelease=6.2.10
;;
esac
echo "complete!"
echo "to use: chroot ${rootdir} /bin/bash"
echo ""
echo " I will set resolv.conf to ali dns"
echo "continue?[Y|n]"
read answer
case $answer in
[Nn][Oo]|[Nn])
echo "set your gentoo by yourself.bye!"
exit 0
;;
[Yy][Ee][Ss]|[Yy]|"")
echo "nameserver 223.5.5.5" >> ${rootdir}/etc/resolv.conf
echo "Now write MAKEOPTS FEATURES in /compat/gentoo/etc/portage/make.conf -- using USTC mirrors for GENTOO_MIRRORS"
echo "MAKEOPTS=\"-j2\"" >> /${rootdir}/etc/portage/make.conf
echo "GENTOO_MIRRORS=\"https://mirrors.ustc.edu.cn/gentoo\"" >> ${rootdir}/etc/portage/make.conf
echo "FEATURES=\"-ipc-sandbox -mount-sandbox -network-sandbox -pid-sandbox -xattr -sandbox -usersandbox\"" >> ${rootdir}/etc/portage/make.conf
echo "Now setting soft sources --Using TUNA mirror for emerge-webrsync"
mkdir -p ${rootdir}/etc/portage/repos.conf
cp ${rootdir}/usr/share/portage/config/repos.conf ${rootdir}/etc/portage/repos.conf/gentoo.conf
sed -i "" 's/rsync.gentoo.org/mirrors.tuna.tsinghua.edu.cn/' ${rootdir}/etc/portage/repos.conf/gentoo.conf
echo " I will run emerge-webrsync"
chroot ${rootdir} /bin/bash -c "emerge-webrsync"
echo "all done."
echo "Now you can run '#chroot /compat/gentoo/ /bin/bash' Into gentoo"
;;
esac
最后更新于