Build a root file system based on ubuntu-base and transplant it to the RK3568 development board

foreword

1. Use ubuntu-base to build the root file system

1. Obtain ubuntu-base-18.04.5-base-arm64.tar.gz from the ubuntu official website

2. Copy the obtained file to the ubuntu virtual machine, create a new directory, and decompress it.

3. Install qemu-user-static

4. Set the software source

5. Configure DNS

6. Mount the ubuntu-base file system

7. Install the necessary software

8. Install the desktop environment

9. Modify root user password

10. Add new user

11. New users use the sudo command

12. Set the host name and IP

13. Configure DHCP

14. Modify the default waiting time for system restart

15. Set boot password-free login to the graphical interface

16. Disable system hibernation

2. Package the image file

1. Create an empty image file with a size of 6144MB

2. Format the file into ext4 file system

3. Mount the image file to an empty folder, and then copy the ubuntu_rootfs file to the empty folder

4. After copying, use e2fsck to repair and detect the mirror file system, and resize2fs to reduce the size of the mirror file

3. Burn the file system to the development board

reference:


foreword

The configuration parameters of the domestic Rockchip RK3568 development board are eye-catching and cost-effective.

But the official soft ecology based on buildroot is not ideal, and I personally like the official ubuntu interface, so I consulted the literature, built the ubuntu file system, and finally successfully ran it on the development board! joy! sprinkle flowers~~~

In this process, there are countless pits, so I will make a record here, so that I can continue to improve it in the future.

lab environment:

Development board: Xunwei RK3568

File system: ubuntu-base-18.04.5-base-arm64

1. Use ubuntu-base to build the root file system

1. Obtain ubuntu-base-18.04.5-base-arm64.tar.gz from the ubuntu official website

Download address: ubuntu-base-18.04.5-base-arm64.tar.gz

2. Copy the obtained file to the ubuntu virtual machine, create a new directory, and decompress it.

mkdir ubuntu_rootfs
sudo tar -xpf ubuntu-base-18.04.5-base-arm64.tar.gz -C ubuntu_rootfs/

3. Install qemu-user-static

qemu-user-static is an emulator, which can select the arm64 configuration file to simulate the operating environment of the development board, and then mount the downloaded ubuntu-base file to build the ubuntu file system.

sudo apt install qemu-user-static

Since the downloaded ubuntu-base is of aarch64 architecture, you need to copy qemu-aarch64-static to ubuntu_rootfs/usr/bin/.

sudo cp /usr/bin/qemu-aarch64-static ubuntu_rootfs/usr/bin

4. Set the software source

It should be noted that the ARM source is used here, and the source of our machine cannot be copied.

sudo vim ./ubuntu_rootfs/etc/apt/sources.list

Here we choose Huawei's domestic download source.

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

Delete the original text and replace the content.

5. Configure DNS

In order to update the software online, we copy the local dns configuration file to the root file system

sudo cp /etc/resolv.conf ubuntu_rootfs/etc/resolv.conf

Then add dns in the /etc/resolv.conf file

sudo vim ./ubuntu_rootfs/etc/resolv.conf

Add content as follows

nameserver 8.8.8.8
nameserver 114.114.114.114

6. Mount the ubuntu-base file system

Write a mount script

#!/bin/bash
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}
}
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

Increase script execution permissions

sudo chmod +x mount.sh

Mount the file system

bash mount.sh -m ubuntu_rootfs/

unmount file system

bash mount.sh -u ubuntu_rootfs/

Notice:

After mounting, you will enter the development board simulation environment, you can install software and change the system configuration;

After the file system is built, enter exit to exit the simulation environment, then run the script to uninstall the ubuntu_base file system;

Finally, package the image.

7. Install the necessary software

apt-get update

apt-get install net-tools
apt-get install ethtool
apt-get install ifupdown
apt-get install psmisc
apt-get install nfs-common
apt-get install htop
apt-get install vim
apt-get install rsyslog
apt-get install iputils-ping
apt-get install language-pack-en-base
apt-get install sudo
apt-get install network-manager

8. Install the desktop environment

apt-get install ubuntu-desktop

9. Modify root user password

For convenience, we can also set the password to root.

10. Add new user

Here you need to enter some user information, or you can directly press Enter to keep the default value.

11. New users use the sudo command

