名前

guestmount - Mount a guest filesystem on the host using FUSE and libguestfs

書式

 guestmount [--options] -a disk.img -m device [--ro] mountpoint
 guestmount [--options] -a disk.img -i [--ro] mountpoint
 guestmount [--options] -d Guest -i [--ro] mountpoint

説明

The guestmount program can be used to mount virtual machine filesystems and other disk images on the host. It uses libguestfs for access to the guest filesystem, and FUSE (the "filesystem in userspace") to make it appear as a mountable device.
Along with other options, you have to give at least one device ( -a option) or libvirt domain ( -d option), and at least one mountpoint (-m option) or use the -i inspection option. How this works is better explained in the guestfish(1) manual page, or by looking at the examples below.
FUSE lets you mount filesystems as non-root. The mountpoint must be owned by you. The filesystem will not be visible to any other users unless you make configuration changes, see "NOTES" below.
To unmount the filesystem, use the guestunmount(1) command.

For a typical Windows guest which has its main filesystem on the first partition:
 guestmount -a windows.img -m /dev/sda1 --ro /mnt
For a typical Linux guest which has a /boot filesystem on the first partition, and the root filesystem on a logical volume:
 guestmount -a linux.img -m /dev/VG/LV -m /dev/sda1:/boot --ro /mnt
To get libguestfs to detect guest mountpoints for you:
 guestmount -a guest.img -i --ro /mnt
For a libvirt guest called "Guest" you could do:
 guestmount -d Guest -i --ro /mnt
If you don’t know what filesystems are contained in a guest or disk image, use virt-filesystems(1) first:
 virt-filesystems -d MyGuest
If you want to trace the libguestfs calls but without excessive debugging information, we recommend:
 guestmount [...] --trace /mnt
If you want to debug the program, we recommend:
 guestmount [...] --trace --verbose /mnt
To unmount the filesystem after using it:
 guestunmount /mnt

注記

他のユーザーは標準でファイルシステムを参照できません。

If you mount a filesystem as one user (eg. root), then other users will not be able to see it by default. The fix is to add the FUSE "allow_other" option when mounting:
 sudo guestmount [...] -o allow_other /mnt
and to enable this option in /etc/fuse.conf.

Enabling FUSE

On some distros, you may need to add yourself to a special group (eg. "fuse") before you can use any FUSE filesystem. This is necessary on Debian and derivatives.
On other distros, no special group is required. It is not necessary on Fedora or Red Hat Enterprise Linux.

fusermount エラー: "デバイスまたはリソースがビジーです"

You can see this error when another process on the system jumps into the mountpoint you have just created, holding it open and preventing you from unmounting it. The usual culprits are various GUI "indexing" programs.
The popular workaround for this problem is to retry the "fusermount -u" command a few times until it works ( guestunmount(1) does this for you). Unfortunately this isn't a reliable fix if (for example) the mounted filesystem is particularly large and the intruding program particularly persistent.
A proper fix is to use a private mountpoint by creating a new mount namespace using the Linux-specific clone(2)/unshare(2) flag "CLONE_NEWNS". Unfortunately at the moment this requires root and we would also probably need to add it as a feature to guestmount.

Race conditions possible when shutting down the connection

When guestunmount(1)/fusermount(1) exits, guestmount may still be running and cleaning up the mountpoint. The disk image will not be fully finalized.
This means that scripts like the following have a nasty race condition:
 guestmount -a disk.img -i /mnt
 # copy things into /mnt
 guestunmount /mnt
 # immediately try to use 'disk.img' ** UNSAFE **
The solution is to use the --pid-file option to write the guestmount PID to a file, then after guestunmount spin waiting for this PID to exit.
 guestmount -a disk.img -i --pid-file guestmount.pid /mnt
 
 # ...
 # ...
 
 # Save the PID of guestmount *before* calling guestunmount.
 pid="$(cat guestmount.pid)"
 
 # Unmount the filesystem.
 guestunmount /mnt
 
 timeout=10
 
 count=$timeout
 while kill -0 "$pid" 2>/dev/null && [ $count -gt 0 ]; do
     sleep 1
     ((count--))
 done
 if [ $count -eq 0 ]; then
     echo "$0: wait for guestmount to exit failed after $timeout seconds"
     exit 1
 fi
 
 # Now it is safe to use the disk image.
