文章目錄
- 使用 debootstrap 制作 ARM64 rootfs.cpio
- 1. 安裝依賴
- 2. 制作檔案系統
- 3. 進入檔案系統
- 4. 定制檔案系統
- 4.1 配置網絡
- 4.2 更換國内鏡像源
- 4.3 配置 root 使用者密碼
- 4.4 建立一個普通使用者
- 4.5 安裝依賴
- 4.6 設定主機名和以太網
- 5. 退出檔案系統
- 6. 得到 roofs.cpio
使用 debootstrap 制作 ARM64 rootfs.cpio
Debian 9,配合 Raspberry Pi 4 Model B
1. 安裝依賴
$ sudo apt-get install debian-archive-keyring
$ sudo apt-get install qemu qemu-user-static binfmt-support debootstrap
2. 制作檔案系統
$ mkdir ~/build && cd ~/build
# 切換到 root
$ sudo su - root
# 建構檔案系統
$ debootstrap --arch=arm64 --foreign stretch linux-rootfs http://ftp.cn.debian.org/debian/
# --arch: 指定制作的檔案系統的架構
# --foreign: 在與主機架構不同時需要指定此參數,作為初始化的解包
# stretch: Debian9的發行版号,Debian10為buster
# linux-rootfs: 存放檔案系統的檔案夾
3. 進入檔案系統
# # 此腳本有兩個參數 -u 是取消挂載 -m 是挂載
$ ./ch-mount.sh -m linux-rootfs
# 執行腳本後,沒有報錯會進入檔案系統,顯示I have no name
# 執行第二步,初始化檔案系統,會把一個系統的基礎包初始化
$ debootstrap/debootstrap --second-stage
# 初始化完畢後,退出檔案系統,再次進入後顯示root
$ exit
# 再次進入時,執行如下指令即可
$ sudo chroot linux-roofs
#!/bin/bash
# ch-mount.sh
function mnt() {
echo "MOUNTING"
sudo mount -t proc /proc ${2}proc
sudo mount -t sysfs /sys ${2}sys
sudo mount -o bind /dev ${2}dev
sudo mount -o bind /dev/pts ${2}dev/pts
sudo chroot ${2}
}
function umnt() {
echo "UNMOUNTING"
sudo umount ${2}proc
sudo umount ${2}sys
sudo umount ${2}dev/pts
sudo umount ${2}dev
}
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
umnt $1 $2
else
echo ""
echo "Either 1'st, 2'nd or both parameters were missing"
echo ""
echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
echo ""
echo "For example: ch-mount -m /media/sdcard/"
echo ""
echo 1st parameter : ${1}
echo 2nd parameter : ${2}
fi
4. 定制檔案系統
4.1 配置網絡
要確定進入檔案系統後有網絡,可以将
/etc/resolv.conf
檔案拷貝到
linux-rootfs/etc/resolv.conf
。
4.2 更換國内鏡像源
# 若是遇到沒法拉取 https 源的狀況,請先使用 http 源并安裝
$ apt install apt-transport-https
$ cp /etc/apt/source.list /etc/apt/source.list_bak
# 這裡用的vim.tiny是建構檔案系統是自帶的,跟vim同樣也能夠編輯檔案,把檔案内容所有替換為如下内容
$ vim.tiny /etc/apt/source.list
# 預設注釋了源碼鏡像以提升 apt update 速度,若有須要可自行取消注釋
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
4.3 配置 root 使用者密碼
$ passwd
4.4 建立一個普通使用者
# 這兩個環境變量能夠自行修改
$ USER=pi
$ HOST=raspberry
$ useradd -G sudo -m -s /bin/bash $USER
$ passwd $USER
4.5 安裝依賴
# 安裝音頻管理
$ apt-get install alsa-utils libasound2-dev
# 安裝 vim 和 ssh
$ apt-get install vim ssh
# 安裝網絡管理工具
$ apt-get install ifupdown net-tools
# 安裝其餘依賴,若是還有其餘依賴須要安裝能夠繼續向後加入
$ apt-get install udev sudo wget curl
4.6 設定主機名和以太網
$ echo $HOST > /etc/hostname
$ echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts
$ echo "127.0.0.1 $HOST" >> /etc/hosts
$ echo "auto eth0" > /etc/network/interfaces.d/eth0
$ echo "iface eth0 inet dhcp" >> /etc/network/interfaces.d/eth0
5. 退出檔案系統
所有以上完成後,根檔案系統基本制作完畢,調用腳本取消挂載。
$ exit
$ ./ch-mount -u linux-rootfs