From 49b2ae2e69e1a273b4d4a8746a872ec00b91c86f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 21 Dec 2010 17:23:08 +0000 Subject: [PATCH] recipes: Refresh guestfish recipes. --- html/recipes.css | 8 ++++---- make-recipes.sh | 6 +++--- recipes/clone.html | 7 ++++++- recipes/clone.sh | 17 ++++++++-------- recipes/editgrub.html | 12 +++++------ recipes/editgrub.sh | 2 +- recipes/export2tar.html | 6 ++++++ recipes/export2tar.sh | 2 +- recipes/iso2tar.html | 6 ++++++ recipes/list-apps.example | 29 ++++++++++++++++++++++++++ recipes/list-apps.html | 9 +++++++++ recipes/list-apps.sh | 6 ++++++ recipes/list-apps.title | 1 + recipes/list-files.html | 3 +++ recipes/list-files.sh | 5 +++++ recipes/list-files.title | 1 + recipes/product-name.example | 2 ++ recipes/product-name.html | 9 +++++++++ recipes/product-name.sh | 6 ++++++ recipes/product-name.title | 1 + recipes/resize.html | 19 ------------------ recipes/resize.sh | 35 -------------------------------- recipes/resize.title | 1 - recipes/rpmqa.example | 14 ------------- recipes/rpmqa.html | 19 ------------------ recipes/rpmqa.sh | 3 --- recipes/rpmqa.title | 1 - recipes/show-devices.html | 5 +++++ recipes/squashfs.example | 48 +++++++++++++------------------------------- recipes/squashfs.html | 6 ++++++ recipes/squashfs.sh | 18 +++++++++++------ recipes/tar2vm.html | 2 +- recipes/tar2vm.sh | 14 ++++++------- recipes/user-quota.html | 6 ++++++ recipes/user-quota.sh | 13 ++++++++++++ recipes/user-quota.title | 1 + 36 files changed, 177 insertions(+), 166 deletions(-) create mode 100644 recipes/list-apps.example create mode 100644 recipes/list-apps.html create mode 100755 recipes/list-apps.sh create mode 100644 recipes/list-apps.title create mode 100644 recipes/list-files.html create mode 100755 recipes/list-files.sh create mode 100644 recipes/list-files.title create mode 100644 recipes/product-name.example create mode 100644 recipes/product-name.html create mode 100755 recipes/product-name.sh create mode 100644 recipes/product-name.title delete mode 100644 recipes/resize.html delete mode 100755 recipes/resize.sh delete mode 100644 recipes/resize.title delete mode 100644 recipes/rpmqa.example delete mode 100644 recipes/rpmqa.html delete mode 100755 recipes/rpmqa.sh delete mode 100644 recipes/rpmqa.title create mode 100644 recipes/user-quota.html create mode 100755 recipes/user-quota.sh create mode 100644 recipes/user-quota.title diff --git a/html/recipes.css b/html/recipes.css index ecd6141..c207355 100644 --- a/html/recipes.css +++ b/html/recipes.css @@ -1,8 +1,8 @@ /* CSS to make pod2html files look a little bit better. */ @import url("http://people.redhat.com/~rjones/css/standard.css"); -pre.example { - font-weight: bold; - width: 40em; - border: 1px solid #c00; +div.example pre { + /*font-weight: bold;*/ + width: 40em; + border: 1px solid #c00; } \ No newline at end of file diff --git a/make-recipes.sh b/make-recipes.sh index a8ba4fe..7bd8114 100755 --- a/make-recipes.sh +++ b/make-recipes.sh @@ -66,9 +66,9 @@ for f in recipes/*.sh; do cat recipes/$b.html fi echo '

'$b'.sh

' - echo '
'
-    sed -e 's,&,\&,g' -e 's,<,\<,g' -e 's,>,\>,g' < $f
-    echo '
' + echo '
' + source-highlight --output=STDOUT --src-lang=sh --input=$f + echo '
' if [ -r recipes/$b.example ]; then 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.
 
 

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. +

diff --git a/recipes/clone.sh b/recipes/clone.sh index d2b9d99..85acf1f 100755 --- a/recipes/clone.sh +++ b/recipes/clone.sh @@ -1,15 +1,14 @@ #!/bin/sh - -preimage="$1" -newimage="$2" -root="$3" -nameserver="$4" -hostname="$5" +preimage="$1" ;# original guest +newimage="$2" ;# new guest +root="$3" ;# root filesystem +nameserver="$4" ;# new nameserver +hostname="$5" ;# new hostname -dd if="$preimage" of="$newimage" +dd if="$preimage" of="$newimage" bs=1M guestfish -a "$newimage" -m "$root" </boot/grub/grub.conf. This guestfish script shows how to do that.

-

-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 < /tmp/rpms -$ ls -l /tmp/rpms --rw-rw-r--. 1 rjones rjones 17228 2009-04-26 07:02 /tmp/rpms -$ head /tmp/rpms -tzdata-2008i-1.el5 -nash-5.1.19.6-44 -gnome-mime-data-2.4.2-3.1 -dump-0.4b41-2.fc6 -emacs-leim-21.4-20.el5 -rootfiles-8.1-1.1.1 -glibc-2.5-34 -popt-1.10.2.3-9.el5 -libart_lgpl-2.3.17-4 -audit-libs-1.7.7-6.el5 diff --git a/recipes/rpmqa.html b/recipes/rpmqa.html deleted file mode 100644 index d5a3676..0000000 --- a/recipes/rpmqa.html +++ /dev/null @@ -1,19 +0,0 @@ -

-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 < +A simple way to see which home directory is using most +space. Note this just counts the contents of directories +in /home and doesn't include other files that a user may +have. +

diff --git a/recipes/user-quota.sh b/recipes/user-quota.sh new file mode 100755 index 0000000..1913bbe --- /dev/null +++ b/recipes/user-quota.sh @@ -0,0 +1,13 @@ +#!/bin/sh - + +vmfile="$1" +dir=/home + +eval $(guestfish --ro -a "$vmfile" -i --listen) + +for d in $(guestfish --remote ls "$dir"); do + echo -n "$dir/$d" + echo -ne '\t' + guestfish --remote du "$dir/$d"; +done | sort -nr -k 2 +guestfish --remote exit diff --git a/recipes/user-quota.title b/recipes/user-quota.title new file mode 100644 index 0000000..774c166 --- /dev/null +++ b/recipes/user-quota.title @@ -0,0 +1 @@ +See which user is using most space \ No newline at end of file -- 1.8.3.1