Note that if you use the "guestfs_mount_local" API directly (see "MOUNT LOCAL" in guestfs(3)) then it is much easier to write a safe, race-free program.

オプション

-a IMAGE
--add IMAGE
ブロックデバイスまたは仮想マシンイメージを追加します。 ディスクイメージの形式は自動検知されます。 これを上書きして強制的に特定の形式を使用する場合、 --format=.. オプションを使用します。
-a URI
--add URI
リモートディスクを追加します。 "リモートストレージの追加" in guestfish(1) 参照。
--blocksize=512
--blocksize=4096
--blocksize
This parameter sets the sector size of the disk image. It affects all explicitly added subsequent disks after this parameter. Using --blocksize with no argument switches the disk sector size to the default value which is usually 512 bytes. See also "guestfs_add_drive_opts" in guestfs(3).
-c URI
--connect URI
 I<-d> オプションと同時に使用するとき、 これは使用する libvirt URI を指定します。 標準状態で標準の libvirt 接続を使用します。
    
-d LIBVIRT-DOMAIN
--domain LIBVIRT-DOMAIN
名前付き libvirt 仮想マシンからディスクを追加します。 --ro オプションも使用されている場合、すべての libvirt 仮想マシンを使用できます。 しかしながら、書き込みモードでは、 停止状態の libvirt 仮想マシンのみ指定できます。 名前の代わりに仮想マシンの UUID を使用できます。
--dir-cache-timeout N
Set the readdir cache timeout to N seconds, the default being 60 seconds. The readdir cache [actually, there are several semi-independent caches] is populated after a readdir(2) call with the stat and extended attributes of the files in the directory, in anticipation that they will be requested soon after. There is also a different attribute cache implemented by FUSE (see the FUSE option -o attr_timeout), but the FUSE cache does not anticipate future requests, only cache existing ones.
--echo-keys
キーやパスフレーズを入力するとき、通常 guestfish はエコーを無効化します。 そのため、入力内容を確認できません。 テンペスト攻撃の心配がなく、 部屋に誰も居なければ、 入力内容を確認するためにこのフラグを指定できます。
--fd=FD
Specify a pipe or eventfd file descriptor. When the mountpoint is ready to be used, guestmount writes a single byte to this file descriptor. This can be used in conjunction with --no-fork in order to run guestmount captive under another process.
--format=raw|qcow2|..
--format
-a オプションは標準状態でディスクイメージの形式を自動検知します。 これを使用することにより、コマンドラインで後続の -a オプションのディスク形式を強制的に指定できます。 引数なしで --format を使用することにより、 後続の -a オプションに対して自動検知に戻せます。 仮想マシンのディスクイメージが信頼できない raw 形式である場合、 ディスク形式を指定するためにこのオプションを使用すべきです。 これにより、悪意のある仮想マシンにより起こり得る セキュリティ問題を回避できます (CVE-2010-3851)。 " guestfs(3)/guestfs_add_drive_opts" 参照。
--fuse-help
Display help on special FUSE options (see -o below).
--help
簡単なヘルプを表示して、終了します。
-i
--inspector
virt-inspector(1) コードを使用すると、 オペレーティングシステムを判定するためにディスクを検査します。 また、実際の仮想マシンにマウントすることと同じように ファイルシステムをマウントします。
--key SELECTOR
Specify a key for LUKS, to automatically open a LUKS device when using the inspection. "ID" can be either the libguestfs device name, or the UUID of the LUKS device.
--key "ID":key:KEY_STRING
Use the specified "KEY_STRING" as passphrase.
--key "ID":file:FILENAME
Read the passphrase from FILENAME.
--key "ID":clevis
Attempt passphrase-less unlocking for "ID" with Clevis, over the network. Please refer to "ENCRYPTED DISKS" in guestfs(3) for more information on network-bound disk encryption (NBDE). Note that if any such option is present on the command line, QEMU user networking will be automatically enabled for the libguestfs appliance.
--keys-from-stdin
Read key or passphrase parameters from stdin. The default is to try to read passphrases from the user by opening /dev/tty. If there are multiple encrypted devices then you may need to supply multiple keys on stdin, one per line.
-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 /. マウントパラメーターの三番目の (ほとんど使用されない) 項目は、 バックエンドのファイルシステムをマウントするために使用される マウントオプションの一覧です。 これが指定されていない場合、 マウントオプションは空文字列または "ro" ( --ro フラグが使用されている場合) になります。
 -m /dev/sda1:/:acl,user_xattr
    
