blob: 41f29da3254faa5f7498e506a84a9759cf33e155 [file] [log] [blame]
Eric Andersen6fd8c662001-02-13 20:04:30 +00001/* vi: set sw=4 ts=4: */
2/*
3 * pivot_root.c - Change root file system. Based on util-linux 2.10s
4 *
5 * busyboxed by Evin Robertson
Eric Andersend160a272001-02-24 19:17:07 +00006 * pivot_root syscall stubbed by Erik Andersen, so it will compile
Eric Andersenc7bda1c2004-03-15 08:29:22 +00007 * regardless of the kernel being used.
Bernhard Reutner-Fischerb1629b12006-05-19 19:29:19 +00008 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02009 * Licensed under GPLv2, see file LICENSE in this source tree.
Eric Andersen6fd8c662001-02-13 20:04:30 +000010 */
Denys Vlasenkodd898c92016-11-23 11:46:32 +010011//config:config PIVOT_ROOT
Denys Vlasenkob097a842018-12-28 03:20:17 +010012//config: bool "pivot_root (1.1 kb)"
Denys Vlasenkodd898c92016-11-23 11:46:32 +010013//config: default y
14//config: select PLATFORM_LINUX
15//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020016//config: The pivot_root utility swaps the mount points for the root filesystem
17//config: with some other mounted filesystem. This allows you to do all sorts
18//config: of wild and crazy things with your Linux system and is far more
19//config: powerful than 'chroot'.
Denys Vlasenkodd898c92016-11-23 11:46:32 +010020//config:
Denys Vlasenko72089cf2017-07-21 09:50:55 +020021//config: Note: This is for initrd in linux 2.4. Under initramfs (introduced
22//config: in linux 2.6) use switch_root instead.
Denys Vlasenkodd898c92016-11-23 11:46:32 +010023
Denys Vlasenkofdb92352017-08-05 01:51:12 +020024//applet:IF_PIVOT_ROOT(APPLET_NOFORK(pivot_root, pivot_root, BB_DIR_SBIN, BB_SUID_DROP, pivot_root))
Denys Vlasenkodd898c92016-11-23 11:46:32 +010025
26//kbuild:lib-$(CONFIG_PIVOT_ROOT) += pivot_root.o
Pere Orga5bc8c002011-04-11 03:29:49 +020027
28//usage:#define pivot_root_trivial_usage
29//usage: "NEW_ROOT PUT_OLD"
30//usage:#define pivot_root_full_usage "\n\n"
31//usage: "Move the current root file system to PUT_OLD and make NEW_ROOT\n"
32//usage: "the new root file system"
33
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000034#include "libbb.h"
Eric Andersen6fd8c662001-02-13 20:04:30 +000035
Denys Vlasenkofdb92352017-08-05 01:51:12 +020036extern int pivot_root(const char *new_root, const char *put_old);
Eric Andersen6fd8c662001-02-13 20:04:30 +000037
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000038int pivot_root_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Eric Andersen6fd8c662001-02-13 20:04:30 +000039int pivot_root_main(int argc, char **argv)
40{
Denis Vlasenko59839142006-09-10 18:26:51 +000041 if (argc != 3)
42 bb_show_usage();
Eric Andersen6fd8c662001-02-13 20:04:30 +000043
Denys Vlasenkofdb92352017-08-05 01:51:12 +020044 /* NOFORK applet. Hardly matters wrt performance, but code is trivial */
45
Denis Vlasenkof885c542007-02-06 00:35:36 +000046 if (pivot_root(argv[1], argv[2]) < 0) {
47 /* prints "pivot_root: <strerror text>" */
48 bb_perror_nomsg_and_die();
49 }
Eric Andersen6fd8c662001-02-13 20:04:30 +000050
Denis Vlasenko59839142006-09-10 18:26:51 +000051 return EXIT_SUCCESS;
Eric Andersen6fd8c662001-02-13 20:04:30 +000052}