从外部操作系统分区使用 bash 环境

kal*_*gne 4 shell chroot

我有一个外部分区 ,/dev/sda其中包含一个 Ubuntu 操作系统。根位于/dev/sda2.

我想从这个操作系统分区访问命令。

我尝试执行以下步骤:

我首先从 Linux U 盘启动(实际上是 Arch Linux)。然后我将目标分区挂载到/mnt我的安装映像的文件夹中:

$ mount /dev/sda2 /mnt
Run Code Online (Sandbox Code Playgroud)

我使用 chroot 来设置根文件夹:

$ chroot /mnt
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

chroot: failed to run command `/usr/bin/zsh` : No such file or directory
Run Code Online (Sandbox Code Playgroud)

到底是怎么回事?也许我被 chroot 的手册页误导了:

chroot - run command or interactive shell with special root directory

我首先使用了正确的方法吗?

phe*_*mer 7

您没有指定要在 chroot 中运行的内容。所以它试图启动一个shell。它也不知道应该启动哪个 shell,所以它尝试使用$SHELL环境变量中的那个,显然是/usr/bin/zsh. 这个 shell 显然不存在于你的 chroot 中。

告诉chroot你想运行什么:

chroot /mnt /bin/bash
Run Code Online (Sandbox Code Playgroud)

 

根据您尝试执行的操作,您可能还会遇到其他问题,除非您mount -o bind有来自主机的几项内容,例如/dev, /dev/pts, /sys, & /proc