#Bash 的 switch_root 命令
switch_root [OPTION]... NEWROOT INIT [ARG...]
功能
切换到另一个文件系统作为挂载树的根目录。
switch_root将已挂载的/proc、/dev、/sys和/run移动到NEWROOT,并将NEWROOT设置为新的根文件系统,然后启动INIT进程
类型
可执行文件(/usr/sbin/switch_root),属于 util-linux。
参数
OPTIONS选项:-h,--help- 显示帮助-V,--version- 显示版本
NEWROOT- 新的根文件系统INIT- init 进程ARG-INIT的参数
#示例
$ sudo switch_root new_root /usr/lib/systemd/systemd --system --deserialize=78
#相关命令
| 命令 | 说明 |
|---|---|
| chroot | 执行命令时指定根路径 |
| pivot_root | 切换根文件系统(可恢复) |
#推荐阅读
#手册
SWITCH_ROOT(8) System Administration SWITCH_ROOT(8)
NAME
switch_root - switch to another filesystem as the root of the mount
tree
SYNOPSIS
switch_root [-hV]
switch_root newroot init [arg...]
DESCRIPTION
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.
OPTIONS
-h, --help
Display help text and exit.
-V, --version
Print version and exit.
EXIT STATUS
switch_root returns 1 on failure, it never returns on success.
NOTES
switch_root will fail to function if newroot is not the root of a
mount. If you want to switch root into a directory that does not meet
this requirement then you can first use a bind-mounting trick to turn
any directory into a mount point:
mount --bind $DIR $DIR
AUTHORS
Peter Jones <[email protected]>, Jeremy Katz <[email protected]>, Karel
Zak <[email protected]>
SEE ALSO
chroot(2), init(8), mkinitrd(8), mount(8)
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The switch_root command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-10-23 SWITCH_ROOT(8)