Scroll to navigation

virt-rescue(1) Virtualization Support virt-rescue(1)

名前

virt-rescue - 仮想マシンにおいてレスキューシェルを実行します

書式

 virt-rescue [--options] -d domname

 virt-rescue [--options] -a disk.img [-a disk.img ...] [-i]

古い形式:

 virt-rescue [--options] domname

 virt-rescue [--options] disk.img [disk.img ...]

説明

virt-rescue is like a Rescue CD, but for virtual machines, and without the need for a CD. virt-rescue gives you a rescue shell and some simple recovery tools which you can use to examine or rescue a virtual machine or disk image.

You can run virt-rescue on any virtual machine known to libvirt, or directly on disk image(s):

 virt-rescue -d GuestName -i

 virt-rescue --ro -a /path/to/disk.img -i

 virt-rescue -a /dev/sdc

For live VMs you must use the --ro option.

When you run virt-rescue on a virtual machine or disk image, you are placed in an interactive bash shell where you can use many ordinary Linux commands. What you see in / (/bin, /lib etc) is the rescue appliance. You must mount the virtual machine’s filesystems. There is an empty directory called /sysroot where you can mount filesystems.

To automatically mount the virtual machine’s filesystems under /sysroot use the -i option. This uses libguestfs inspection to find the filesystems and mount them in the right place. You can also mount filesystems individually using the -m option.

Another way is to list the logical volumes (with lvs(8)) and partitions (with parted(8)) and mount them by hand:

 ><rescue> lvs
 LV      VG        Attr   LSize   Origin Snap%  Move Log Copy%  Convert
 lv_root vg_f15x32 -wi-a-   8.83G
 lv_swap vg_f15x32 -wi-a- 992.00M
 ><rescue> mount /dev/vg_f15x32/lv_root /sysroot
 ><rescue> mount /dev/vda1 /sysroot/boot
 ><rescue> ls /sysroot

利用可能なファイルシステムを一覧表示するためのもう 1 つのコマンドは virt-filesystems(1) です。

Linux 仮想マシンにおいてコマンド(たとえば、grub)を実行するには、まず /sysroot ディレクトリーの中に chroot する必要があります:

 ><rescue> chroot /sysroot

注記

Virt-rescue can be used on any disk image file or device, not just a virtual machine. For example you can use it on a blank file if you want to partition that file (although we would recommend using guestfish(1) instead as it is more suitable for this purpose). You can even use virt-rescue on things like USB drives, SD cards and hard disks.

You can get virt-rescue to give you scratch disk(s) to play with. This is useful for testing out Linux utilities (see --scratch).

Virt-rescue does not require root. You only need to run it as root if you need root to open the disk image.

This tool is just designed for quick interactive hacking on a virtual machine. For more structured access to a virtual machine disk image, you should use guestfs(3). To get a structured shell that you can use to make scripted changes to guests, use guestfish(1).

オプション

--help
簡単なヘルプを表示します。
-a FILE
--add FILE
Add "FILE" which should be a disk image from a virtual machine. If the virtual machine has multiple block devices, you must supply all of them with separate -a options.

ディスクイメージの形式は自動検知されます。 これを上書きして強制的に特定の形式を使用する場合、 --format=.. オプションを使用します。

-a URI
--add URI
リモートディスクを追加します。 "リモートストレージの追加" in guestfish(1) 参照。
--append KERNELOPTS
レスキューカーネルに追加オプションを渡します。
-c URI
--connect URI
libvirt を使用していると、指定された URI に接続します。 省略すると、デフォルトの libvirt ハイパーバイザーに接続します。

ゲストのブロックデバイスを直接指定していると((-a))、libvirt は何も使用されません。

-d guest
--domain guest
名前付きの libvirt 仮想マシンからすべてのディスクを追加します。 名前の代わりに仮想マシンの UUID を使用できます。
-e none
Disable the escape key.
-e KEY
Set the escape key to the given key sequence. The default is "^]". To specify the escape key you can use:
"^x"
Control key + "x" key.
"none"
-e none means there is no escape key, escapes are disabled.

See "ESCAPE KEY" below for further information.

--format=raw|qcow2|..
--format
-a オプションは標準状態でディスクイメージの形式を自動検知します。 これを使用することにより、コマンドラインで後続の -a オプションのディスク形式を強制的に指定できます。 引数なしで --format を使用することにより、 後続の -a オプションに対して自動検知に戻せます。

例:

 virt-rescue --format=raw -a disk.img
    

