第 21.6 节 Linux 兼容层——基于 OpenSUSE
OpenSUSE 15.5-shell 脚本
该脚本虽然使用的镜像是基于 dnf 包管理器构建的,但是 opi 会自动安装 zypper 从而实现双包管理器共存,但是需要用户自行导入 zypper 源。
脚本内容如下:
#/bin/sh
rootdir=/compat/suse
url="https://mirrors.ustc.edu.cn/opensuse/distribution/openSUSE-current/appliances/opensuse-leap-dnf-image.x86_64-lxc-dnf.tar.xz"
echo "begin to install latest Opensuse Leap ..."
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 opensuse"
fetch ${url}
mkdir -p ${rootdir}
tar zxvf opensuse-leap-dnf-image*.tar.xz -C ${rootdir} --numeric-owner
rm opensuse-leap-dnf-image.x86_64-lxc-dnf.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 opensuse,we should change 'compat.linux.osrelease'. 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 opensuse by yourself.bye!"
exit 0
;;
[Yy][Ee][Ss]|[Yy]|"")
echo "nameserver 223.5.5.5" >> ${rootdir}/etc/resolv.conf
echo " I will install opi nano tar and vim"
chroot ${rootdir} /bin/bash -c "dnf update && dnf install -y opi nano tar vim"
echo "all done."
echo "Now you can run '#chroot /compat/suse/ /bin/bash' Into Opensuse"
;;
esac
OpenSUSE Tumbleweed-shell 脚本
本节有点问题,暂不可用。
Tumbleweed 即风滚草,是 OpenSUSE 的滚动更新版本。
# fetch http://book.bsdcn.org/suset.sh
# sh suset.sh
脚本内容如下:
#/bin/sh
rootdir=/compat/suse
url="https://mirrors.ustc.edu.cn/opensuse/tumbleweed/appliances/opensuse-tumbleweed-dnf-image.x86_64-lxc-dnf.tar.xz"
echo "begin to install OpenSUSE Tumbleweed..."
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 opensuse"
fetch ${url}
mkdir -p ${rootdir}
tar zxvf opensuse*.tar.xz -C ${rootdir} --numeric-owner
rm opensuse-tumbleweed-dnf-image.x86_64-lxc-dnf.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 opensuse,we should change 'compat.linux.osrelease'. 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 opensuse by yourself.bye!"
exit 0
;;
[Yy][Ee][Ss]|[Yy]|"")
echo "nameserver 223.5.5.5" >> ${rootdir}/etc/resolv.conf
echo " I will install opi nano tar and vim"
chroot ${rootdir} /bin/bash -c "dnf update && dnf install -y opi nano tar vim"
echo "all done."
echo "Now you can run '#chroot /compat/suse/ /bin/bash' Into Opensuse"
;;
esac
故障排除
当使用 LXC Leap 镜像时,zypper 是不可用的。同样地,当使用 openSUSE Tumbleweed 时,dnf 和 zypper 都不可用。该问题不影响我们的 leap 脚本,但是影响第二个风滚草的脚步,导致无法正常使用。已经报告 Bug。
例如,当试图安装 Vim 时,你会遇到一个错误信息。
Installation of perl-5.36.1-1.2.x86_ 64 failed:
Error's Subprocessg faited.c Error: RPM failed: Command exited with status 1
在 LXC Leap 中,用 rpm 替换 rpm-ndb 可以解决这个问题,dnf 也不会遇到这个问题。这个问题是 zypper 特有的。然而,在 openSUSE Tumbleweed LXC 中,dnf 和 zypper 都有这个问题,替换 rpm-ndb 也不能解决。
最后更新于