Replacing a running Linux root filesystem

8,863

See this Stack Exchange answer. The accepted answer points to this link, which explains how to use pivot_root to create a temporary in-memory root filesystem, which enables you to change, resize, replace or in any other way mess with your root filesystem without reboot.

Share:
8,863

Related videos on Youtube

hygri
Author by

hygri

Embedded Linux, IP / Cisco Networks, Synthetic Chemistry

Updated on September 18, 2022

Comments

  • hygri
    hygri almost 2 years

    I'm trying to come up with a bash-scriptable method of replacing the root filesystem on a running PC. The system uses a MBR partitioned disk with an ext4 rootfs and a swap partition, unfortunately it doesn't use LVM / BTRFS or anything useful like that. It's running a minimal Debian distro using grub / kernel & initrd / systemd.

    There is no physical access to the PC in question - it is running some kiosk software, with which a proprietary tool can be used to push a tarball containing binaries and an update shell script to the PC. My plan is to use this update system to try to replace the rootfs.

    My ideas basically boil down to the following:

    • Replace the initrd with a custom version which does not switch_root to the real rootfs but instead replaces it (probably using dd to write a new image), then reboot to the new system

    • (Somehow!) switch_root from the live system to some sort of temporary filesystem, then do the above dd & reboot

    • As above, but pivot_root the init process to a new, temporary fs and do the above, or something like it...

    I'm not familiar with pivot_root and switch_root functionality and am currently having a play - i'm sure this has been done before, but I've searched and not found a solution!