Upgrade libguestfs to clean-up OpenStack Image

當我們在製作 OpenStack Image 的時候,最後需要把 Image 做 Cleanup 的動作,而此時會需要使用到 libguestfs,此篇文章紀錄在安裝 libguestfs 時碰到的問題,與如何從 Source Code compile and install。

文章當中所使用的環境是 Ubuntu 14.04.5 LTS x64,如果要安裝 libguestfs 通常都是使用 apt 去安裝。

但是 apt-get install libguestfs 當中我們所需要使用到的 virt-sysprepvirt-sysprep 1.24.5,這個版本會碰到 這個問題

sysprep operation failed: exception: Guestfs.Error(“vgchange_uuid_all: Volume group has active logical volumes”)

而這個問題已經在 libguestfs 大於 1.27.36 的版本修復了。

This issue is fixed with
https://github.com/libguestfs/libguestfs/commit/c004e4648d2091eb217026b15eed7e041557b635
which is in libguestfs >= 1.27.36.

為了解決這個問題,我後來決定從 Source Code 去編譯 libguestfs

Build from Source Code Step

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Get Source Code from http://download.libguestfs.org/
wget http://download.libguestfs.org/1.36-stable/libguestfs-1.36.5.tar.gz
# Get pre-compiled appliance from http://download.libguestfs.org/binaries/appliance/
wget http://download.libguestfs.org/binaries/appliance/appliance-1.36.1.tar.xz

# untar appliance into /usr/local/lib/guestfs/appliance or where you want
tar xvf appliance-1.36.1.tar.xz
mkdir /usr/local/lib/guestfs
mv appliance /usr/local/lib/guestfs

# Install build dependencies
sudo apt-get build-dep libguestfs
# uncompress install package
tar zxvf libguestfs-1.36.5.tar.gz
cd libguestfs-1.36.5
./configure --disable-appliance --disable-daemon
make

這樣子就已經安裝好了,接下來只需要執行,需要注意的是執行方式,根據官方的說明:

libguestfs-faq said:

Don’t run make install! Use the ./run script instead (see README).

libguestfs-building said:

The ./run script adds every libguestfs binary to the $PATH, so the above examples run guestfish and virt-inspector from the build directory (not the globally installed guestfish if there is one).

因為我們的系統已經存在舊版的 libguestfs,若執行會發生版本衝突:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
./virt-sysprep -d trusty
[ 0.0] Examining the guest ...
virt-sysprep: error: libguestfs error: add_domain: unknown option in
guestfs_add_domain_argv->bitmask (this can happen if a program is compiled
against a newer version of libguestfs, then dynamically linked to an older
version)

If reporting bugs, run virt-sysprep with debugging enabled and include the
complete output:

virt-sysprep -v -x [...]</pre>


因此我們需要使用 `./run.sh` 去執行 `libguestfs`,並且記得把 `appliance` 環境變數加進去:

<pre class="lang:sh decode:true " >export LIBGUESTFS_PATH=/usr/local/lib/guestfs/appliance
./run virt-sysprep -d trusty