• 0 Posts
  • 2 Comments
Joined 2 years ago
cake
Cake day: June 5th, 2023

help-circle

  • man 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.

    WARNING: switch_root removes recursively all files and directories on the current root filesystem.

    If you look at the source code, it uses mount(2) with the MS_MOVE flag to move the /proc, /dev, /sys, /run to the new root, then deletes all the files on the old root fs recursively, then MS_MOVE-mounts the new root over the old one. As the comment in the source code points out:

    /* Don’t try to unmount the old “/”, there’s no way to do it. */

    This is presumably why it deletes the files on the initrd, because it is a ram disk and the files would be eating up memory if left there.