Linux rootfs:移植Ubuntu-base文件系统到IMX6ULL开发板

1、镜像下载

去Ubuutu镜像官网下载对应CPU架构的镜像,IMX6ULL支持硬件浮点运算,属于armhf,所以下载ubuntu-base-16.04.6-base-armhf.tar.gz即可,其他发行版本切换到其他目录去查找。

注意:ubuntu-base构建的文件系统是没有UI界面的!


2、构建Ubuntu-base根文件系统步骤

(1)解压镜像,并且进入文件系统目录;
mkdir ubuntu_base_rootfs
sudo tar xzf ubuntu-base-16.04.6-base-armhf.tar.gz -C ./ubuntu_base_rootfs/
cd ubuntu_base_rootfs/
(2)PC机安装qemu,并将它拷贝到镜像中;
sudo apt install qemu-user-static
sudo cp /usr/bin/qemu-arm-static ./usr/bin/ 	# 把对应CPU架构的qemu程序拷贝过去
(3)更改软件源;
sudo cp /etc/resolv.conf ./etc/resolv.conf
sudo vi ./etc/apt/sources.list

sources.list追加的内容如下(使用的是中科大的软件源):

deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
(4)在主机上挂载Ubuntu-base文件系统,用于后面配置系统;
sudo mount -t proc /proc ./proc
sudo mount -t sysfs /sysfs ./sys
sudo mount -o bind /dev ./dev
sudo mount -o bind /dev/pts ./dev/pts
sudo chroot ./ 		# 此时当前目录是在ubuntu-base目录下
(5)安装常用软件到ubuntu-base文件系统中;
apt update
apt install sudo vim kmod net-tools ethtool ifupdown language-pack-en-base rsyslog iputils-ping
(6)设置root用户的密码;
passwd root
(7)设置本机名称与IP地址;
echo "yourhostname" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 yourhostname" >> /etc/hosts
(8)设置串口终端;

以串口1为例,它的名称为ttymxc0,所以使用以下ln命令创建一个软链接文件指向/lib/systemd/system/[email protected]

ln -s /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
(9)完成,退出!
exit 	# 退出前面的chroot修改的根目录
sudo umount ./proc
sudo umount ./sys
sudo umount ./dev/pts
sudo umount ./dev

3、使用测试

与其他rootfs类似,可以使用NFS挂载,也可以用于生成对应文件系统类型后直接烧写到flash上启动,只要你喜欢。


4、启动后进入系统

Ubuntu 16.04.6 LTS yourhostname ttymxc0

yourhostname login: root
Password:
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.1.15-g49efdaa armv7l)
...
root@yourhostname:~# 

5、一些常用设置

(注意:如果操作过程中提示有错误,可以考虑文件系统是否有rw读写权限!)

(1)添加新用户
root@yourhostname:/# adduser linrm
Adding user `linrm' ...
Adding new group `linrm' (1000) ...
Adding new user `linrm' (1000) with group `linrm' ...
Creating home directory `/home/linrm' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for linrm
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y
root@yourhostname:/#
root@yourhostname:/# ls /home/
linrm
root@yourhostname:/# 
(2)设置新用户可以使用sudo
su
chmod u+w /etc/sudoers
vi /etc/sudoers
yourusername ALL=(ALL:ALL) ALL
chmod u-w /etc/sudoers

使用过程中可能会提示一下错误提示:

sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

那么还需要切换root用户下执行以下命令:

chown root:root /usr/bin/sudo
chmod 4755 /usr/bin/sudo
(3)以eth0网卡为例,配置DHCP自动获取IP地址

如果使用的是NFS网络文件系统,这一步暂时不用管。

sudo echo auto eth0 > /etc/network/interfaces.d/eth0
sudo echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0
sudo /etc/init.d/networking restart

参考文章:

  • https://juejin.cn/post/6844904186367180808

你可能感兴趣的:(Linux系统移植,linux,ubuntu,imx6ull,rootfs)