Booting Linux with root Filesystem on SD Card
The Linux BSP (Board Support Package) for the NXP i.MXRT SoCs supports booting from SD card. By default, the root file system is a part of the bootable Linux image and resides in SDRAM when the target board is running.
This application note explains how to configure the Linux project and prepare the SD card to move the root file system to a separate, ext4 formatted partition on the SD card. This provides the following benefits:
No need to keep all files in the init RAM disk inside the bootable image;
Use a larger file system without affecting resources in RAM;
Update the file system on the per-file basis without need to rebuild the entire bootable image.
1. Building the Project
Step through the following procedure:
On the Linux development host, install the BSP distribution and activate the cross-build environment as described in Installing and Activating Cross Development Environment :
$ tar -jxf linux-cm-imxrt-<bsp>-<release>.tar.bz2 $ cd linux-cm-imxrt-<bsp>-<release> $ . ./ACTIVATE.sh
Change to the
rootfs
project directory:$ cd projects/rootfs
Update the Linux configuration in order to not include the initial RAM disk into the bootable
uImage
. For this, run makekmenuconfig
in the project directory and uncheck (disable) the Initial RAM filesystem... option:General setup ---> [ ] Initial RAM filesystem and RAM disk (initramfs/initrd) support
Enable building the tarball with the root file system outside of the bootable uImage. For this, define the special
FS_IMAGES
option as$(SAMPLE).tar.gz
inMakefile
. Open theprojects/rootfs/Makefile
file in a text editor and uncomment the following line:Build the project:
Check that the following images required to boot the system with the root file system mounted on SD Card has been created:
rootfs.uImage
- a kernel image without the root file system in it;rootfs.tar.gz
- a tarball containing the root filesystem.
2. Partitioning SD Card
The Emcraft Linux software distribution for the i.MX RT BSPs assumes the following utilization of the SD card storage:
The first 1MB is a service area to store the partition table and the bootloader files;
The next 100MB are allocated to the Boot partition to store the bootable Linux image;
The remainder of the SD card space is allocated to the RootFS partition to store the root file system.
Step through the following procedure:
Use the fdisk utility to prepare the SD card on a Linux host.
As all operations are made with the root permissions, be careful, and verify the destination
/dev/sdX
to avoid corruption of the system drives:Remove all partitions using the
d
command:Use the
n
command to create new primary (p
) partitions. The first partition size is 100M, the second one size is all free space left on SD card:
Install U-Boot to the beginning of the SD card (the prebuilt U-Boot SPL and TPL images can be obtained from the Emcraft web site):
Format the Boot partition with a FAT file system:
Install the Linux bootable image to the Boot partition on the SD card:
Format the RootFS partition with the EXT4 file system:
The
lazy_itable_init=0,lazy_journal_init=0
options tomkfs.ext4
are required to disable "lazy initialization", due to issues with this EXT4 feature on the no-MMU targets in kernel 5.15.Mount the RootFS partition, change to the mounted partition directory and unpack the
rootfs.tar.gz
image here (the command can require the root privileges):Set up the boot jumper on the target board to boot from SD Card.
Insert the prepared card into the SD Card holder on the target.
Update the
bootargs
environment variable in U-boot to tell the kernel to mount the root file system from the dedicated partition on the SD Card. For this, power on the target board and stop booting in the U-Boot command monitor by pressing any key:Update the bootargs environment variable to use
/dev/mmcblk0p2
matching the 2nd partition on the SD Card:Reset the board to boot Linux with the root filesystem on the SD Card. Wait for the shell prompt and check that the system is booted and the mount utility shows that the root file system resides on the SD Card partition
/dev/mmcblb0p2
:Boot the board with the root file system on the SD Card. Wait for the shell prompt and check that root file system is mounted in the Read/Write mode: