title: Flashing an internal SD card that is mounted as root
body: <p>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.</p>
  
  <p>My first thought was to unmount the root filesystem and use something to the effect of:</p>
  
  <pre><code>dd if=/mnt/flashdrive/update.img of=/dev/sdcard 
  </code></pre>
  
  <p>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.</p>
  
  <p>Of course, we could always use dd without unmounting root. This seems rather foolish, however. :P</p>
  
  <p>I was also thinking of modifying the system init script to perform this logic before the system actually mounts the root filesystem.</p>
  
  <p>Is there a correct/easy way to perform this type of update? I would imagine it has been done before.</p>
  
  <p>Thank you!</p>