创建ubuntu根文件系统
1.安装qemu
在Linux PC主机上安装模拟器:
sudo apt-get install qemu-user-static
2.下载和解压 ubuntu-core
ubuntu根文件系统是基于Ubuntu base 16.04来创建的。用户可以到 http://cdimage.ubuntu.com/ubuntu-base/releases/16.04/release/ 下载,选择下载ubuntu-base-16.04.6-base-arm64.tar.gz 。下载完之后,创建临时文件夹并解压根文件系统
mkdir temp
sudo tar -xpf ubuntu-base-16.04.6-base-arm64.tar.gz -C temp
3.修改根文件系统
准备网络:
sudo cp -b /etc/resolv.conf temp/etc/resolv.conf
准备qemu:
sudo cp /usr/bin/qemu-aarch64-static temp/usr/bin/
进入根文件系统进行操作:
sudo chroot temp
执行更新操作:
apt update
apt upgrade
安装自己需要的应用程序,例如vim,git等,具体可根据自己的需要,如果以后需要预装什么软件到系统中,可以在这里执行安装对应的工具包即可:
在pc平台上进行ubuntu的软件安装,执行以下命令:
apt-get update
apt-get upgrade
apt-get install sudo
apt-get install net-tools
apt-get install ethtools
apt-get install network-manager //这个服务程序有可能会导致网卡的静态ip设置不按照/etc/network/interfaces来解析,建议可先不安装
apt-get install iputils-ping
apt-get install base-completion
apt-get install ifupdown
apt-get install wireless-tools
apt-get install openssh-server
apt-get install vim git ....(具体可以根据自己需求添加不同的工具)
4.添加用户及设置密码
添加用户,例如我这里添加用户名为 arm64:
useradd -s '/bin/bash' -m -G adm,sudo arm64
给用户设置密码,先执行passwd arm64,然后输入两次你要设置的密码:
root@ubuntu:/# passwd arm64
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
给root用户设置密码,先执行passwd root,然后输入两次你要设置的密码:
root@ubuntu:/# passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
修改完自己的根文件系统就可以退出了。
exit
5.制作根文件系统
制作自己的根文件系统,大小依据自己的根文件系统而定,注意依据temp文件夹的大小来修改count值,2048表
示2GB的大小。
dd if=/dev/zero of=linux_ubuntu_16.04.img bs=1M count=2048
sudo mkfs.ext4 linux_ubuntu_16.04.img
mkdir rootfs
sudo mount linux_ubuntu_16.04.img rootfs/
sudo cp -rfp temp/* rootfs/
sudo umount rootfs/
这样 linux_ubuntu_16.04.img 就是最终的根文件系统映像文件了。
6.遇到的问题点
6.1 开机起来卡在以下log不动:
[ OK ] Started Daily Cleanup of Temporary Directories.
[ OK ] Reached target System Time Synchronized.
[ OK ] Started Daily apt download activities.
[ OK ] Started Message of the Day.
[ OK ] Started Daily apt upgrade and clean activities.
[ OK ] Reached target Timers.
[ OK ] Started Permit User Sessions.
[ OK ] Started LSB: Set the CPU Frequency Scaling governor to "ondemand".
[ OK ] Started getty on tty2-tty6 if dbus and logind are not available.
[ OK ] Started Raise network interfaces.
[ OK ] Reached target Network.
Starting /etc/rc.local Compatibility...
[ OK ] Started /etc/rc.local Compatibility.
[ OK ] Started Getty on tty1.
[ OK ] Started Getty on tty3.
[ OK ] Started Getty on tty5.
[ OK ] Started Getty on tty6.
[ OK ] Started Getty on tty4.
[ OK ] Started Getty on tty2.
[ TIME ] Timed out waiting for device dev-ttyFIQ0.device.
[DEPEND] Dependency failed for Serial Getty on ttyFIQ0.
[ OK ] Reached target Login Prompts.
[ OK ] Reached target Multi-User System.
[ OK ] Reached target Graphical Interface.
Starting Update UTMP about System Runlevel Changes...
[ OK ] Started Update UTMP about System Runlevel Changes.
解决办法:
在主机上制作rootfs镜像时,执行 apt-get install udev 一下,安装udev。
6.2 执行ifconfig,提示command not found:
root@localhost:~# ifconfig
bash: ifconfig: command not found
解决办法:
在主机上制作rootfs镜像时,执行 apt install net-tools 安装net-tools工具,这一步其实可以在第3步的时候执行apt install安装即可。
然后开机起来就可以执行 ifconfig -a 看到网卡设备了。
root@localhost:~# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:24
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:960 errors:0 dropped:0 overruns:0 frame:0
TX packets:960 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:76800 (76.8 KB) TX bytes:76800 (76.8 KB)
sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
然后配置一下ip和网关等信息,就可以连接网络了。
root@localhost:~# vi /etc/network/interfaces
添加以下内容(具体ip和网关,dns根据你的实际添加):
auto eth0
iface eth0 inet static
address 192.168.11.186
gateway 192.168.11.1
netmask 255.255.255.0
dns-nameservers 114.114.114.114
6.3 开机起来之后,使用root账户登录时总是提示 login incorrect,无法输入密码(这个可根据需要修改,不改也无伤大雅):
SSH可以登录
别的用户也可以通过telnet登录
唯独root不可以
解决方法1:
注释掉以下代码即可。
vi /etc/pam.d/login
#auth [success=ok new_authtok_reqd=ok ignore=ignore user_unknown=bad default=die] pam_securetty.so //注释这行
解决方法2(待验证):
修改/etc/securetty文件,在其末尾添加ttyFIQ0,以允许root在串口终端登陆。
6.4 根文件系统加载后,大小不正常,未占满整个分区:
root@localhost:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.5G 1.5G 0 100% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.7M 1.9G 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 388M 0 388M 0% /run/user/0
在系统正确加载后执行扩展文件系统命令或者直接添加到脚本中实现:
resize2fs -p /dev/mmcblk1p5 // dev/mmcblk1p5是你的根文件系统目录
执行之后:
root@localhost:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 29G 1.7G 26G 7% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.7M 1.9G 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 388M 0 388M 0% /run/user/0