forces raw format (no auto-detection) for disk.img.

 virt-rescue --format=raw -a disk.img --format -a another.img
    

forces raw format (no auto-detection) for disk.img and reverts to auto-detection for another.img.

仮想マシンのディスクイメージが信頼できない raw 形式である場合、 ディスク形式を指定するためにこのオプションを使用すべきです。 これにより、悪意のある仮想マシンにより起こり得る セキュリティ問題を回避できます (CVE-2010-3851)。

-i
--inspector
virt-inspector(1) コードを使用すると、 オペレーティングシステムを判定するためにディスクを検査します。 また、実際の仮想マシンにマウントすることと同じように ファイルシステムをマウントします。

The filesystems are mounted on /sysroot in the rescue environment.

--memsize MB
Change the amount of memory allocated to the rescue system. The default is set by libguestfs and is small but adequate for running system tools. The occasional program might need more memory. The parameter is specified in megabytes.
-m dev[:mountpoint[:options[:fstype]]]
--mount dev[:mountpoint[:options[:fstype]]]
Mount the named partition or logical volume on the given mountpoint in the guest (this has nothing to do with mountpoints in the host).

If the mountpoint is omitted, it defaults to /. You have to mount something on /.

The filesystems are mounted under /sysroot in the rescue environment.

マウントパラメーターの三番目の (ほとんど使用されない) 項目は、 バックエンドのファイルシステムをマウントするために使用される マウントオプションの一覧です。 これが指定されていない場合、 マウントオプションは空文字列または "ro" (--ro フラグが使用されている場合) になります。

 -m /dev/sda1:/:acl,user_xattr
    

パラメーターの四番目の項目は使用するファイルシステムドライバー ("ext3""ntfs" など) です。 これはほとんど必要ありません。 しかし、複数のドライバーがファイルシステムに対して有効である場合 (例: "ext2""ext3")、 または libguestfs がファイルシステムを誤検知している場合、 これは有用です。

--network
仮想マシンにおいて QEMU のユーザーモードのネットワークを有効にします。 "NETWORK" 参照。
-r
--ro
イメージを読み込み専用で開きます。

ディスクイメージまたは仮想マシンが使用中の場合、 必ずこのオプションを使用する必要があります。 また、ディスクへの書き込みアクセスが不要な場合、 このオプションが一般的に推奨されます。

"OPENING DISKS FOR READ AND WRITE" in guestfish(1) 参照。

--scratch
--scratch=N
--scratch オプションにより、大きなスクラッチディスクをレスキュー・アプライアンスに追加できます。--scratch=N により、"N" 個のスクラッチディスクを追加できます。virt-rescue が終了するとき、スクラッチディスクは自動的に削除されます。

-a, -d および --scratch オプションは混在できます。スクラッチディスクは、これらがコマンドラインに現れる順番で、アプライアンスに追加されます。

--selinux
This option is provided for backwards compatibility and does nothing.
--smp N
レスキューアプライアンスにおいて N ≥ 2 仮想 CPU を有効にします。
--suggest
This option was used in older versions of virt-rescue to suggest what commands you could use to mount filesystems under /sysroot. For the current version of virt-rescue, it is easier to use the -i option instead.

このオプションは --ro を意味します。仮想マシンが起動していたり、他の virt-rescue を実行しているときでも安全です。

-v
--verbose
デバッグ用の冗長なメッセージを有効にします。
-V
--version
バージョン番号を表示して、終了します。
-w
--rw
ディスクが追加され、読み書き可能でマウントされるよう、 -a, -d, -m オプションを変更します。

"OPENING DISKS FOR READ AND WRITE" in guestfish(1) 参照。

-x
libguestfs API 呼び出しのトレースを有効にします。

旧形式のコマンドライン引数

Previous versions of virt-rescue allowed you to write either:

 virt-rescue disk.img [disk.img ...]

または

 virt-rescue guestname

whereas in this version you should use -a or -d respectively to avoid the confusing case where a disk image might have the same name as a guest.

互換性のため古い形式がまだサポートされています。

ネットワーク

Adding the --network option enables QEMU user networking in the rescue appliance. There are some differences between user networking and ordinary networking:
ping does not work
Because the ICMP ECHO_REQUEST protocol generally requires root in order to send the ping packets, and because virt-rescue must be able to run as non-root, QEMU user networking is not able to emulate the ping(8) command. The ping command will appear to resolve addresses but will not be able to send or receive any packets. This does not mean that the network is not working.
cannot receive connections
QEMU user networking cannot receive incoming connections.
TCP 接続の作成法
The virt-rescue appliance needs to be small and so does not include many network tools. In particular there is no telnet(1) command. You can make TCP connections from the shell using the magical /dev/tcp/<hostname>/<port> syntax:

 exec 3<>/dev/tcp/redhat.com/80
 echo "GET /" >&3
 cat <&3
    

