Reputation: 1388
How to replace the contents of rootfs partition while the device is booted up?
I am using pine64 (1GB) with stripped debian version and struck in writing a factory reset script which will replace all files in the rootfs partition while the device is running? resident restore file could be tar or img file.
I have already tried two approaches
sudo dd if=pine-debian.img skip=*start of rootfs partition* seek=*start of rootfs partition* of=/dev/mmcblk0
sudo tar -C / -zxvf pine-debian.tar.gz
After both the approaches, the system can recognize any command, not even ls. Any help will be appreciated about how to solve this. how to replace fs content while the device is running?
Upvotes: 1
Views: 761
Reputation: 3494
Ideally, you should have two partitions each with a copy of the rootfs. You can write the partition that is currently not in use with dd
, and then update the bootloader configuration to point to the just written partition as the root. swupdate
supports such a dual-bank scenario, but it only has native support for U-Boot; if you use a different bootloader, you'll have to add a script to perform the swap.
If you really need to overwrite in-place, directly overwriting the partition is not possible because that filesystem is currently in use. Untarring will also fail because some files are currently in use - in particular libc. You could try to add the --unlink-first
option to the untar command, but I'm not sure if that works.
Two other options:
kexec --initrd=...
to boot into the in-RAM root filesystem.Upvotes: 1