By default, new users cannot use the sudo command, we need to modify the /etc/sudoers file.

The /etc/sudoers file is read-only by default, so you need to modify the write permission of this file first, using the following command:

chmod u+w /etc/sudoers

Then use vim to open /etc/sudoers, find the line "root ALL=(ALL:ALL) ALL", and add below this line:

vim /etc/sudoers

ssismm	ALL=(ALL:ALL) ALL

After the modification is completed, save and exit, and restore the read-only attribute of /etc/sudoers, using the following command:

chmod u-w /etc/sudoers

12. Set the host name and IP

echo "rk3568" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 rk3568" >> /etc/hosts

13. Configure DHCP

Let's configure the network DHCP, so that the network will be automatically set up after the system starts.

RK3568 has two network cards by default.

NIC eth0:

echo auto eth0 > /etc/network/interfaces.d/eth0
echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0

NIC eth1:

echo auto eth1 > /etc/network/interfaces.d/eth1
echo iface eth1 inet dhcp >> /etc/network/interfaces.d/eth1

In the actual test, the network port must be connected to the network cable system to start normally. That is, in the case of not being connected to the Internet, it takes a long time to start every time, and the card is stuck on the network connection for 5 minutes. Here we can modify the following file:

vim /lib/systemd/system/networking.service

 Change the TimeoutStartSec=5min inside to:

TimeoutStartSec=10sec

14. Modify the default waiting time for system restart

When restarting the development board, if there is a process that has not ended, the system will wait. The default waiting time is very long, resulting in a slow restart.

We can modify the default wait time:

vim /etc/systemd/system.conf

Find these lines:

 #DefaultTimeoutStartSec=90s
 #DefaultTimeoutStopSec=90s
 #DefaultTRestartSec=100ms

Uncomment and change DefaultTimeoutStopSec=90s to:

 DefaultTimeoutStopSec=1s

Save and exit.

15. Set boot password-free login to the graphical interface

We modify the 50-ubuntu.conf file with the following command:

vim /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf

Add the following content at the end of the file, as shown in the figure below after adding:

greeter-show-manual-login=true

all-guest=false

Save and exit after the modification is complete, and then enter the following command to modify the content of the gdm-autologin file, as shown in the figure below after modification:

vim /etc/pam.d/gdm-autologin

Then enter the following command to modify the content of the gdm-password file, and the modification is completed as shown in the figure below:

vim /etc/pam.d/gdm-password

Then enter the following command to modify the /root/.profile file:

vim /root/.profile

Change the last line of the file to the following content, and the modification is completed as shown in the figure below:

tty -s && mesg n || true

Then enter the following command to modify the custom.conf file:

vim /etc/gdm3/custom.conf

Add the following content to the end of the file, as shown in the figure below:

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=root
TimedLoginEnable=true
TimedLogin=root
TimedLoginDelay=10

16. Disable system hibernation

Check:

sudo systemctl status sleep.target

disable:

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

So far, the file system we built can open the visual interface for root user password-free login!

2. Package the image file

1. Create an empty image file with a size of 6144MB

dd if=/dev/zero of=ubuntu_rootfs.img bs=1M count=6144

2. Format the file into ext4 file system

mkfs.ext4 ubuntu_rootfs.img

3. Mount the image file to an empty folder, and then copy the ubuntu_rootfs file to the empty folder

mkdir ubuntu_base_rootfs
sudo mount ubuntu_rootfs.img ubuntu_base_rootfs
sudo cp -rfp ubuntu_rootfs/* ubuntu_base_rootfs/

4. After copying, use e2fsck to repair and detect the mirror file system, and resize2fs to reduce the size of the mirror file

sudo umount ubuntu_base_rootfs/
e2fsck -p -f ubuntu_rootfs.img
resize2fs -M ubuntu_rootfs.img

In the end, we got the file system image file with a size of 4.9GB 

3. Burn the file system to the development board

For simplicity, first burn the official buildroot image on the development board, and then burn the file system separately.

At this point, you're done! There should be applause here! ! ! sprinkle flowers~~~

reference:

[ARM] Use Ubuntu-base to build the root file system

Build a root file system based on ubuntu-base and transplant it to the RK3568 development board

Guess you like

Origin blog.csdn.net/ssismm/article/details/129612239