3

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:

  1. Copy the bin, sbin, lib etc... into my new /tmp_root/ folder
  2. Mount/bind /proc, /sys, dev, run into /tmp_root/
  3. Call pivot_root
  4. Unmount everything from oldroot
  5. Kill of all processes that are related to oldroot/dev
  6. 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

1

INFO:

switch_root

switch_root moves already mounted /proc, /dev, /sys and /run to newroot and makes newroot the new root filesystem and starts init process.

init

The program init is the process with process ID 1. It is responsible for initializing the system in the required way. init is started directly by the kernel and resists signal 9, which normally kills processes. All other programs are either started directly by init or by one of its child processes.

Any programs, daemons, modules (?) started before switch_root is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.

You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.


"I want to be able to format that device and write a new rootfs to it"

Assume you have the new rootfs built already and ready to "install".

After you format how will you boot into this? Is this why you want to switch_root because it is already booted?

If yes switch_root may not be the tool you need.

Other tools that may allow you to format and copy your new rootfs.

  • Your boot loader.
  • A live linux distro installed on a bootable USB.
  • A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.
  • Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.
  • Network boot ether PXE or even a NFS.

Does this help at all?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.