パラメーターの四番目の項目は使用するファイルシステムドライバー ("ext3" や "ntfs" など) です。 これはほとんど必要ありません。 しかし、複数のドライバーがファイルシステムに対して有効である場合 (例: "ext2" と "ext3")、 または libguestfs がファイルシステムを誤検知している場合、 これは有用です。
--no-fork
Don’t daemonize (or fork into the background).
-n
--no-sync
By default, we attempt to sync the guest disk when the FUSE mountpoint is unmounted. If you specify this option, then we don't attempt to sync the disk. See the discussion of autosync in the guestfs(3) manpage.
-o OPTION
--option OPTION
追加オプションを FUSE に渡します。 To get a list of all the extra options supported by FUSE, use the command below. Note that only the FUSE -o options can be passed, and only some of them are a good idea.
 guestmount --fuse-help
    
Some potentially useful FUSE options:
-o allow_other
Allow other users to see the filesystem. This option has no effect unless you enable it globally in /etc/fuse.conf.
-o attr_timeout=N
Enable attribute caching by FUSE, and set the timeout to N seconds.
-o kernel_cache
Allow the kernel to cache files (reduces the number of reads that have to go through the guestfs(3) API). This is generally a good idea if you can afford the extra memory usage.
-o uid=N -o gid=N
Use these options to map all UIDs and GIDs inside the guest filesystem to the chosen values.
-o use_ino
Preserve inode numbers from the underlying filesystem. Without this option, FUSE makes up its own inode numbers. The inode numbers you see in stat(2), "ls -i" etc aren't the inode numbers of the underlying filesystem. Note this option is potentially dangerous if the underlying filesystem consists of multiple mountpoints, as you may see duplicate inode numbers appearing through FUSE. Use of this option can confuse some software.
--pid-file FILENAME
"filename" に guestmount ワーカープロセスの PID を書き込みます。
-r
--ro
Add devices and mount everything read-only. Also disallow writes and make the disk appear read-only to FUSE. This is highly recommended if you are not going to edit the guest disk. If the guest is running and this option is not supplied, then there is a strong risk of disk corruption in the guest. We try to prevent this from happening, but it is not always possible. "OPENING DISKS FOR READ AND WRITE" in guestfish(1) 参照。
--selinux
This option is provided for backwards compatibility and does nothing.
-v
--verbose
libguestfs からの冗長なメッセージを有効にします。
-V
--version
プログラムのバージョンを表示して、終了します。
-w
--rw
ディスクが追加され、読み書き可能でマウントされるよう、 -a, -d, -m オプションを変更します。 "OPENING DISKS FOR READ AND WRITE" in guestfish(1) 参照。
-x
--trace
Trace libguestfs calls and entry into each FUSE function. This also stops the daemon from forking into the background (see --no-fork).

ファイル

$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).

終了ステータス

このプログラムは、成功すると 0 を、エラーがあると 0 以外を返します。

関連項目

guestunmount(1), fusermount(1), guestfish(1), virt-inspector(1), virt-cat(1), virt-edit(1), virt-tar(1), libguestfs-tools.conf(5), "MOUNT LOCAL" in guestfs(3), http://libguestfs.org/, http://fuse.sf.net/.

著者

Richard W.M. Jones ("rjones at redhat dot com") Copyright (C) 2009-2020 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.