0

I'm working on an embedded device with an arm cortex A9. The kernel version is 4.16.0 and is generated by buildroot 2018.05. The storage memory is an mmc with several partition. U-boot reads the uImage in one partition and starts the kernel. The filesystem is included in the kernel image and is loaded at startup in an initramfs (config : BR2_TARGET_ROOTFS_INITRAMFS).

I want to use an overlayfs to use a folder (in the mmc) as a 'user' filesystem, mounted onto /.

I already tried succesfully to overlay /etc with a directory named /data/etc by adding these lines to the /etc/fstab :

/dev/mmcblk0p1 /data auto defaults 1 2
overlay /etc overlay x-systemd.requires=/data,lowerdir=/etc,upperdir=/data/etc,workdir=/data/work/etc 0 0

This is working, but the overlay is mounted after systemd has already launch its sevices. So the network configuration for example is the one in the uImage and not the one in my user filesystem. I'd like to mount the overlay before lauching systemd, just after / is mounted.

I have understood that at startup, the system creates a first memory space in ram and then extracts the cpio image in it. Then / is mounted there and the system launches the first program : systemd:/sbin/init with the PID 1. Is my understanding right ?

I have read lots of article and Q&A website but I still do not understand where I have to make the changes to perform my overlay at boot time. What are the files that contains the mount / operation ?

  • There is already such a system for intel architecture PCs when you run persistent live systems from systems made directly from an iso file. For example in Ubuntu you can create a casper-rw file or partition for the whole system but if you create a home-rw file or partition /home will be mounted on that partition. I know that you are working with the arm architecture, and Ubuntu does not provide iso files for that architecture, only direct images of the installed system. But you may be helped by analyzing how the persistent live system works (the source code of the package casper). – sudodus Nov 29 '19 at 18:35
  • Thanks for the tip. I'll see how it works. I also have found several articles about raspberry devices but at every time, the boot stage is different than mine and I cannot found where is the code I must modify. – grorel Dec 2 '19 at 10:33
0

This boot time operation is in initramfs. You need to add a script to your initramfs/scripts, probably init-bottom to (re)mount the filesystems as desired, then generate a new initramfs package.

The script executes before your filesystem init, at the end of the kernel init process. The reason it is confusing is because the code for the setup is nowhere directly on the filesystem, it is in your initramfs file.

|improve this answer|||||
-1

You need to figure out the actual location of your overlay, and the enter it to the file

/etc/fstab

in the way you would enter it in a running system.

One caveat: You need to add the file into the buildroot overlay-filesystem, so that when building the rootfs, buildroot includes the modified filesystem-table.

As an example, lets assume, you want to overlay /dev/mmc0p0 over /home, you would do these steps, using MYCOMP and MYBOARD as your companys and your boards name:

- create a filesystem structure in a seperate directory, as 
  specified in the buildroot manual chapter 9.1 "Recommended 
  directory structure", presumably under /tmp/br_ext
- in this directory you add board/MYCOMP/MYBOARD/rottfs_overlay/etc/fstab 
  and fill it with this information:

board/MYCOMP/MYBOARD/rottfs_overlay/etc/fstab:

  /dev/mmc0p0 /home ext4 defaults 0 1

Then you build the filesystem in the buildroot tree with:

make BR2_EXTERNAL=/tmp/br_ext menuconfig
make

After rebooting the new filesystem, the overlay should be in place.

|improve this answer|||||
  • Your answer doesn't fit my question. I see the misunderstanding and I'll add some explanations to be more specific and prevent this . You're dealing with overlay while creating the uImage. I need an overlay in the product to keep the "manufacturer" filesystem intact, and overlay a "user" filesystem onto it. – grorel Nov 29 '19 at 13:19
  • You will have two options: 1.) find out if the vendor provides some kind of 'hook' to attach scripts from within the boot process. 2.) use som kernel parameter to mount an overlay at boot time. i do not know of the latter. – gerhard d. Dec 13 '19 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.