From: Richard W.M. Jones
There are lots of possible improvements to this script, such as
-using qcow snapshots so that cloned VMs share storage with their
+using qcow2 snapshots so that cloned VMs share storage with their
"parent" preimages.
+For more information about cloning images using libvirt and libguestfs
+see Richard Jones's procedure for cloning a Fedora VM.
+'$b'.sh
'
- echo ''
- sed -e 's,&,\&,g' -e 's,<,\<,g' -e 's,>,\>,g' < $f
- echo '
'
+ echo 'Example output
'
echo ''
diff --git a/recipes/clone.html b/recipes/clone.html
index f87b4ad..7079f3f 100644
--- a/recipes/clone.html
+++ b/recipes/clone.html
@@ -12,6 +12,11 @@ with a new nameserver entry, and change
/etc/HOSTNAME
.
-Usage assumes that the VM has a separate /boot
-partition containing grub, which is usually the case. So
-for example:
-
-editgrub.sh broken-guest.img /dev/sda1 +editgrub.sh broken-guest.img+ +
+See also virt-edit. +
diff --git a/recipes/editgrub.sh b/recipes/editgrub.sh index 4cb8ee9..14a7861 100755 --- a/recipes/editgrub.sh +++ b/recipes/editgrub.sh @@ -1,3 +1,3 @@ #!/bin/sh - -guestfish -a "$1" -m "$2" vi /grub/grub.conf +guestfish -a "$1" -i edit /boot/grub/grub.conf diff --git a/recipes/export2tar.html b/recipes/export2tar.html index fd23add..9d9f2d4 100644 --- a/recipes/export2tar.html +++ b/recipes/export2tar.html @@ -12,3 +12,9 @@ export2tar.sh guest.img /dev/VolGroup00/LogVol00 /home home.tar.gz/dev/VolGroup00/LogVol00
is the partition or LV inside
the VM which contains the directory you want.
+
++See also virt-tar +and Richard +Jones's complete list of ways to upload and download files. +
diff --git a/recipes/export2tar.sh b/recipes/export2tar.sh index 41816da..fa79b3e 100755 --- a/recipes/export2tar.sh +++ b/recipes/export2tar.sh @@ -1,3 +1,3 @@ #!/bin/sh - -guestfish -a "$1" --ro -m "$2" tgz-out "$3" "$4" +guestfish --ro -a "$1" -m "$2" tgz-out "$3" "$4" diff --git a/recipes/iso2tar.html b/recipes/iso2tar.html index b72f3ba..b1fe0aa 100644 --- a/recipes/iso2tar.html +++ b/recipes/iso2tar.html @@ -9,3 +9,9 @@ Usage is very simple:iso2tar.sh cd.iso output.tar.gz+ +
+See also virt-tar +and Richard +Jones's complete list of ways to upload and download files. +
diff --git a/recipes/list-apps.example b/recipes/list-apps.example new file mode 100644 index 0000000..c37063c --- /dev/null +++ b/recipes/list-apps.example @@ -0,0 +1,29 @@ +$ list-apps.sh win7.img +[0] = { + app_name: Mozilla Firefox (3.6.12) + app_display_name: Mozilla Firefox (3.6.12) + app_epoch: 0 + app_version: 3.6.12 (en-GB) + app_release: + app_install_path: C:\Program Files\Mozilla Firefox + app_trans_path: + app_publisher: Mozilla + app_url: http://www.mozilla.com/en-GB/ + app_source_package: + app_summary: + app_description: Mozilla Firefox +} +[1] = { + app_name: VLC media player + app_display_name: VLC media player 1.1.5 + app_epoch: 0 + app_version: 1.1.5 + app_release: + app_install_path: C:\Program Files\VideoLAN\VLC + app_trans_path: + app_publisher: VideoLAN + app_url: http://www.videolan.org/ + app_source_package: + app_summary: + app_description: +} diff --git a/recipes/list-apps.html b/recipes/list-apps.html new file mode 100644 index 0000000..0a1c4b0 --- /dev/null +++ b/recipes/list-apps.html @@ -0,0 +1,9 @@ ++The command lists the applications (eg. RPMs, debs, Windows programs) +installed inside a virtual machine. It does this using the +inspection API. +
+ ++See also virt-inspector. +
diff --git a/recipes/list-apps.sh b/recipes/list-apps.sh new file mode 100755 index 0000000..f781a7d --- /dev/null +++ b/recipes/list-apps.sh @@ -0,0 +1,6 @@ +#!/bin/sh - + +eval "$(guestfish --ro -a "$1" --i --listen)" +root="$(guestfish --remote inspect-get-roots)" +guestfish --remote inspect-list-applications "$root" +guestfish --remote exit diff --git a/recipes/list-apps.title b/recipes/list-apps.title new file mode 100644 index 0000000..104ffe8 --- /dev/null +++ b/recipes/list-apps.title @@ -0,0 +1 @@ +List the apps (eg. RPMs) installed inside a virtual machine \ No newline at end of file diff --git a/recipes/list-files.html b/recipes/list-files.html new file mode 100644 index 0000000..c8f8c88 --- /dev/null +++ b/recipes/list-files.html @@ -0,0 +1,3 @@ ++List the files in a virtual machine. +
diff --git a/recipes/list-files.sh b/recipes/list-files.sh new file mode 100755 index 0000000..2f91f28 --- /dev/null +++ b/recipes/list-files.sh @@ -0,0 +1,5 @@ +#!/bin/sh - + +guestfish --ro -a "$1" -i find0 / - | + tr '\000' '\n' | + sort diff --git a/recipes/list-files.title b/recipes/list-files.title new file mode 100644 index 0000000..0e8c0d0 --- /dev/null +++ b/recipes/list-files.title @@ -0,0 +1 @@ +List the files and directories in a virtual machine diff --git a/recipes/product-name.example b/recipes/product-name.example new file mode 100644 index 0000000..55b77fe --- /dev/null +++ b/recipes/product-name.example @@ -0,0 +1,2 @@ +$ product-name.sh win.img +Windows 7 Enterprise diff --git a/recipes/product-name.html b/recipes/product-name.html new file mode 100644 index 0000000..509ada1 --- /dev/null +++ b/recipes/product-name.html @@ -0,0 +1,9 @@ ++Get the string which describes the operating system installed in a +virtual machine. This uses the +inspection API. +
+ ++See also virt-inspector. +
diff --git a/recipes/product-name.sh b/recipes/product-name.sh new file mode 100755 index 0000000..7dcc7da --- /dev/null +++ b/recipes/product-name.sh @@ -0,0 +1,6 @@ +#!/bin/sh - + +eval "$(guestfish --ro -a "$1" --i --listen)" +root="$(guestfish --remote inspect-get-roots)" +guestfish --remote inspect-get-product-name "$root" +guestfish --remote exit diff --git a/recipes/product-name.title b/recipes/product-name.title new file mode 100644 index 0000000..ed64090 --- /dev/null +++ b/recipes/product-name.title @@ -0,0 +1 @@ +Get the operating system "Product Name" string \ No newline at end of file diff --git a/recipes/resize.html b/recipes/resize.html deleted file mode 100644 index 1a0ca3b..0000000 --- a/recipes/resize.html +++ /dev/null @@ -1,19 +0,0 @@ --This example shows how a block device containing a partition -and a physical volume can be resized. -
- --If you try this out, you -may find that attempts to repartition the disk fail because the -disk is locked by the LVM devices which exist on it. You have -to deactivate (temporarily) the volume groups, perform the -fdisk, and then activate them again. -
- --This example script is self-contained. It first creates a -block device (a temporary file) containing some LVs, then it extends -the temporary file, and shows how to deactivate volgroups, repartition, -and activate them again. -
diff --git a/recipes/resize.sh b/recipes/resize.sh deleted file mode 100755 index 17a7e77..0000000 --- a/recipes/resize.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - - -guestfish <
-The command lists the RPMs installed inside a Fedora / RHEL / CentOS
-or other RPM-based virtual machine. It does this by running the
-rpm -qa
command directly inside the machine.
-
-To use it you need to know the partition or LV inside the -VM that contains the root filesystem, so for example: -
- --rpmqa.sh guest.img /dev/VolGroup00/LogVol00 | less -- -
-You can write a similar command for Debian-based virtual machines -very easily. -
diff --git a/recipes/rpmqa.sh b/recipes/rpmqa.sh deleted file mode 100755 index 8d93f6d..0000000 --- a/recipes/rpmqa.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - - -guestfish -a "$1" --ro -m "$2" command "rpm -qa" diff --git a/recipes/rpmqa.title b/recipes/rpmqa.title deleted file mode 100644 index b50b9b4..0000000 --- a/recipes/rpmqa.title +++ /dev/null @@ -1 +0,0 @@ -List the RPMs installed inside a Fedora or RHEL virtual machine \ No newline at end of file diff --git a/recipes/show-devices.html b/recipes/show-devices.html index 7bed5c7..e27443f 100644 --- a/recipes/show-devices.html +++ b/recipes/show-devices.html @@ -3,3 +3,8 @@ This very simple script shows how you can display an overview of what devices, partitions and LVM data are found in a guest image. + ++See +also virt-filesystems. +
diff --git a/recipes/squashfs.example b/recipes/squashfs.example index af40dd5..1e816f3 100644 --- a/recipes/squashfs.example +++ b/recipes/squashfs.example @@ -1,36 +1,16 @@ $ squashfs.sh -Parallel mksquashfs: Using 2 processors +Parallel mksquashfs: Using 4 processors Creating 4.0 filesystem on test.sqsh, block size 131072. -[===============================================================|] 663/663 100% -Exportable Squashfs 4.0 filesystem, data block size 131072 - compressed data, compressed metadata, compressed fragments - duplicates are removed -Filesystem size 1518.07 Kbytes (1.48 Mbytes) - 98.41% of uncompressed filesystem size (1542.53 Kbytes) -Inode table size 8095 bytes (7.91 Kbytes) - 35.59% of uncompressed inode table size (22748 bytes) -Directory table size 7612 bytes (7.43 Kbytes) - 49.11% of uncompressed directory table size (15499 bytes) -Number of duplicate files found 6 -Number of inodes 701 -Number of files 663 -Number of fragments 13 -Number of symbolic links 37 -Number of device nodes 0 -Number of fifo nodes 0 -Number of socket nodes 0 -Number of directories 1 -Number of ids (unique uids + gids) 1 -Number of uids 1 - root (0) -Number of gids 1 - root (0) -total 1732 -drwxr-xr-x 2 root root 15498 May 27 10:34 . -drwxr-xr-x 18 root root 0 May 29 08:44 .. --rw-r--r-- 1 root root 345 Mar 3 17:53 Kobil_mIDentity_switch.8.gz --rw-r--r-- 1 root root 4878 Mar 8 14:50 MAKEDEV.8.gz --rw-r--r-- 1 root root 1278 May 5 11:36 NetworkManager.8.gz --rw-r--r-- 1 root root 2938 Apr 10 12:15 PAM.8.gz --rw-r--r-- 1 root root 736 Feb 24 20:25 PolicyKit.8.gz -lrwxrwxrwx 1 root root 15 May 14 06:41 accept.8.gz -> cupsaccept.8.gz +[===============================================================|] 752/752 100% + +[...] + +Filesystem Size Used Avail Use% Mounted on +/dev/vda1 97M 3.5M 89M 4% /sysroot/output + +$ guestfish -a test1.img -m /dev/sda1 ll / +total 38 +drwxr-xr-x 4 root root 1024 Dec 21 16:52 . +drwxr-xr-x 23 500 500 4096 Dec 21 16:52 .. +drwx------ 2 root root 12288 Dec 21 16:52 lost+found +drwxr-xr-x. 2 root root 19456 Dec 18 07:20 man8 diff --git a/recipes/squashfs.html b/recipes/squashfs.html index 6b989a0..53774d5 100644 --- a/recipes/squashfs.html +++ b/recipes/squashfs.html @@ -14,3 +14,9 @@ squashfs from the contents of some local directory (/usr/share/man/man8
in this example)
and then make that appear in the guest.
+
++See also virt-tar +and Richard +Jones's complete list of ways to upload and download files. +
diff --git a/recipes/squashfs.sh b/recipes/squashfs.sh index 3daaf2e..ac5bfca 100755 --- a/recipes/squashfs.sh +++ b/recipes/squashfs.sh @@ -1,12 +1,18 @@ #!/bin/sh - datadir=/usr/share/man/man8 +rm -f test.sqsh /sbin/mksquashfs $datadir test.sqsh -guestfish <-Alternatively use a squashfs. +See also virt-make-fs.
diff --git a/recipes/tar2vm.sh b/recipes/tar2vm.sh index 713e9e3..12d8c7a 100755 --- a/recipes/tar2vm.sh +++ b/recipes/tar2vm.sh @@ -1,11 +1,11 @@ #!/bin/sh - guestfish <