[Ubuntu] 移植ubuntu18.04.4根文件系统到嵌入式平台
1、通过 ubuntu cdimage 下载 ubuntu18.04.4内核
在 windows 系统网页中下载
版本:ubuntu-base-18.04.4-base-armhf.tar.gz
2、解压
$ mkdir linux-rootfs
$ sudo tar -xpf ubuntu-base-18.04.4-base-armhf.tar.gz -C linux-rootfs
3、在电脑的 ubuntu 系统中安装模拟器并拷贝到根文件系统
$ sudo apt-get install qemu-user-static
$ sudo cp /usr/bin/qemu-arm-static linux-rootfs/usr/bin/
4、拷贝本地dns文件到根文件系统
$ sudo cp -b /etc/resolv.conf linux-rootfs/etc/resolv.conf
5、打开根文件系统中的 linux-rootfs/etc/apt/sources.list 修改安装包源
$ sudo vim linux-rootfs/etc/apt/sources.list
将屏蔽的源全部打开
6、挂载脚本mount.sh
#!/bin/bash
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 chroot ${2}
}
function umnt() {
echo “UNMOUNTING”
sudo umount ${2}/proc
sudo umount ${2}/sys
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
挂载根文件系统 ./mount.sh -m linux-rootfs
7、更新根文件系统
#apt-get update
#apt-get upgrade
8、安装自己需要的工具包
#apt-get install vim git openssh-server sudo net-tools iputils-ping wireless-tools udev htop rsyslog network-manager ifupdown ethtoo florence
安装登录界面、显示界面
XUBUNTU
#apt-get install ubuntu-session xubuntu-desktop
#update-alternatives --config x-session-manager
选择 lightdm
UBUNTU
#apt-get install ubuntu-session ubuntu-desktop
自动选择gdm3
上述安装可能报错:
Errors were encountered while processing:
blueman
E: Sub-process /usr/bin/dpkg returned an error code (1)
解决方法:
#cd /var/lib/dpkg/
/var/lib/dpkg# mv info/ info_old
/var/lib/dpkg# mkdir info
/var/lib/dpkg# apt-get update
/var/lib/dpkg# apt-get -f install
/var/lib/dpkg# mv info/* info_old/
/var/lib/dpkg# rm -rf info/
/var/lib/dpkg# mv info_old/ info
9、配置网络
#echo auto eth0 > etc/network/interfaces.d/eth0
#echo iface eth0 inet dhcp >> etc/network/interfaces.d/eth0
#echo auto wlan0 > etc/network/interfaces.d/wlan0
#echo allow-hotplug wlan0 > etc/network/interfaces.d/wlan0
#echo iface wlan0 inet dhcp >> etc/network/interfaces.d/wlan0
10、修改系统主机名称
#vim /ect/hostname
添加用户,设置密码
useradd -s ‘/bin/bash’ -m -G adm,sudo admin
passwd admin
passwd root
11、退出挂载脚本
#exit
./mount.sh -u linux-rootfs
12、制作镜像文件
#!/bin/bash -e
TARGET_ROOTFS_DIR=./linux-rootfs
MOUNTPOINT=./rootfs
ROOTFSIMAGE=linaro-rootfs.img
OUT=…/out
echo Making rootfs!
if [ -e ${ROOTFSIMAGE} ]; then
rm ${ROOTFSIMAGE}
fi
if [ -e ${MOUNTPOINT} ]; then
rm -r ${MOUNTPOINT}
fi
#Create directories
mkdir M O U N T P O I N T d d i f = / d e v / z e r o o f = {MOUNTPOINT} dd if=/dev/zero of= MOUNTPOINTddif=/dev/zeroof={ROOTFSIMAGE} bs=1M count=0 seek=6000
finish() {
sudo umount ${MOUNTPOINT} || true
echo -e “\e[31m MAKE ROOTFS FAILED.\e[0m”
exit -1
}
echo Format rootfs to ext4
mkfs.ext4 ${ROOTFSIMAGE}
echo Mount rootfs to ${MOUNTPOINT}
sudo mount ${ROOTFSIMAGE} ${MOUNTPOINT}
trap finish ERR
echo Copy rootfs to ${MOUNTPOINT}
sudo cp -rfp ${TARGET_ROOTFS_DIR}/* ${MOUNTPOINT}
echo Umount rootfs
sudo umount ${MOUNTPOINT}
echo Rootfs Image: ${ROOTFSIMAGE}
e2fsck -p -f ${ROOTFSIMAGE}
resize2fs -M ${ROOTFSIMAGE}
[ ! -d ${OUT} ] && mkdir ${OUT}
cp $ROOTFSIMAGE ${OUT}
13,烧录镜像,开机发现的的问题
终端无法打开:
apt-get remove gnome-terminal
apt-get install xterminal
安装标准ubuntu 用的 gmd3 HDMI登陆界面无法显示
vim /etc/gdm3/custom.conf
取消注释 WaylandEnable = false
#######后续问题,继续完善########