第 21.9 节 Linux 兼容层——基于 Slackware Linux
注意
**slackware 并未提供基本系统的下载,需要自己在 slackware 或 FreeBSD 下(FreeBSD 需要安装
bash
以及gmake
)使用脚本生成,原版脚本地址为 https://github.com/nnnewb/slackware-WSL,因为无人赞助服务器,请你自己生成该文件。
脚本内容如下:
#!/bin/sh
export ROOT_DIR=/compat
export DIST=slackware
export DIST_FULLNAME=Slackware
VER=15.0
FILE=${DIST}64-${VER}.tar.xz
SUBDIR=""
URL=https://book.bsdcn.org
UPDATE_CMD="slackpkg update"
UPGRADE_CMD="slackpkg upgrade-all"
INSTALL_CMD="slackpkg install"
UPDATE=1
UPGRADE=1
INSTALL=1
echo "Starting to install ${DIST_FULLNAME}"
sleep 0.5
# check.sh
echo "Checking relative modules"
if [ ! "$(sysrc -n linux_enable)" = "YES" ]; then
echo "linux service is not enabled. Enable it now?(Y|n)"
read ANSWER
case ${ANSWER} in
[Nn][Oo]|[Nn])
echo "Warning: You MUST start linux service with \"service linux start\" EACH TIME FREEBSD IS REBOOTED."
echo "Sure to continue without enabling linux service?(y|N)"
read ANSWER
case ${ANSWER} in
[Yy][Ee][Ss]|[Yy])
echo "WARNING: linux moudle not enabled"
;;
[Nn][Oo]|[Nn]|"")
echo "Enabling linux moudle"
sysrc linux_enable=YES
;;
*)
echo "Aborting."
exit 4
;;
esac
;;
[Yy][Ee][Ss]|[Yy]|"")
echo "Enabling linux moudle"
sysrc linux_enable=YES
;;
*)
echo "Aborting."
exit 4
;;
esac
fi
echo "Starting linux service"
service linux start
if ! which -s dbus-daemon; then
echo "dbus-daemon not found. Install dbus now?(Y|n)"
read ANSWER
case ${ANSWER} in
[Nn][Oo]|[Nn])
echo "Abort. dbus not installed"
exit 2
;;
[Yy][Ee][Ss]|[Yy]|"")
echo "Installing dbus"
pkg install -y dbus
;;
*)
echo "Aborting."
exit 4
;;
esac
fi
if [ ! "$(sysrc -n dbus_enable)" = "YES" ]; then
echo "dbus is not enabled. Enable it now?(Y|n)"
read ANSWER
case ${ANSWER} in
[Nn][Oo]|[Nn])
echo "WARNING: You MUST start dbus with \"service dbus start\" EACH TIME FREEBSD IS REBOOTED."
echo "Sure to continue without enabling dbus?(y|N)"
read ANSWER
case ${ANSWER} in
[Yy][Ee][Ss]|[Yy])
echo "Warning: dbus not enabled"
;;
[Nn][Oo]|[Nn]|"")
echo "Enabling dbus service"
sysrc dbus_enable="YES"
;;
*)
echo "Aborting."
exit 4
;;
esac
;;
[Yy][Ee][Ss]|[Yy]|"")
echo "Enabling dbus service"
sysrc dbus_enable="YES"
;;
*)
echo "Aborting."
exit 4
;;
esac
fi
if [ -z "$(ps aux | grep -p dbus | grep -v grep)" ]; then
echo "Starting dbus service"
service dbus start
fi
if [ ! "$(sysrc -f /boot/loader.conf -qn nullfs_load)" = "YES" ]; then
echo "nullfs should be loaded when boot. Set nullfs_load to YES?(Y|n)"
read ANSWER
case ANSWER in
[Nn][Oo]|[Nn])
echo "Warning: You MUST load nullfs with \"kldload -v nullfs\" EACH TIME FREEBSD IS REBOOTED."
echo "Sure to continue without setting nullfs_load to YES?(y|N)"
read ANSWER
case ANSWER in
[Yy][Ee][Ss]|[Yy])
echo "Warning: nullfs_load not set"
;;
[Nn][Oo]|[Nn]|"")
echo "Setting nullfs_load to YES"
sysrc -f /boot/loader.conf nullfs_load="YES"
;;
*)
echo "Aborting."
exit 4
;;
esac
;;
[Yy][Ee][Ss]|[Yy]|"")
echo "Setting nullfs_load to YES"
sysrc -f /boot/loader.conf nullfs_load="YES"
;;
*)
echo "Aborting."
exit 4
;;
esac
fi
if ! kldstat -n nullfs >/dev/null 2>&1; then
echo "Loading nullfs module"
kldload -v nullfs
fi
# pre_extract.sh
echo "${DIST_FULLNAME} will be installed in ${ROOT_DIR}/${DIST}"
echo "Downloading basic system"
fetch ${URL}/${FILE}
echo "Exacting basic system"
sleep 0.5
mkdir -p ${ROOT_DIR}/${DIST}
tar xvpf ${FILE} ${SUBDIR:-} -C ${ROOT_DIR}/${DIST} --numeric-owner
echo "Mounting recuired file system"
sleep 0.5
echo "devfs ${ROOT_DIR}/${DIST}/dev devfs rw,late 0 0" >> /etc/fstab
echo "tmpfs ${ROOT_DIR}/${DIST}/dev/shm tmpfs rw,late,size=1g,mode=1777 0 0" >> /etc/fstab
echo "fdescfs ${ROOT_DIR}/${DIST}/dev/fd fdescfs rw,late,linrdlnk 0 0" >> /etc/fstab
echo "linprocfs ${ROOT_DIR}/${DIST}/proc linprocfs rw,late 0 0" >> /etc/fstab
echo "linsysfs ${ROOT_DIR}/${DIST}/sys linsysfs rw,late 0 0" >> /etc/fstab
echo "/tmp ${ROOT_DIR}/${DIST}/tmp nullfs rw,late 0 0" >> /etc/fstab
#echo "/home ${ROOT_DIR}/${DIST}/home nullfs rw,late 0 0" >> /etc/fstab
mount -al
# setup.sh
echo "Should ${DIST_FULLNAME} use Alibaba DNS or local resolv.conf?( (A)li | (l)ocal | (c)ancel )"
read ANSWER
case ${ANSWER} in
[Aa][Ll][Ii]|[Aa]|"")
echo "Setting Alibaba DNS"
echo "nameserver 223.5.5.5" >> ${ROOT_DIR}/etc/resolv.conf
DNS_CONFIGURED=1
;;
[Ll][Oo][Cc][Aa][Ll]|[Ll])
echo "Using local reslov.conf"
cp /etc/resolv.conf ${ROOT_DIR}/etc/resolv.conf
DNS_CONFIGURED=1
;;
*)
echo "Cancled."
echo "You have to edit ${ROOT_DIR}/etc/resolv.conf by yourself!"
DNS_CONFIGURED=0
;;
esac
if [ ${DNS_CONFIGURED} = 1 ]; then
if [ ${UPDATE} = 1 ]; then
echo "Updating ${DIST_FULLNAME}"
chroot ${ROOT_DIR}/${DIST} /bin/bash -c "${UPDATE_CMD}"
fi
if [ ${UPGRADE} = 1 ]; then
echo "Upgrading ${DIST_FULLNAME}"
chroot ${ROOT_DIR}/${DIST} /bin/bash -c "${UPGRADE_CMD}"
fi
else
echo "DNS is not set, skipping upgrade"
fi
echo "Setting default bash theme"
cp ${ROOT_DIR}/${DIST}/etc/profile ${ROOT_DIR}/${DIST}/root/.bashrc
echo "Cleaning up"
rm ${FILE}
echo "Done."
echo "Now you can switch to ${DIST_FULLNAME} with \"chroot ${ROOT_DIR}/${DIST} /bin/bash\""
最后更新于