kexec – using kexec system call to update live UBIFS root filesystem

I use UBIFS as main general purpose MTD file system in my embedded projects. When customer is updating our embedded device, he updates root filesystem completely. I believe it is more error prone than updating single applications or files. It is not possible to update live attached UBI volume, so if you wish to update flash contents it is mandatory umount root filesystem and detach the UBI volume.

There are few ways to do it:

  1. reboot the device and start it from different (minimal) flash partition as root filesystem (you have to maintain two root filesystems, the real one, and the minimal one used for update),
  2. use pivot_root/chroot pair to switch to different rootfs and then umount main root filesystem (unfortunately, it did not worked for me),
  3. create minimal root filesystem on the fly, and boot into it using kexec kernel system call.

The third way is my favorite, basic steps to perform UBI file system update are as follow:

  1. Create file for temporary file system.
  2. Mount the temporary file as loop device.
  3. Create required directory structure.
  4. Copy all required files (busybox, libraries, kernel modules, modutils, ubiformat, etc) to the mounted root filesystem.
  5. Copy your update script, or update application into the mounted directory
  6. Umount the temporary file.
  7. Use kexec to boot with the kernel, use temporary file as initial ramdisk, execute your update script, or update application as the init process (use “init=/your_update_script.sh” kernel command line parameter).
  8. After “warm reboot” your UBI volume is not attached and you can update it with ubiformat.

I suggest attaching update script to your update package, as it is possible to customize tasks inside this script and it is possible to do whatever you want during this script execution.

Advertisements
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s