I am running my rootfs on a flash device (MTD device with UBIFS) - Note: it's a bitbake system so its not full-blown ubuntu or anything.
I want to be able to format that device and write a new rootfs to it, and so I need to ubidetach
this device, which I can do, but in order to do that I have to kill off every process/shell/app, etc... that ever lived - i.e. a similar list to if you do:
fuser -vm /dev
.
So my attempt so far (that does work to a degree) is using pivot_root where I do the following:
- Copy the bin, sbin, lib etc... into my new /tmp_root/ folder
- Mount/bind /proc, /sys, dev, run into /tmp_root/
- Call pivot_root
- Unmount everything from oldroot
- Kill of all processes that are related to oldroot/dev
- unmount oldroot
This works ok - and at this point I can detatch the UBIFS an flash the MTD device. However I have had to kill off all the apps that are runnings - which is not very useful!
So, what I want to do is (at least as a trial) instead of pivot_root
do a switch_root
, or some such, and then I can run up all my apps AND (hopfully) flash the MTD device. Normally this is initramtfs
(or so I have read), but in my case I just want to do some testing and switch file system on an already running rootfs.
With the same /tmp_root
folder that I created I have tried:
exec switch_root /tmp_root /sbin/init
exec -c /dev/console switch_root /tmp_root /sbin/init
But I always get the same sort of result somthing like:
old root filesystem is not an initramfs: invalid argument
I am a bit stuck, is it even possible to completely switch the rootfs once the system is up and running?
note: running linux kernel 4.1.x