IMX6ULL - Linux root file system (rootfs) build

Keywords: Linux imx6ull

Author: zzssdd2

E-mail: zzssdd2@foxmail.com

1, Ubuntu-base20.04.3

Ubuntu has officially made the root file system of base version of each architecture and version. Just download it and make a few changes.

  1. download Ubuntu Base 20.04.3 LTS (Focal Fossa)

    ubuntu-base-20.04.3-base-armhf.tar.gz	2021-08-19 10:56	22M
    
  2. decompression

    mkdir rootfs
    sudo chmod 777 rootfs
    tar -zxvf ubuntu-base-20.04.3-base-armhf.tar.gz -C rootfs
    #Avoid errors in later software updates
    sudo chmod 777 ./rootfs/tmp/
    
  3. Installation tools

    sudo apt-get install qemu-user-static
    sudo cp /usr/bin/qemu-arm-static ./rootfs/usr/bin/
    
  4. Copy host DNS

    sudo cp /etc/resolv.conf ./rootfs/etc/resolv.conf
    
  5. Replace download source

    cp ./rootfs/etc/apt/source.list ./rootfs/etc/apt/source.list.bak
    vim ./rootfs/etc/apt/source.list
    `Esc` + `:`
    %s/ports.ubuntu.com/mirror.tuna.tsinghua.edu.cn/g
    `Enter`
    
  6. Create the mount script vim mount.sh

    The contents are as follows:

    #!/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
    
    

    Change permissions:

    sudo chmod +x mount.sh 
    
  7. mount

    source mount.sh -m ./rootfs/
    
  8. Update software

    apt update
    apt install sudo vim kmod net-tools ethtool ifupdown rsyslog htop iputils-ping language-pack-en-base ssh
    

    Note: ssh must be installed, or the following link serial port service will make an error

  9. Set user name and password

    root@zsd-virtual-machine:/# passwd root
    New password: 
    Retype new password: 
    passwd: password updated successfully
    
    root@zsd-virtual-machine:/# adduser zsd 
    New password: 
    Retype new password: 
    `Enter`
    `Enter`
    ......
    `Enter`
    `Enter`
    
  10. Set IP and name

    root@zsd-virtual-machine:/# echo "zzssdd2-imx6ull" > /etc/hostname
    root@zsd-virtual-machine:/# echo "127.0.0.1 localhost" >> /etc/hosts
    root@zsd-virtual-machine:/# echo "127.0.0.1 zzssdd2-imx6ull" >> /etc/hosts
    
  11. Set serial port terminal

    ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttymxc0.service
    

    be careful:

    If an error is reported, the prompt is as follows:

    root@zsd-virtual-machine:/# ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttymxc0.service
    /usr/bin/ln: failed to create symbolic link '/etc/systemd/system/getty.target.wants/getty@ttymxc0.service': No such file or directory
    

    Note there is no getty.target.wants directory in / etc/systemd/system /.

    Solution: the directory will be created when ssh is installed, and then re execute the command to set the serial port terminal.

  12. sign out

    #Exit qemu simulator
    exit
    #Unmount
    source mount.sh -u ./rootfs/
    #pack
    sudo tar -czvf ubuntu-base-20.04.3-rootfs.tar.gz rootfs/*
    

2, Debian 11

  • Directly use the Debian root file system made by three parties, such as Linaro
  • use Multistrap or Debootstrap Tool to build your own Debian root file system

Next, I use the debootstrap tool to build the Debian 11 root file system (don't ask why you don't use multistrap, just don't ask) []

  1. Installation tools

    sudo apt install binfmt-support qemu qemu-user-static debootstrap
    
  2. Extract Debain file system

    sudo debootstrap --arch=armhf --foreign bullseye rootfs https://mirrors.tuna.tsinghua.edu.cn/debian/
    

    Parameter Description:

    arch: CPU architecture

    Bull eye: debian version name, which is the name of version 11

    foreign: this parameter needs to be specified when it is different from the host architecture. It is only used for initial unpacking

    rootfs: the folder where you want to store the file system

    https://mirrors.tuna.tsinghua.edu.cn/debian/ : Download source. Here, the domestic Tsinghua source is used

    After successful extraction:

    $ ls ./rootfs/
    bin   debootstrap  etc   lib   root  sbin  tmp  var
    boot  dev          home  proc  run   sys   usr
    
  3. Copy QEMU arm static to the basic system you just built

    sudo cp /usr/bin/qemu-arm-static ./rootfs/usr/bin
    
  4. File system boot complete

    sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true chroot rootfs debootstrap/debootstrap --second-stage
    

    Parameter Description:

    • chroot rootfs

      Change the root directory to rootfs: that is, change the visible root path of the current process and its child processes. After the change, the program cannot access files and commands outside the visible root directory.

    • DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true

      Avoiding debconf asking users any questions (non interactive) is equivalent to silently configuring the installation.

      Learn more debconf - Debian Wiki

    • debootstrap

      man debootstrap
       or
      debootstrap --help
      

      Learn more Debootstrap - Debian Wiki

    The prompt after completion is as follows:

    I: Base system installed successfully.
    
  5. Replace download source

    #backups
    sudo cp ./rootfs/etc/apt/sources.list ./rootfs/etc/apt/sources.list.bak
    #edit
    sudo vim ./rootfs/etc/apt/sources.list
    
    #Replace with the following:
    
    # The source image is annotated by default to improve apt update speed. You can cancel the annotation if necessary
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
    
  6. Create the mount script vim mount.sh

    The contents are as follows:

    #!/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
    
    

    Change permissions:

    sudo chmod +x mount.sh 
    
  7. mount

    source mount.sh -m ./rootfs/
    
  8. Execute the following command

    # <file system> <mount point> <type> <options> <dump> <pass>
    echo "proc /proc proc defaults 0 0" >> etc/fstab 
    
  9. Setting locale environment parameters in Linux

    export LC_ALL=C
    

    If it is not set, the following prompt will appear when installing the software later:

    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:
    	LANGUAGE = "zh_CN:en_US:en",
    	LC_ALL = (unset),
    	LC_PAPER = "zh_CN.UTF-8",
    	LC_NUMERIC = "zh_CN.UTF-8",
    	LC_IDENTIFICATION = "zh_CN.UTF-8",
    	LC_MEASUREMENT = "zh_CN.UTF-8",
    	LC_NAME = "zh_CN.UTF-8",
    	LC_TELEPHONE = "zh_CN.UTF-8",
    	LC_ADDRESS = "zh_CN.UTF-8",
    	LC_MONETARY = "zh_CN.UTF-8",
    	LC_TIME = "zh_CN.UTF-8",
    	LANG = "zh_CN.UTF-8"
        are supported and installed on your system.
    perl: warning: Falling back to the standard locale ("C").
    /usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
    /usr/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory
    /usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
    
  10. Install software

    apt update
    
    apt install sudo
    apt install net-tools
    apt install ethtool 
    apt install htop 
    apt install ssh
    ......
    
  11. Set user

    #Set root user password
    passwd root
    #Add new user
    adduser zzssdd2
    
  12. Set up Ethernet

    echo "auto eth0" > /etc/network/interfaces.d/eth0
    echo "iface eth0 inet dhcp" >> /etc/network/interfaces.d/eth0
    
  13. Set IP and name

    echo "zzssdd2-imx6ull" > /etc/hostname
    echo "127.0.0.1 localhost" >> /etc/hosts
    echo "127.0.0.1 zzssdd2-imx6ull" >> /etc/hosts
    
  14. sign out

    #Exit qemu environment
    exit
    # Unmount
    source mount.sh -u ./rootfs/
    #pack
    sudo tar -zcvf debian_bullseye-rootfs.tar.gz ./rootfs/*
    

3, Builderoot

Buildroot Is a simple, efficient and easy-to-use tool, which can generate embedded Linux system through cross compilation. Refer to the official manual for more details The Buildroot user manual

Next, use build root-2021.08.1 to configure the IMX6ULL platform.

  1. Download: https://buildroot.org/download.html

  2. Unzip: tar -jxvf builderoot-2021.08.1.tar.bz2

  3. Enter the graphical configuration interface: make menuconfig

    Note: the options posted below are manually configured and changed. If they are not posted, it means that the default settings are used

  4. Configure Target options

    Target options  ---> 
    	Target Architecture (ARM (little endian))
    	Target Binary Format (ELF)
    	Target Architecture Variant (cortex-A7)
    	Target ABI (EABIhf)
    	Floating point strategy (NEON/VFPv4)
    	ARM instruction set (ARM)
    
  5. Configure Toolchain

    Toolchain  --->  
    	Toolchain type (External toolchain)
    	Toolchain (Custom toolchain)
    	Toolchain origin (Pre-installed toolchain)
    	(/usr/local/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf) Toolchain path 
    	($(ARCH)-none-linux-gnueabihf) Toolchain prefix 
        External toolchain gcc version (10.x)
        External toolchain kernel headers series (4.20.x)
        External toolchain C library (glibc/eglibc)
        [ ] Toolchain has RPC support? 
        [*] Toolchain has C++ support?
    
  6. Configure System configuration

    System configuration  --->
    	(zzssdd2) System hostname 
    	(Hello zzssdd2) System banner
    	/dev management (Dynamic using devtmpfs + mdev) 
    	(root) Root password
    	(eth0) Network interface to configure through DHCP 
    
  7. Configure Target packages

    In this step, you can select the package you need to install according to your own needs (here, I keep the default selection for faster compilation in the next step).

  8. After the on-demand configuration is completed: save -- > Exit -- > execute the make command and wait until the compilation is completed. The compiled root file system can be seen in the output/images directory under the Buildroot root directory.

    be careful:

    1. If you have executed make before compiling, you need to execute make clean first and then execute the make command, otherwise an error may be reported.
    2. If some packages are extremely slow to download, do not move down, or fail to download, you can copy them to the browser for manual download according to the address prompted by the compilation information. After downloading it, copy it to the dl directory under the root directory of builderoot, and then CTRL+C terminates the compilation -- > make clean clears the last compilation -- > make recompile.

4, Verify

reference resources Building NFS & TFTP environment with development board directly connected to computer

Posted by Vasko on Sat, 30 Oct 2021 00:23:53 -0700