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:

  1. On the Linux development host, install the BSP distribution and activate the cross-build environment as described in :

    $ tar -jxf linux-cm-imxrt-<bsp>-<release>.tar.bz2 $ cd linux-cm-imxrt-<bsp>-<release> $ . ./ACTIVATE.sh
  2. Change to the rootfs project directory:

    $ cd projects/rootfs
  3. Update the Linux configuration in order to not include the initial RAM disk into the bootable uImage. For this, run make kmenuconfig in the project directory and uncheck (disable) the Initial RAM filesystem... option:

    General setup ---> [ ] Initial RAM filesystem and RAM disk (initramfs/initrd) support
  4. 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 in Makefile. Open the projects/rootfs/Makefile file in a text editor and uncomment the following line:

  5. Build the project:

  6. 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:

  1. 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:

  2. 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):

  3. Format the Boot partition with a FAT file system:

  4. Install the Linux bootable image to the Boot partition on the SD card:

  5. Format the RootFS partition with the EXT4 file system:

    The lazy_itable_init=0,lazy_journal_init=0 options to mkfs.ext4 are required to disable "lazy initialization", due to issues with this EXT4 feature on the no-MMU targets in kernel 5.15.

  6. 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):

  7. Set up the boot jumper on the target board to boot from SD Card.

  8. Insert the prepared card into the SD Card holder on the target.

  9. 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:

  10. Update the bootargs environment variable to use /dev/mmcblk0p2 matching the 2nd partition on the SD Card:

  11. 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:

  12. 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: