jefby
jefby

Reputation: 375

what's the difference between switch_root and run_init?

What's the difference between switch_root and run_init, besides switch_root being made by busybox while run_init is from klibc?

Thanks very much

Upvotes: 2

Views: 1142

Answers (1)

Ulfalizer
Ulfalizer

Reputation: 4762

They both perform exactly the same function, which is to switch to the "real" root and execv(3) the "real" init(8) program from an initramfs. They both assume that the filesystem that should become the root has been mounted on some directory, which they take as an argument.

(An initramfs is a (usually) temporary in-memory filesystem loaded by the bootloader. Its purpose is to do any setup that might be required before mounting the real root and switching to the real init program.)

Recent source code for run-init can be found here. run_init() is the entry point (called from run-init.c, which parses the arguments).

Recent source code for switch_root can be found here. switch_root_main() is the entry point.

The code is short for both implementations (though a bit tricky), which makes it easy to compare them by eye. The only difference seems to be that they perform slightly different sanity checks, and that recent versions of run-init have an extra option to drop selected capabilities(7) before execv()'ing the new init.

Upvotes: 2

Related Questions