一、使用ubuntu-base镜像制作
参考传送门:
firefly-rk3399开发板–从0开始制作ubuntu镜像
https://blog.csdn.net/Yongheng6/article/details/140086423
1.下载ubuntu-base镜像
清华大学开源软件镜像
https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cdimage/ubuntu-base/releases/
2.解压到自己创建的rootfs_ubuntu文件夹下
$ tar -xvf ubuntu-base-18.04.5-base-arm64.tar.gz -C rootfs_ubuntu/
3.安装 qemu-user-static
不懂qemu的自行去百度
$ sudo apt-get install qemu-user-static
$ sudo cp /usr/bin/qemu-aarch64-static ./rootfs_ubuntu/usr/bin/
4.修改apt源
这里用华为的arm源,阿里源狗都不用
$ cat etc/apt/sources.list
deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-proposed main multiverse restricted universe
deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-proposed main multiverse restricted universe
deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-updates main multiverse restricted universe
5.配置DNS
$ vi ./etc/resolv.conf
填入这写
nameserver 8.8.8.8
nameserver 114.114.114.114
6.创建挂载/卸载ubuntu-base
文件系统脚本mnt_ubuntu.sh
#!/bin/bash
mnt() {
echo "MOUNTING"
sudo mount -t proc /proc ./rootfs_ubuntu/proc
sudo mount -t sysfs /sys ./rootfs_ubuntu/sys
sudo mount -o bind /dev ./rootfs_ubuntu/dev
sudo mount -o bind /dev/pts ./rootfs_ubuntu/dev/pts
sudo chroot ./rootfs_ubuntu/
}
umnt() {
echo "UNMOUNTING"
sudo umount ./rootfs_ubuntu/proc
sudo umount ./rootfs_ubuntu/sys
sudo umount ./rootfs_ubuntu/dev/pts
sudo umount ./rootfs_ubuntu/dev
}
if [ "$1" == "-m" ] ;
then
mnt $1
elif [ "$1" == "-u" ];
then
umnt $1
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 : ./rootfs_ubuntu/
fi
7.运行挂载脚本,chroot进入rootfs_ubuntu
wxd@ubuntu:~/work/myrootfs$ ./mnt_ubuntu.sh -m
MOUNTING
root@ubuntu:/#
8.在ubuntu-base中安装软件
# chmod 777 /tmp
# apt-get update
# apt-get install net-tools ethtool ifupdown psmisc nfs-common htop vim rsyslog iputils-ping language-pack-en-base sudo network-manager systemd iputils-ping openssh-sftp-server -y ssh rsync bash-completion ssh rsync
9.其他系统设置
1.修改root密码
#passwd root #这里设置root密码为root
2.设置主机名称和IP
# echo "localhost" > /etc/hostname
# echo "127.0.0.1 localhost" >> /etc/hosts
# echo "127.0.0.1 ubuntu" >> /etc/hosts
/etc/hostname中存放的是主机名,/etc/hosts存放的是域名与ip的对应关系,域名与主机名没有任何关系,你可以为任何一个IP指定任意一个名字。
10.解除挂载
wxd@ubuntu:~/work/myrootfs$ ./mnt_ubuntu.sh -u
11.压缩
# mv rootfs_ubuntu rootfs_ubuntu_bionic_arm64
# tar -cjvf rootfs_ubuntu_bionic_arm64.tar.gz rootfs_ubuntu_bionic_arm64
12.修改文件格式
有的开发板如RK的芯片的镜像为ext4格式,这里不做记录
二、使用debootstrap 制作根文件系统
参考传送门:
debootstrap 制作根文件系统
https://www.cnblogs.com/huaibovip/p/debootstrap-fs.html
debootstrap是debian/ubuntu下的一个工具,用来构建一套基本的根文件系统,其生成的目录符合Linux文件系统标准(FHS),即包含了/boot、/etc、/bin、/usr等等目录,但它比发行版本的Linux体积小很多,当然功能也没那么强大,因此,只能说是“基本的系统”。
1.安装依赖
# apt-get install binfmt-support qemu-system-common qemu-user-static debootstrap
2.制作"base"文件系统
# sudo debootstrap --arch [平台] [发行版本代号] [构建目录] [镜像地址]
sudo debootstrap --arch=$1 --foreign $2 $RFSDIR http://mirrors.ustc.edu.cn/ubuntu-ports/
三、以ls1046为例讲解文件系统的制作流程
0.ls1046编译出ubuntu.img的过程逻辑
编译文件系统镜像大致流程为,判断文件系统文件夹flexbuild/build/rfs/rootfs_ubuntu_bionic_arm6
里是否存在编译过的标志usr/aptpkg/.firststagedone
,如果有则执行后续编译apps和打包等过程;如果没有则使用脚本flex-mkdistrorfs制作,该脚本大致分为两步,第一步为使用debootstrap制作文件系统,第二步为apt安装一些deb包,包括常用的软件和库,需要为后续编译apps做准备。
再之后将编译出的apps、网卡udev规则、内核模块全都拷贝到文件系统文件夹下
其脚本源码追踪为:
"autobuild")
flex_autobuild_all
flex_autobuild_all() {
generate_kernel_img
if [ "$BUILD_PERF" = "y" ]; then
flex-builder -c perf -a $DESTARCH -f $CONFIGLIST
fi
flex-builder -i mkflashscr -f $CONFIGLIST
generate_qoriq_all_firmware
flex-builder -i mkbootpartition -a $DESTARCH -s -f $CONFIGLIST
build_rfs_apps <--文件系统的制作在这里面
merge_apps_to_rfs <--编译apps,合并到文件系统里在这里
build_rfs_apps() {
if [ "$BUILD_UBUNTU_TINY" = "y" ]; then
build_ubuntu_tiny
fi
if [ ! -f $RFSDIR/usr/aptpkg/.rfsblddone ]; then <--是否存在编译过的标志usr/aptpkg/.firststagedone
flex-builder -i mkrfs -r $DISTROTYPE:$DISTROSCALE -a $DESTARCH -f $CONFIGLIST
fi
flex-builder -c apps -a $DESTARCH -m all -f $CONFIGLIST
}
"mkrfs")
generate_distro_rfs
exit ;;
generate_distro_rfs() {
if [ $DISTROTYPE = ubuntu -o $DISTROTYPE = debian ]; then
build_distro_rfs_ubuntu
elif [ $DISTROTYPE = buildroot ]; then
build_distro_rfs_buildroot
fi
}
build_distro_rfs_ubuntu() {
if [ $DESTARCH = arm64 ]; then
tarch=arm64
elif [ $DESTARCH = arm32 ]; then
tarch=armhf
fi
if [ $DISTROTYPE = ubuntu -o $DISTROTYPE = debian ] && [ -f $RFSDIR/usr/aptpkg/.rfsblddone ]; then
echo $RFSDIR already exists!
exit 0
fi
if [ $DISTROTYPE = ubuntu -o $DISTROTYPE = debian ] && [ -d $RFSDIR -a ! -f $RFSDIR/usr/aptpkg/.rfsblddone ]; then
echo $RFSDIR exist but imcomplete, regenerate it ...
sudo rm -rf $RFSDIR/* <--文件系统不完整的话,会删除整个文件系统,如果是自己制作的文件系统,制作完后记得加上上面的标志文件
fi
mkdir -p $RFSDIR
echo "building $RFSDIR ..."
if [ $DESTARCH = arm64 ]; then
prebuilt_rfs_name=$prebuilt_arm64_rfs_name
elif [ $DESTARCH = arm32 ]; then
prebuilt_rfs_name=$prebuilt_arm32_rfs_name
fi
if [ "$FETCH_PREBUILT_ROOTFS" = "y" -a -n "$prebuilt_rfs_name" ] && \
[ $DISTROTYPE = ubuntu -o $DISTROTYPE = debian ] && [ $DISTROSCALE != tiny ]; then
set +e
curl -C - -f $prebuilt_rfs_url/$prebuilt_rfs_name -o $RFSDIR/$prebuilt_rfs_name
var=`echo $?`
set -e
if [ $var = 0 ]; then
echo Extracting $prebuilt_rfs_name, waiting ...
sudo tar xf $RFSDIR/$prebuilt_rfs_name -C $RFSDIR
var=`echo $?`
if [ $var = 0 ]; then
rm -f $RFSDIR/$prebuilt_rfs_name
fi
else
echo Failed to download prebuilt $prebuilt_rfs_url/$prebuilt_rfs_name!
echo Building $DISTROTYPE from scratch ...
if [ -n "$BUILDARG" ]; then
flex-mkdistrorfs $tarch $CODENAME ${BUILDARG}
else
flex-mkdistrorfs $tarch $CODENAME additional_packages_list_$DISTROSCALE
fi
fi
elif [ $DISTROSCALE = tiny ] && [ $DISTROTYPE = ubuntu ]; then
set +e
if [ $DESTARCH = arm64 ]; then
rfsname=$ubuntu_base_arm64
elif [ $DESTARCH = arm32 ]; then
rfsname=$ubuntu_base_arm32
fi
curl -C - -f $ubuntu_base_url/$rfsname -o $RFSDIR/$rfsname
var=`echo $?`
set -e
if [ $var = 0 ]; then
echo Extracting $rfsname, waiting ...
sudo tar xf $RFSDIR/$rfsname -C $RFSDIR
var=`echo $?`
if [ $var = 0 ]; then
rm -f $RFSDIR/$rfsname
fi
else
echo Failed to download $ubuntu_base_url/$rfsname!
exit
fi
if [ $DISTROSCALE = tiny ]; then
flex-mkdistrorfs $tarch $CODENAME additional_packages_list_tiny
else
flex-mkdistrorfs $tarch $CODENAME additional_packages_list_moderate <--ubuntu系统好像是执行的这里
fi
else
echo Building $DISTROTYPE $CODENAME for $DESTARCH
if [ -n "$BUILDARG" ]; then
echo flex-mkdistrorfs $tarch $CODENAME ${BUILDARG}
flex-mkdistrorfs $tarch $CODENAME ${BUILDARG}
else
echo flex-mkdistrorfs $tarch $CODENAME additional_packages_list_$DISTROSCALE
flex-mkdistrorfs $tarch $CODENAME additional_packages_list_$DISTROSCALE
fi
fi
if [ "$UDEV_RULES_QORIQ_NI_REMAP" = "y" ] && [ -d $RFSDIR/etc/udev/rules.d ]; then
sudo cp -f $FBDIR/configs/udev/udev-rules-qoriq/72-fsl-dpaa-persistent-networking.rules $RFSDIR/etc/udev/rules.d
fi ↑这里不知道怎么回事,没有执行,自己手动拷进去吧
fbprint_d $RFSDIR
}
merge_apps_to_rfs() {
flex-builder -i merge-component -a $DESTARCH -f $CONFIGLIST
flex-builder -i compressapps -a $DESTARCH -f $CONFIGLIST
if [ $hostarch = x86_64 -o $hostarch = i686 ]; then
if [ $DISTROTYPE = ubuntu -o $DISTROTYPE = debian ]; then
flex-builder -i compressrfs -a $DESTARCH -f $CONFIGLIST
fi
if [ "$BUILD_GUESTRFS" = "y" ] && [ $DISTROTYPE = ubuntu -o $DISTROTYPE = debian ]; then
flex-builder -i mkguestrfs -a $DESTARCH -B 3G -f $CONFIGLIST
fi
fi
fbprint_d "$DESTARCH: Build $DISTROTYPE userland and apps components in $FBDIR/build/images!"
}
"merge-component")
merge_components
exit ;;
merge_components() {
if [ ! -d $RFSDIR ]; then
echo $RFSDIR not exist, generating it ..
generate_distro_rfs
fi
# install apps components
if [ $DISTROTYPE = ubuntu -a $DISTROSCALE = tiny ]; then
if [ $DESTARCH = arm64 ]; then
if [ ! -f $DESTDIR/usr/local/bin/restool ]; then
flex-builder -c restool -a ${DESTARCH} -f $CONFIGLIST
fi
sudo mkdir -p $RFSDIR/usr/local/bin
sudo cp -f $DESTDIR/usr/local/bin/{ls-*,restool} $RFSDIR/usr/local/bin
fi
elif [ $DISTROTYPE = ubuntu -o $DISTROTYPE = debian ]; then
if [ ! -f $DESTDIR/usr/local/bin/restool ]; then <--usr/local/bin/restool 为apps编译出来的
echo components packages not exist, building it ..
flex-builder -c apps -a ${DESTARCH} -f $CONFIGLIST <--如果没有需要重新编译
fi
sudo cp -rf $FBDIR/build/apps/components_$DESTARCH/* $RFSDIR <--拷贝编译出的apps
fi
sudo chroot $RFSDIR ldconfig
# install kernel modules
libmodules=$FBDIR/build/linux/kernel/$DESTARCH/lib/modules
if [ -d $libmodules ]; then
rm -f $FBDIR/$libmodules/*/{build,source}
sudo mkdir -p $RFSDIR/lib/modules
sudo rm -rf $RFSDIR/lib/modules/*
sudo cp -rf $libmodules/* $RFSDIR/lib/modules
sudo rm -f $RFSDIR/lib/modules/*.tgz
fi
# install PFE firmware to $RFSDIR/lib/firmware
if [ $CONFIG_MACHINE_LS1012ARDB = y -o $CONFIG_MACHINE_LS1012AFRWY = y ]; then
if [ ! -f $FBDIR/build/firmware/qoriq-engine-pfe-bin/ls1012a/slow_path/ppfe_class_ls1012a.elf ]; then
flex-builder -c qoriq-engine-pfe-bin
fi
sudo mkdir -p $RFSDIR/lib/firmware
. $FBDIR/configs/board/ls1012ardb/manifest
sudo cp -f $FBDIR/$pfe_kernel $RFSDIR/lib/firmware/
cd $RFSDIR/lib
mkdir -p $FBDIR/build/images
#tar cvzf $FBDIR/build/images/linux-lib-firmware.tgz firmware
cd $FBDIR
fi
# install perf
if [ -f $FBDIR/build/linux/kernel/$DESTARCH/perf ]; then
sudo cp -f $FBDIR/build/linux/kernel/$DESTARCH/perf $RFSDIR/usr/bin
fi
if [ "$CONFIG_BUILD_QORIQ_EDGESCALE" = "y" ]; then
if [ -f $RFSDIR/etc/rc.local ] && [ $DESTDIR/usr/local/bin/startup.sh ]; then
if ! grep startup.sh $RFSDIR/etc/rc.local; then
sudo sed -i '/does nothing/a\/usr\/local\/bin\/startup.sh &' $RFSDIR/etc/rc.local
fi
fi
fi
fbprint_d "merge kernel modules and apps components into $RFSDIR"
}
1.使用ubuntu_base制作文件系统
解压标题一制作好的压缩包rootfs_ubuntu_bionic_arm64.tar.gz
挂载一系列节点
wxd@ubuntu:~/work/OK10xx-linux-fs/flexbuild/build/rfs$ cat mount.sh
mount -t proc /proc /home/wxd/work/OK10xx-linux-fs/flexbuild/build/rfs/rootfs_ubuntu_bionic_arm64/proc
mount -t sysfs /sys /home/wxd/work/OK10xx-linux-fs/flexbuild/build/rfs/rootfs_ubuntu_bionic_arm64/sys
mount -o bind /dev /home/wxd/work/OK10xx-linux-fs/flexbuild/build/rfs/rootfs_ubuntu_bionic_arm64/dev
mount -o bind /dev/pts /home/wxd/work/OK10xx-linux-fs/flexbuild/build/rfs/rootfs_ubuntu_bionic_arm64/dev/pts
chroot手动执行安装一些flex-mkdistrorfs
第二步install_cfg_secondstage
里的步骤
# chroot rootfs_ubuntu_bionic_arm64
root@ubuntu:/#
install_cfg_secondstage() {
if [ -f /usr/aptpkg/.rfsblddone ] && [ ! -f /proc/cpuinfo ]; then
return
fi
if [ -n "$3" ]; then
packages_list=/usr/aptpkg/$3
else
packages_list=/usr/aptpkg/additional_packages_list_moderate <--里面是需要apt安装的deb包
fi
. $packages_list
# create user and passwd
if [ ! -d /home/user ]; then
useradd -m -d /home/user -s /bin/bash user <--添加用户,设置密码
gpasswd -a user sudo
echo -e 'root\nroot\n' | passwd root
echo -e 'user\nuser\n' | passwd user
mkdir -p /home/user
chown -R user:user /home/user
fi
# set default hostname
echo localhost > /etc/hostname
# set apt sources list to install additional packages
asl=/etc/apt/sources.list
if [ "$MKRFS_WITH_DEBOOTSTRAP" = y -a $DISTROTYPE = ubuntu ]; then
rm -f $asl
if [ $ARCH = "x86_64" -o $ARCH = "i686" ]; then
fn=archive; pn=ubuntu;
else
fn=ports; pn=ubuntu-ports;
fi
echo deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic main multiverse restricted universe >> $asl
echo deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-backports main multiverse restricted universe >> $asl
echo deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-proposed main multiverse restricted universe >> $asl
echo deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-security main multiverse restricted universe >> $asl
echo deb http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-updates main multiverse restricted universe >> $asl
echo deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic main multiverse restricted universe >> $asl
echo deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-backports main multiverse restricted universe >> $asl
echo deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-proposed main multiverse restricted universe >> $asl
echo deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-security main multiverse restricted universe >> $asl
echo deb-src http://mirrors.huaweicloud.com/ubuntu-ports/ bionic-updates main multiverse restricted universe >> $asl
# echo deb http://us.$fn.ubuntu.com/$pn/ $2 main restricted >> $asl
# echo deb-src http://us.$fn.ubuntu.com/$pn/ $2 main restricted >> $asl
# echo deb http://us.$fn.ubuntu.com/$pn/ $2-updates main restricted >> $asl
# echo deb-src http://us.$fn.ubuntu.com/$pn/ $2-updates main restricted >> $asl
# echo deb http://$fn.ubuntu.com/$pn $2-security main restricted >> $asl
# echo deb-src http://$fn.ubuntu.com/$pn $2-security main restricted >> $asl
# some packages (e.g. docker, iperf, netperf, etc) need to be installed from universe/multiverse
# echo deb http://us.$fn.ubuntu.com/$pn/ $2 universe >> $asl
# echo deb-src http://us.$fn.ubuntu.com/$pn/ $2 universe >> $asl
# echo deb http://us.$fn.ubuntu.com/$pn/ $2-updates universe >> $asl
# echo deb-src http://us.$fn.ubuntu.com/$pn/ $2-updates universe >> $asl
# echo deb http://us.$fn.ubuntu.com/$pn/ $2 multiverse >> $asl
# echo deb-src http://us.$fn.ubuntu.com/$pn/ $2 multiverse >> $asl
# echo deb http://us.$fn.ubuntu.com/$pn/ $2-updates multiverse >> $asl
# echo deb-src http://us.$fn.ubuntu.com/$pn/ $2-updates multiverse >> $asl
elif [ "$MKRFS_WITH_DEBOOTSTRAP" = y -a $DISTROTYPE = debian ]; then
rm -f $asl
echo deb [arch=$1] http://mirrors.kernel.org/debian/ $2 main >> $asl
fi
apt-get update
if [ $DISTROTYPE = ubuntu -a $DISTROSCALE != tiny ]; then
if ! dpkg-query -W language-pack-en-base 1>/dev/null; then
echo installing language-pack-en-base ..
DEBIAN_FRONTEND=noninteractive LC_ALL=C LANGUAGE=C LANG=C \
apt-get -y install language-pack-en-base
fi
fi
if [ ! -f /proc/uptime ]; then
mount -t proc proc /proc
fi
if [ ! -f /dev/pts/ptmx ]; then
mount -t devpts devpts /dev/pts
fi
#apt-get -y upgrade
# install cross toolchain for armhf on aarch64 machine
if [ $ARCH = aarch64 -a $DISTROTYPE = ubuntu -a $DISTROSCALE != tiny ] && \
[ -f /usr/bin/qemu-aarch64-static ]; then
apt-get -y install crossbuild-essential-armhf gcc-arm-linux-gnueabihf
fi
# Add additional packages for user convenience
echo installing additional packages: $additional_packages_list
for pkg in $additional_packages_list; do
echo installing $pkg ...
DEBIAN_FRONTEND=noninteractive apt-get -y install $pkg || true
done
echo installed additional packages.
if [ "$3" != "additional_packages_list_tiny" ]; then
# install python lib six depended by building ovs-dpdk locally
if ! pip show -q six; then
pip install six;
fi
fi
# install extrinsic packages which is needed but not provided yet from official ubuntu
if [ $DISTROSCALE != tiny ]; then
pkglist=`cd /usr/aptpkg && ls *.sh`
for pkg in $pkglist; do
pn=${pkg%.*}
if [ -n "$extrinsic_packages_list" ] && [ `echo $extrinsic_packages_list | grep -E $pn` ]; then
echo installing extrinsic package $pn ...
/usr/aptpkg/$pkg
fi
done
fi
if [ $1 = arm64 ]; then
tarch=aarch64-linux-gnu
elif [ $1 = armhf ]; then
tarch=arm-linux-gnueabihf
fi
if [ $1 = arm64 -o $1 = armhf ] && [ $DISTROSCALE != tiny ]; then
cd /lib/$tarch && ln -sf ../../usr/lib/$tarch/libxml2.so libxml2.so && \ <--编译apps要用到一些库
ln -sf ../../usr/lib/$tarch/libpcap.so libpcap.so && \
ln -sf ../../usr/lib/$tarch/libnuma.so libnuma.so && \
ln -sf ../../usr/lib/$tarch/libssl.so libssl.so && \
ln -sf ../../usr/lib/$tarch/libcrypto.so libcrypto.so
cd /usr/lib && ln -sf $tarch/libcunit.so libcunit.so
fi
if [ -f /usr/bin/sudo -a ! -u /usr/bin/sudo ]; then
chmod +s /usr/bin/sudo
fi
if [ -d /var/cache/man ]; then
chown -R man:root /var/cache/man
fi
# some shared libraries locate in /lib/aarch64-linux-gnu(or /lib/arm-linux-gnueabihf) and /usr/local/lib
LD_LIBRARY_PATH=/lib/$tarch
echo export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH >> /root/.bashrc
echo export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH >> /home/user/.bashrc
# set friendly rows and columns for tty <--这两句别加,深坑,查了一周vi为什么不正常
#echo stty columns 237 rows 58 >> /root/.bashrc
#echo stty columns 237 rows 58 >> /home/user/.bashrc
tmpusr=`ls -t /home | cut -d' ' -f1 | head -1`
if [ -d /home/$tmpusr -a "$tmpusr" != "user" ]; then
rm -rf /home/$tmpusr
fi
if [ $DISTROSCALE != tiny -a $DISTROTYPE = ubuntu ]; then
/usr/aptpkg/reconfigpkg.sh
fi
rm -rf /var/cache/apt/archives/*.deb
if [ -f /proc/uptime ]; then
umount /proc
fi
if [ -f /dev/pts ]; then
umount /dev/pts -l
fi
# find /dev/* | grep -v pts | xargs rm -rf
touch /usr/aptpkg/.rfsblddone <--这
}
四、文件系统解包
欲讲解包,先聊打包
compress_distrorfs() {
if [ -f $RFSDIR/proc/uptime ]; then
sudo chroot $RFSDIR umount /proc
fi
cd $RFSDIR
if [ $DISTROTYPE = ubuntu -o $DISTROTYPE = debian ]; then
if [ $DISTROSCALE = tiny ]; then
tarballname=rootfs_${DISTROTYPE}_${CODENAME}_${DESTARCH}_tiny_`date +%Y%m%d%H%M`.tgz
else
tarballname=rootfs_${DISTROTYPE}_${CODENAME}_${DESTARCH}_`date +%Y%m%d%H%M`.tgz
fi
fi
echo packing $tarballname, waiting ...
sudo tar czf $FBDIR/build/images/$tarballname *
cd ..
ln -sf $tarballname $FBDIR/build/images/rootfs_${DISTROTYPE}_${CODENAME}_${DESTARCH}.tgz
if [ "$MACHINE" = "ls1012ardb" ]; then
make_ext4fs -s -T -I -l 7510982656 $FBDIR/build/images/ubuntu.img $RFSDIR <--make_ext4fs就是打包命令,之前遇到过,打包/dev
fi 下面的节点会报错,是github上下载编译了新的make_ext4fs才好
if [ "$MACHINE" = "ls1043ardb" -o "$MACHINE" = "ls1046ardb"]; then
make_ext4fs -s -T -I -l 7473233920 $FBDIR/build/images/ubuntu.img $RFSDIR
fi
cd $FBDIR
fbprint_d $FBDIR/build/images/$tarballname
}
编译出的镜像文件,文件类型为Android sparse image
$ file ubuntu.img
ubuntu.img: Android sparse image, version: 1.0, Total of 1828608 4096-byte output blocks in 24286 input chunks.
sparse压缩文件系统镜像,目的是方便传输/刷机/存储等。想查看内容需先转换为raw格式,
可以使用工具simg2img 来转化,simg2img 来自deb包 android-sdk-libsparse-utils
$ simg2img -h
Usage: simg2img <sparse_image_files> <raw_image_file>
$ simg2img ubuntu.img ubuntu_raw.img
转化后的镜像为ext4是可以挂载的
$ file ubuntu_raw.img
ubuntu_raw.img: Linux rev 1.0 ext4 filesystem data, UUID=57f8f4bc-abf4-655f-bf67-946fc0f9f25b (extents) (large files)