YOUPI reflash system
Document writer <olivier.nicolas@insa-lyon.fr>
v1.6, 2022-11-17
The Linux Boot Process
initramfs stands for INITial RAM File System |
It is a compressed cpio archive, unlike initrd which is a compressed file system. (Extracts from: https://www.kernel.org/doc/html/latest/admin-guide/initrd.html)
In a nutshell:
When using initramfs, the system typically boots as follows:
|
![]() |
The Flashing Process itself - Short version.
For a hands-on explanation, see the add device page.
For this process, we actually customize the init process to, in short,
perform the following duties:
-
Get an IP address via dhcp.
-
nfs-mount the server directories associated to the type of device we want to flash.
-
Execute our flashing script, using the image specified for the specific device.
-
Reboot once the flashing process has ended, bypassing the last few steps of the process described previously.
Customizing the initramfs
Thus, for this system we need to create a custom initramfs for each type of device on our platform. It will need specific information in order to handle the device to be flashed.
In this section, the color code used is the following: |
Existing Directories Existing Files New device-type directories New device-type files Generated Directories Generated Files
Architecture
This is a simplified version of the setup for one device of type new-device-type. It doesn’t show all the useful files, only what is needed to explain the concept. More details are available here. |
reflash/initramfs/utils ├── minimal_dirs │ ├── __global__ │ │ ├── initramfs.d │ │ │ └── init │ │ └── make_initramfs.sh │ └── new-device-type │ └── initramfs.d │ └── config └── mk_boot_initramfs.sh
Considering the device is connected to the platform and its IP address being configured in your dnsmasq.conf to be 10.0.1.1, you will need to run the following command: |
~/reflash/initramfs/utils $ ./mk_boot_initramfs.sh 10.0.1.1 It will generate: reflash/initramfs/devices/new-device-type/
reflash/initramfs/devices/ └──new-device-type/ └── boot/ ├ initramfs └── ...
The boot directory will also contain the necessary files to boot the system (from the system’s current
boot directory).
In some cases (and it might be generalized to all types of devices),
the reflash/initramfs/utils/minimal_dirs/new-device-type/ folder will also contain a list of
the minimum files needed to boot the system in a file named bootfiles-list, in order no to copy the
entire content of the system’s boot folder.
The packing script
In reflash/initramfs/utils/ $ mk_boot_initramfs.sh It basically copies to the device the files needed to generate the initramfs. That is: the contents of: * minimal_dirs/__global__/ * minimal_dirs/new-device-type/ It includes: the lists of packages/binaries the init script will need when the initramfs is "booted", the device's configuration file and a few other utilities, as well as the init script itself. Then the __global__/make_initramfs.sh script is run on the target device to perform the following:
-
Install on the device all that will be needed inside the initramfs (packages, utilities, etc.).
-
Copy all the binaries, libraries and configuration files, and the init script in a temporary directory.
-
Copy what is needed from the /boot/ directory to perform the first boot into the temporary directory.
-
Pack this temporary directory into the final initramfs file.
-
Transfer the boot folder into reflash/initramfs/devices/new-device-type/
-
Cleanup what was used in this process.
The init script
This script is at the root of the initramfs and is first executed during the initramfs boot sequence.
It performs the following actions:
-
Make necessary directories.
-
Mount file systems.
-
Retrieve device-specific configuration information.
-
Perform device-specific duties when necessary.
-
Get it’s IP address through dhcp.
-
Mount server directories through nfs.
-
Run the script specified for the device (link from ~/reflash/devices/$device-type/$MAC/init-script.sh).
-
Reboot the system (with its newly installed image).