Question

I am working on an embedded linux device that has an internal SD card. This device needs to be updatable without opening the device and taking out the SD card. The goal is to allow users to update their device with a USB flash drive. I would like to completely overwrite the internal SD card with a new SD card image.

My first thought was to unmount the root filesystem and use something to the effect of:

dd if=/mnt/flashdrive/update.img of=/dev/sdcard 

However, It appears difficult to actually unmount a root filesystem correctly, as processes like "login" and "systemd" are still using resources on root. As soon as you kill login, for example, the update script is killed as well.

Of course, we could always use dd without unmounting root. This seems rather foolish, however. :P

I was also thinking of modifying the system init script to perform this logic before the system actually mounts the root filesystem.

Is there a correct/easy way to perform this type of update? I would imagine it has been done before.

Thank you!

Était-ce utile?

La solution

Re-imaging a mounted file system doesn't sound like a good idea, even if the mount is read-only.

Consider:

  • Use a ramdisk (initialized from a compressed image) as your actual root filesystem, but perhaps have all but the most essential tools in file systems mounted beneath, which you can drop to upgrade. Most Linux implementations do this early in their boot process anyway before they mount the main disk filesystems: rebooting to do the upgrade may be an option.

  • SD cards are likely larger than you need anyway. Have two partitions and alternate between them each time you upgrade. Or have a maintenance partition which you boot into to perform upgrades/recovery.

  • Don't actually image the file system, but instead upgrade individual files.

Autres conseils

Try one of or both:

  1. Bring down to single user mode first: telinit 1

or/and

  1. Remount / as readonly: mount -o remount,ro /

before running the dd

Personally I would never do something as you do, but it is possible to do.

Your linux system does it every time it is booted. In fact, what happens is that your kernel initially mounts the initrd, loads all the modules and after that it calls pivot_root to mount the real / .

pivot_root is also a command that can be used from shell, you'd better run man 8 pivot_root but just to give you an idea, you can do something like this

mount /dev/hda1 /new-root
cd /new-root
pivot_root . old-root
exec chroot . sh <dev/console >dev/console 2>&1
umount /old-root

One last thing: this way of performing software upgrade is extremely weak. Please consider other solutions.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top