[linux] rootfs root file system image production

In the embedded linux platform, most of the work is to fill the root file system. During development, the root file system is generally placed on the development host in the form of a directory.

When the root file system is filled, we need to package it into xxx.img or other image formats. This article takes the xxx.img image format as an example to describe how to package the root file system into an img image file.

The root file system directory structure and files packaged in this article are shown in the following figure:


(The files and directories are a bit messy, it doesn't affect)

These directories and files are stored rootfsunder the directory.

We open the linux terminal in the same level directory as the rootfs directory, and enter the following command:

dd if=/dev/zero of=rk3568.img bs=1M count=2000

As shown below:

In the picture above:

  • dd: is a linux command for reading, converting and outputting data.
  • if : Indicates the input file.
  • of : Indicates the output file.
  • bs : Indicates the block size.
  • count : Indicates the number of blocks to be copied.

The meaning of the above command is to create a 2000M (about 2G) file, and the content is all filled with 0.

After running the above command, a file will be created rk3568.img, and then an ext4 file system image will be created.

Type in terminal:

sudo mkfs.ext4 -F -L linuxroot rk3568.img

As shown below:

  • sudo mkfs.ext4 : It is a linux command, which is used to format the disk device with Ext4.
  • -F : Indicates forced formatting.
  • -L : Set the volume label. Here is linuxroot
  • rk356.img : is the device.

Then enter the following command in the terminal:

mkdir tmpfs

Create a tmpfsfile. Among them, mkdir is a linux command used to create a directory; tmpfs is a directory name (customizable).

Then use the following command:

sudo mount rk3568.img tempfs/

Mount the rk3568.img file system to tmpfs.

Use the following command to copy the directories and files in the rootfs directory to the tmpfs directory:

sudo cp -rfp rootfs/* tmpfs/

When complete, unmount the filesystem with the following command:

sudo umount tmpfs/

Next use:

sudo e2fsck -p -f rk3568.img

Check the correctness of the ext4 file system. In the above command:

  • -f: Indicates that the correctness is checked forcibly even if the file system has no signs of errors.
  • -p: Indicates that the file system will be automatically repaired without asking the user's opinion.

Then use:

sudo resize2fs -M rk3568.img

Adjust the size of the file system, as shown in the following figure:

Through the above steps, the root file system is completely packaged into an img image file.

After the image file is packaged, the img image file can be downloaded to the storage medium through the programming tool. For example, this article is the root file system of the packaged Rockchip rk3568 processor platform, you can use the official download tool to download it:

Guess you like

Origin blog.csdn.net/iriczhao/article/details/127078414