安装debootstrap和qemu-user-static:
apt install apt-transport-https qemu qemu-user-static binfmt-support debootstrap
构建ubuntu 18.04系统,基础包为minbase,使用清大的源:
qemu-debootstrap --arch arm64 --variant=minbase --include=whiptail,ca-certificates,tzdata bionic rootfs http://mirrors.ustc.edu.cn/ubuntu-ports/
配置软件源:
cat > rootfs/etc/apt/sources.list <<EOF
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
EOF
配置网络信息:
mkdir rootfs/etc/network/
echo 'nameserver 192.168.168.1' > rootfs/etc/resolv.conf
echo 'ubuntu-18.04' > rootfs/etc/hostname
cat > rootfs/etc/netplan/50-cloud-init.yaml <<EOF
network:
ethernets:
eth0:
addresses:
- 192.168.168.6/24
dhcp4: false
gateway4: 192.168.168.1
nameservers:
addresses:
- 192.168.168.1
search: []
version: 2
EOF
挂载本地设备文件到rootfs:
mount -t proc /proc rootfs/proc
mount -t sysfs /sys rootfs/sys
mount -o bind /dev rootfs/dev
mount -o bind /dev/pts rootfs/dev/pts
chroot rootfs内配置:
LANG=C.UTF-8 chroot rootfs/ /bin/bash
在rootfs内执行:
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
apt update
apt upgrade
apt install systemd -y
apt install wireless-regdb crda -y
apt install rsyslog udev dbus kmod openssh-server netplan.io man vim wget net-tools sysstat tmux less wireless-regdb crda dosfstools parted rng-tools -y
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
passwd root
umount /dev/pts/ /dev/ /proc/ /sys
exit
为方便使用之前编译的内核和armbian的uInitrd、firmware文件,挂载armbian的img镜像到本地:
losetup -P -f --show Armbian_5.62_Aml-s9xxx_Ubuntu_bionic_default_4.18.7_20181012.img
mount /dev/loop3p2 /mnt
mount /dev/loop3p2 /mnt/boot
mv /mnt/boot/* rootfs/boot/
mv /mnt/lib/modules/ rootfs/lib/
#也可安装armbian的firmware-aml-4.18-20181011_5.62_arm64.deb
mv /mnt/lib/firmware/ rootfs/lib/
mv /mnt/etc/modprobe.d/ rootfs/etc/
mv /mnt/etc/fstab rootfs/etc/
mv /mnt/root/install.sh rootfs/root/
将armbain镜像内的文件全部删除,将新做的系统移动过去。
rm -rf /mnt/*
mv rootfs/boot/* /mnt/boot/
mv rootfs/* /mnt/
参考:
https://help.ubuntu.com/lts/installation-guide/s390x/apds04.html