Red Hat Training

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

16.6.2. 运行 virt-rescue

在您对客户机虚拟机使用 virt-rescue 之前,请确保 guest 虚拟机没有运行,否则将发生磁盘损坏。确定 guest 虚拟机未处于活动状态时,请输入:
virt-rescue GuestName
(其中 GuestName 是 libvirt 已知的客户端名称),或:
virt-rescue /path/to/disk/image
(其中该路径可以是任意文件、任何逻辑卷、LUN 等等),其中包含客户机虚拟机磁盘。
您将首先看到输出滚动,因为 virt-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 虚拟机本身的文件:
><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 虚拟机上以只读模式确定。不会保存任何更改。您可以使用它来试验客户端虚拟机。从 shell 退出后,所有更改将被丢弃。
  • --network :启用 rescue shell 中的网络访问。如果您需要将 RPM 或其他文件下载到客户端虚拟机,请使用它。