Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

21.6.2. 运行 virt-rescue

在 guest 虚拟机中使用 virt-rescue 之前,请确保 guest 虚拟机未在运行,否则将发生磁盘损坏。当您确定客户机虚拟机未上线时,请输入:
$ virt-rescue -d GuestName
(其中 GuestName 是 libvirt 已知的 guest 名称),或者:
$ virt-rescue -a /path/to/disk/image
(其中,路径可以是任意文件,任意逻辑卷、LUN 等)包含客户机虚拟机磁盘。
您会看到过去滚动的输出,因为 virt-rescue 引导 rescue 虚拟机。最后会显示:
Welcome to virt-rescue, the libguestfs rescue shell.

 Note: The contents of / are the rescue appliance.
 You have to mount the guest virtual machine's partitions under /sysroot
 before you can examine them.

 bash: cannot set terminal process group (-1): Inappropriate ioctl for device
 bash: no job control in this shell
 ><rescue>
此处的 shell 提示符是普通的 bash shell,提供了一定程度的普通 Red Hat Enterprise Linux 命令集。例如,您可以输入:
><rescue> fdisk -l /dev/vda
以上命令将列出磁盘分区。要挂载文件系统,建议您将其挂载到 /sysroot 下,它是救援计算机中的空目录,以便用户挂载您想要的任何内容。请注意,/ 下的文件 是救援虚拟机本身中的文件:
><rescue> mount /dev/vda1 /sysroot/
EXT4-fs (vda1): mounted filesystem with ordered data mode. Opts: (null)
><rescue> ls -l /sysroot/grub/
 total 324
 -rw-r--r--. 1 root root     63 Sep 16 18:14 device.map
 -rw-r--r--. 1 root root  13200 Sep 16 18:14 e2fs_stage1_5
 -rw-r--r--. 1 root root  12512 Sep 16 18:14 fat_stage1_5
 -rw-r--r--. 1 root root  11744 Sep 16 18:14 ffs_stage1_5
 -rw-------. 1 root root   1503 Oct 15 11:19 grub.conf
 [...]
完成对客户机虚拟机进行修复后,通过输入 exitCtrl+d 退出 shell。
virt-rescue 具有很多命令行选项。最常用的选项有:
  • --ro:在 guest 虚拟机上以只读模式运行。不会保存任何更改。您可以使用它来试验 guest 虚拟机。当您从 shell 退出后,所有更改将被丢弃。
  • --network:启用来自 rescue shell 的网络访问。例如,如果您需要将 RPM 或其他文件下载到客户机虚拟机中,可使用此示例。