詳細は bash(1) 参照。

ESCAPE KEY

Virt-rescue supports various keyboard escape sequences which are entered by pressing "^]" (Control key + "]" key).

You can change the escape key using the -e option on the command line (see above), and you can disable escapes completely using -e none. The rest of this section assumes the default escape key.

The following escapes can be used:

"^] ?"
"^] h"
Prints a brief help text about escape sequences.
"^] i"
Prints brief libguestfs inspection information for the guest. This only works if you used -i on the virt-rescue command line.
"^] q"
"^] x"
Quits virt-rescue immediately.
"^] s"
Synchronize the filesystems (sync).
"^] u"
Unmounts all the filesystems, except for the root (appliance) filesystems.
"^] z"
Suspend virt-rescue (like pressing "^Z" except that it affects virt-rescue rather than the program inside the rescue shell).
"^] ^]"
Sends the literal character "^]" (ASCII 0x1d) through to the rescue shell.

CAPTURING CORE DUMPS

If you are testing a tool inside virt-rescue and the tool (not virt-rescue) segfaults, it can be tricky to capture the core dump outside virt-rescue for later analysis. This section describes one way to do this.
1.
Create a scratch disk for core dumps:

 truncate -s 4G /tmp/corefiles
 virt-format --partition=mbr --filesystem=ext2 -a /tmp/corefiles
 virt-filesystems -a /tmp/corefiles --all --long -h
    
2.
When starting virt-rescue, attach the core files disk last:

 virt-rescue --rw [-a ...] -a /tmp/corefiles
    

NB. If you use the --ro option, then virt-rescue will silently not write any core files to /tmp/corefiles.

3.
Inside virt-rescue, mount the core files disk. Note replace /dev/sdb1 with the last disk index. For example if the core files disk is the last of four disks, you would use /dev/sdd1.

 ><rescue> mkdir /tmp/mnt
 ><rescue> mount /dev/sdb1 /tmp/mnt
    
4.
Enable core dumps in the rescue kernel:

 ><rescue> echo '/tmp/mnt/core.%p' > /proc/sys/kernel/core_pattern
 ><rescue> ulimit -Hc unlimited
 ><rescue> ulimit -Sc unlimited
    
5.
Run the tool that caused the core dump. The core dump will be written to /tmp/mnt/core.PID.

 ><rescue> ls -l /tmp/mnt
 total 1628
 -rw------- 1 root root 1941504 Dec  7 13:13 core.130
 drwx------ 2 root root   16384 Dec  7 13:00 lost+found
    
6.
Before exiting virt-rescue, unmount (or at least sync) the disks:

 ><rescue> umount /tmp/mnt
 ><rescue> exit
    
7.
Outside virt-rescue, the core dump(s) can be removed from the disk using guestfish(1). For example:

 guestfish --ro -a /tmp/corefiles -m /dev/sda1
 ><fs> ll /
 ><fs> download /core.NNN /tmp/core.NNN
    

環境変数

Several environment variables affect virt-rescue. See "ENVIRONMENT VARIABLES" in guestfs(3) for the complete list.

ファイル

$XDG_CONFIG_HOME/libguestfs/libguestfs-tools.conf
$HOME/.libguestfs-tools.rc
$XDG_CONFIG_DIRS/libguestfs/libguestfs-tools.conf
/etc/libguestfs-tools.conf
This configuration file controls the default read-only or read-write mode (--ro or --rw).

See libguestfs-tools.conf(5).

関連項目

guestfs(3), guestfish(1), virt-cat(1), virt-edit(1), virt-filesystems(1), libguestfs-tools.conf(5), http://libguestfs.org/.

著者

Richard W.M. Jones http://people.redhat.com/~rjones/

COPYRIGHT

Copyright (C) 2009-2019 Red Hat Inc.

LICENSE

BUGS

To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools

To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools

When reporting a bug, please supply:

  • The version of libguestfs.
  • Where you got libguestfs (eg. which Linux distro, compiled from source, etc)
  • Describe the bug accurately and give a way to reproduce it.
  • Run libguestfs-test-tool(1) and paste the complete, unedited output into the bug report.
2019-02-07 libguestfs-1.40.2