diff options
36 files changed, 177 insertions, 166 deletions
diff --git a/html/recipes.css b/html/recipes.css index ecd61410..c2073553 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 a8ba4fe9..7bd81144 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 '<h3>'$b'.sh</h3>' - echo '<pre class="example">' - sed -e 's,&,\&,g' -e 's,<,\<,g' -e 's,>,\>,g' < $f - echo '</pre>' + echo '<div class="example">' + source-highlight --output=STDOUT --src-lang=sh --input=$f + echo '</div>' if [ -r recipes/$b.example ]; then echo '<h3>Example output</h3>' echo '<pre>' diff --git a/recipes/clone.html b/recipes/clone.html index f87b4ad6..7079f3f0 100644 --- a/recipes/clone.html +++ b/recipes/clone.html @@ -12,6 +12,11 @@ with a new nameserver entry, and change <code>/etc/HOSTNAME</code>. <p> 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. </p> + +<p> +For more information about cloning images using libvirt and libguestfs +see <a href="https://rwmj.wordpress.com/2010/09/24/tip-my-procedure-for-cloning-a-fedora-vm/#content">Richard Jones's procedure for cloning a Fedora VM</a>. +</p> diff --git a/recipes/clone.sh b/recipes/clone.sh index d2b9d99d..85acf1f3 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" <<EOF -write /etc/resolv.conf "nameserver $nameserver" -write /etc/HOSTNAME "$hostname" -sync + write /etc/resolv.conf "nameserver $nameserver" + write /etc/HOSTNAME "$hostname" EOF diff --git a/recipes/editgrub.html b/recipes/editgrub.html index a1b9babe..119bb936 100644 --- a/recipes/editgrub.html +++ b/recipes/editgrub.html @@ -4,12 +4,10 @@ often useful to be able to go in and edit <code>/boot/grub/grub.conf</code>. This guestfish script shows how to do that. </p> -<p> -Usage assumes that the VM has a separate <code>/boot</code> -partition containing grub, which is usually the case. So -for example: -</p> - <pre> -editgrub.sh broken-guest.img /dev/sda1 +editgrub.sh broken-guest.img </pre> + +<p> +See also <a href="http://libguestfs.org/virt-edit.1.html">virt-edit</a>. +</p> diff --git a/recipes/editgrub.sh b/recipes/editgrub.sh index 4cb8ee9c..14a7861f 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 fd23add4..9d9f2d47 100644 --- a/recipes/export2tar.html +++ b/recipes/export2tar.html @@ -12,3 +12,9 @@ export2tar.sh guest.img /dev/VolGroup00/LogVol00 /home home.tar.gz <code>/dev/VolGroup00/LogVol00</code> is the partition or LV <i>inside</i> the VM which contains the directory you want. </p> + +<p> +See also <a href="http://libguestfs.org/virt-tar.1.html">virt-tar</a> +and <a href="https://rwmj.wordpress.com/2010/12/02/tip-uploading-and-downloading/#content">Richard +Jones's complete list of ways to upload and download files</a>. +</p> diff --git a/recipes/export2tar.sh b/recipes/export2tar.sh index 41816daf..fa79b3e1 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 b72f3ba9..b1fe0aa3 100644 --- a/recipes/iso2tar.html +++ b/recipes/iso2tar.html @@ -9,3 +9,9 @@ Usage is very simple: <pre> iso2tar.sh cd.iso output.tar.gz </pre> + +<p> +See also <a href="http://libguestfs.org/virt-tar.1.html">virt-tar</a> +and <a href="https://rwmj.wordpress.com/2010/12/02/tip-uploading-and-downloading/#content">Richard +Jones's complete list of ways to upload and download files</a>. +</p> diff --git a/recipes/list-apps.example b/recipes/list-apps.example new file mode 100644 index 00000000..c37063c2 --- /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 00000000..0a1c4b0d --- /dev/null +++ b/recipes/list-apps.html @@ -0,0 +1,9 @@ +<p> +The command lists the applications (eg. RPMs, debs, Windows programs) +installed inside a virtual machine. It does this using the +<a href="http://libguestfs.org/guestfs.3.html#inspection">inspection API</a>. +</p> + +<p> +See also <a href="http://libguestfs.org/virt-inspector.1.html">virt-inspector</a>. +</p> diff --git a/recipes/list-apps.sh b/recipes/list-apps.sh new file mode 100755 index 00000000..f781a7df --- /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 00000000..104ffe83 --- /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 00000000..c8f8c883 --- /dev/null +++ b/recipes/list-files.html @@ -0,0 +1,3 @@ +<p> +List the files in a virtual machine. +</p> diff --git a/recipes/list-files.sh b/recipes/list-files.sh new file mode 100755 index 00000000..2f91f288 --- /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 00000000..0e8c0d01 --- /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 00000000..55b77fe9 --- /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 00000000..509ada1a --- /dev/null +++ b/recipes/product-name.html @@ -0,0 +1,9 @@ +<p> +Get the string which describes the operating system installed in a +virtual machine. This uses the +<a href="http://libguestfs.org/guestfs.3.html#inspection">inspection API</a>. +</p> + +<p> +See also <a href="http://libguestfs.org/virt-inspector.1.html">virt-inspector</a>. +</p> diff --git a/recipes/product-name.sh b/recipes/product-name.sh new file mode 100755 index 00000000..7dcc7da1 --- /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 00000000..ed64090d --- /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 1a0ca3bb..00000000 --- a/recipes/resize.html +++ /dev/null @@ -1,19 +0,0 @@ -<p> -This example shows how a block device containing a partition -and a physical volume can be resized. -</p> - -<p> -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. -</p> - -<p> -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. -</p> diff --git a/recipes/resize.sh b/recipes/resize.sh deleted file mode 100755 index 17a7e770..00000000 --- a/recipes/resize.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - - -guestfish <<EOF -alloc test.img 130M -run -# You can uncomment the following to see the -# geometry (CHS), which is needed to repartition. -#sfdisk-disk-geometry /dev/sda -sfdisk /dev/sda 0 0 0 , -pvcreate /dev/sda1 -vgcreate VG /dev/sda1 -lvcreate LV1 VG 32M -lvcreate LV2 VG 32M -lvcreate LV3 VG 32M -sync -EOF - -truncate --size=260M test.img - -guestfish -a test.img <<EOF -run -# Turn off the VGs before we can repartition. -vg-activate-all false -sfdisk-N /dev/sda 1 32 255 63 0,31 -vg-activate-all true - -pvresize /dev/sda1 - -# The following command would fail if the -# partition or PV hadn't been resized: -lvcreate LV4 VG 64M - -echo New LV list: -lvs -EOF
\ No newline at end of file diff --git a/recipes/resize.title b/recipes/resize.title deleted file mode 100644 index cc2f3a23..00000000 --- a/recipes/resize.title +++ /dev/null @@ -1 +0,0 @@ -Repartition and resize a block device
\ No newline at end of file diff --git a/recipes/rpmqa.example b/recipes/rpmqa.example deleted file mode 100644 index 837186a5..00000000 --- a/recipes/rpmqa.example +++ /dev/null @@ -1,14 +0,0 @@ -$ ./rpmqa.sh RHEL53PV32.img /dev/VolGroup00/LogVol00 > /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 d5a36768..00000000 --- a/recipes/rpmqa.html +++ /dev/null @@ -1,19 +0,0 @@ -<p> -The command lists the RPMs installed inside a Fedora / RHEL / CentOS -or other RPM-based virtual machine. It does this by running the -<code>rpm -qa</code> command directly inside the machine. -</p> - -<p> -To use it you need to know the partition or LV <i>inside</i> the -VM that contains the root filesystem, so for example: -</p> - -<pre> -rpmqa.sh guest.img /dev/VolGroup00/LogVol00 | less -</pre> - -<p> -You can write a similar command for Debian-based virtual machines -very easily. -</p> diff --git a/recipes/rpmqa.sh b/recipes/rpmqa.sh deleted file mode 100755 index 8d93f6d5..00000000 --- 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 b50b9b47..00000000 --- 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 7bed5c74..e27443f5 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. </p> + +<p> +See +also <a href="http://libguestfs.org/virt-filesystems.1.html">virt-filesystems</a>. +</p> diff --git a/recipes/squashfs.example b/recipes/squashfs.example index af40dd5d..1e816f3c 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 6b989a01..53774d53 100644 --- a/recipes/squashfs.html +++ b/recipes/squashfs.html @@ -14,3 +14,9 @@ squashfs from the contents of some local directory (<code>/usr/share/man/man8</code> in this example) and then make that appear in the guest. </p> + +<p> +See also <a href="http://libguestfs.org/virt-tar.1.html">virt-tar</a> +and <a href="https://rwmj.wordpress.com/2010/12/02/tip-uploading-and-downloading/#content">Richard +Jones's complete list of ways to upload and download files</a>. +</p> diff --git a/recipes/squashfs.sh b/recipes/squashfs.sh index 3daaf2e8..ac5bfca6 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 <<EOF -alloc test.img 10M -add test.sqsh -run -mount /dev/sdb / -ll / +guestfish -N fs -a test.sqsh <<'EOF' + mkmountpoint /output + mkmountpoint /squash + mount-options "" /dev/sda1 /output + mount-options "" /dev/sdb /squash + cp-a /squash /output/man8 + umount /squash + df-h + umount /output EOF + +rm test.sqsh diff --git a/recipes/tar2vm.html b/recipes/tar2vm.html index 7350549f..ecb5c55c 100644 --- a/recipes/tar2vm.html +++ b/recipes/tar2vm.html @@ -21,5 +21,5 @@ course). </p> <p> -Alternatively use <a href="#squashfs">a squashfs</a>. +See also <a href="http://libguestfs.org/virt-make-fs.1.html">virt-make-fs</a>. </p> diff --git a/recipes/tar2vm.sh b/recipes/tar2vm.sh index 713e9e3c..12d8c7a7 100755 --- a/recipes/tar2vm.sh +++ b/recipes/tar2vm.sh @@ -1,11 +1,11 @@ #!/bin/sh - guestfish <<EOF -alloc $2 $3 -run -part-disk /dev/sda mbr -mkfs ext3 /dev/sda1 -mount /dev/sda1 / -tgz-in $1 / -umount-all + alloc $2 $3 + run + part-disk /dev/sda mbr + mkfs ext3 /dev/sda1 + mount /dev/sda1 / + tgz-in $1 / + umount-all EOF diff --git a/recipes/user-quota.html b/recipes/user-quota.html new file mode 100644 index 00000000..f58d5689 --- /dev/null +++ b/recipes/user-quota.html @@ -0,0 +1,6 @@ +<p> +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. +</p> diff --git a/recipes/user-quota.sh b/recipes/user-quota.sh new file mode 100755 index 00000000..1913bbe4 --- /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 00000000..774c166b --- /dev/null +++ b/recipes/user-quota.title @@ -0,0 +1 @@ +See which user is using most space
\ No newline at end of file |