23.3 Raspberry Pi Linux Compatibility Layer
Arch Linux Distribution Overview
#!/bin/sh
rootdir=/compat/arch # Set Arch Linux installation root directory
url="https://mirrors.jlu.edu.cn/archlinuxarm/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz" # Arch Linux ARM image download URL
echo "begin to install Arch Linux ..."
echo "check modules ..."
# Check linux module
if [ "$(sysrc -n linux_enable)" = "NO" ]; then # Check if linux module is enabled
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 # Enable linux module
;;
esac
fi
echo "start linux"
service linux start # Start linux compatibility layer
# Check dbus
if ! /usr/bin/which -s dbus-daemon; then # Check if dbus-daemon exists
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 # Install dbus
;;
esac
fi
if [ "$(sysrc -n dbus_enable)" != "YES" ]; then # Check if dbus is enabled
echo "dbus should be enabled. Continue?(Y|n)"
read answer
case $answer in
[Nn][Oo]|[Nn])
echo "dbus not running"
exit 2
;;
[Yy][Ee][Ss]|[Yy]|"")
service dbus enable # Enable dbus
;;
esac
fi
echo "start dbus"
service dbus start # Start dbus service
echo "now we will bootstrap Arch Linux"
fetch ${url} # Download Arch Linux ARM image
mkdir -p ${rootdir} # Create installation root directory
tar xpvf ArchLinuxARM-rpi-aarch64-latest.tar.gz -C ${rootdir} --numeric-owner # Extract image to root directory
rm ArchLinuxARM-rpi-aarch64-latest.tar.gz # Remove the archive
if [ ! "$(sysrc -f /boot/loader.conf -qn nullfs_load)" = "YES" ]; then # Check if nullfs is enabled
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 # Enable nullfs
;;
esac
fi
if ! kldstat -n nullfs >/dev/null 2>&1; then # Check if nullfs module is loaded
echo "load nullfs module"
kldload -v nullfs # Dynamically load nullfs module
fi
echo "mount some fs for linux"
echo "devfs ${rootdir}/dev devfs rw,late 0 0" >> /etc/fstab # Configure devfs
echo "tmpfs ${rootdir}/dev/shm tmpfs rw,late,size=1g,mode=1777 0 0" >> /etc/fstab # Configure tmpfs
echo "fdescfs ${rootdir}/dev/fd fdescfs rw,late,linrdlnk 0 0" >> /etc/fstab # Configure fdescfs
echo "linprocfs ${rootdir}/proc linprocfs rw,late 0 0" >> /etc/fstab # Configure linprocfs
echo "linsysfs ${rootdir}/sys linsysfs rw,late 0 0" >> /etc/fstab # Configure linsysfs
echo "/tmp ${rootdir}/tmp nullfs rw,late 0 0" >> /etc/fstab # Configure /tmp
#echo "/home ${rootdir}/home nullfs rw,late 0 0" >> /etc/fstab # Optional: configure /home
mount -al # Mount all file systems
echo "For Arch Linux, we should change 'compat.linux.osrelease'. continue? (Y|n)"
read answer
case $answer in
[Nn][Oo]|[Nn])
echo "configuration not completed"
exit 4
;;
[Yy][Ee][Ss]|[Yy]|"")
echo "compat.linux.osrelease=6.12.63" >> /etc/sysctl.conf # Write sysctl configuration
sysctl compat.linux.osrelease=6.12.63 # Apply sysctl configuration
;;
esac
echo "complete!"
echo "to use: chroot ${rootdir} /bin/bash"
echo ""
echo "the script can also perform some initial configuration"
echo "if agree:"
echo " set resolv.conf to Ali DNS"
echo " init pacman keyring"
echo " use USTC mirror"
echo "continue?[Y|n]"
read answer
case $answer in
[Nn][Oo]|[Nn])
echo "set your Arch Linux by yourself."
exit 0
;;
[Yy][Ee][Ss]|[Yy]|"")
rm ${rootdir}/etc/resolv.conf # Remove original resolv.conf
echo "nameserver 223.5.5.5" >> ${rootdir}/etc/resolv.conf # Set DNS
chroot ${rootdir} /bin/bash -c "pacman-key --init" # Initialize pacman keyring
chroot ${rootdir} /bin/bash -c "pacman-key --populate archlinuxarm" # Populate keyring
echo 'Server = https://mirrors.ustc.edu.cn/archlinuxarm/$arch/$repo' > ${rootdir}/etc/pacman.d/mirrorlist # Set to USTC mirror
echo '[archlinuxcn]' >> ${rootdir}/etc/pacman.conf
echo 'Server = https://mirror.sjtu.edu.cn/archlinux-cn/aarch64' >> ${rootdir}/etc/pacman.conf
echo "Refresh sources and systems"
echo "Enabling DisableSandbox in pacman.conf to avoid landlock error on this kernel"
sed -E -i '' 's/^[[:space:]]*#[[:space:]]*DisableSandbox/DisableSandbox/' ${rootdir}/etc/pacman.conf # Uncomment DisableSandbox to enable the option
grep -n 'DisableSandbox' ${rootdir}/etc/pacman.conf
chroot ${rootdir} /bin/bash -c "pacman -Syyu --noconfirm" # Update system
echo "Refresh key"
chroot ${rootdir} /bin/bash -c "pacman -S --noconfirm archlinuxcn-keyring" # Install archlinuxcn-keyring
echo "Install yay"
chroot ${rootdir} /bin/bash -c "pacman -S --noconfirm yay base base-devel nano wqy-zenhei" # Install base software and yay
echo "Create user"
chroot ${rootdir} /bin/bash -c "useradd -G wheel -m test" # Create user test and add to wheel group
echo "Now modify the sudo configuration"
echo '%wheel ALL=(ALL) ALL' >> ${rootdir}/etc/sudoers # Configure wheel group sudo privileges
echo '%sudo ALL=(ALL:ALL) ALL' >> ${rootdir}/etc/sudoers # Configure sudo group sudo privileges
echo "change fakeroot"
chroot ${rootdir} /bin/bash -c "pacman -S --noconfirm fakeroot-tcp" # Install fakeroot-tcp
echo "Make localised settings"
echo 'zh_CN.UTF-8 UTF-8' >> ${rootdir}/etc/locale.gen # Enable Chinese UTF-8 locale
chroot ${rootdir} /bin/bash -c "locale-gen" # Generate locale settings
echo "all done."
;;
esac
echo "Now you can run '#chroot /compat/arch/ /bin/bash' into Arch Linux"References
Last updated