recipes: Refresh guestfish recipes.
authorRichard W.M. Jones <rjones@redhat.com>
Tue, 21 Dec 2010 17:23:08 +0000 (17:23 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 21 Dec 2010 17:23:08 +0000 (17:23 +0000)
36 files changed:
html/recipes.css
make-recipes.sh
recipes/clone.html
recipes/clone.sh
recipes/editgrub.html
recipes/editgrub.sh
recipes/export2tar.html
recipes/export2tar.sh
recipes/iso2tar.html
recipes/list-apps.example [new file with mode: 0644]
recipes/list-apps.html [new file with mode: 0644]
recipes/list-apps.sh [new file with mode: 0755]
recipes/list-apps.title [new file with mode: 0644]
recipes/list-files.html [new file with mode: 0644]
recipes/list-files.sh [new file with mode: 0755]
recipes/list-files.title [new file with mode: 0644]
recipes/product-name.example [new file with mode: 0644]
recipes/product-name.html [new file with mode: 0644]
recipes/product-name.sh [new file with mode: 0755]
recipes/product-name.title [new file with mode: 0644]
recipes/resize.html [deleted file]
recipes/resize.sh [deleted file]
recipes/resize.title [deleted file]
recipes/rpmqa.example [deleted file]
recipes/rpmqa.html [deleted file]
recipes/rpmqa.sh [deleted file]
recipes/rpmqa.title [deleted file]
recipes/show-devices.html
recipes/squashfs.example
recipes/squashfs.html
recipes/squashfs.sh
recipes/tar2vm.html
recipes/tar2vm.sh
recipes/user-quota.html [new file with mode: 0644]
recipes/user-quota.sh [new file with mode: 0755]
recipes/user-quota.title [new file with mode: 0644]

index ecd6141..c207355 100644 (file)
@@ -1,8 +1,8 @@
 /* CSS to make pod2html files look a little bit better. */
 @import url("http://people.redhat.com/~rjones/css/standard.css");
 
 /* 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
 }
\ No newline at end of file
index a8ba4fe..7bd8114 100755 (executable)
@@ -66,9 +66,9 @@ for f in recipes/*.sh; do
         cat recipes/$b.html
     fi
     echo '<h3>'$b'.sh</h3>'
         cat recipes/$b.html
     fi
     echo '<h3>'$b'.sh</h3>'
-    echo '<pre class="example">'
-    sed -e 's,&,\&amp;,g' -e 's,<,\&lt;,g' -e 's,>,\&gt;,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>'
     if [ -r recipes/$b.example ]; then
         echo '<h3>Example output</h3>'
         echo '<pre>'
index f87b4ad..7079f3f 100644 (file)
@@ -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
 
 <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>
 "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>
index d2b9d99..85acf1f 100755 (executable)
@@ -1,15 +1,14 @@
 #!/bin/sh -
 
 #!/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
 
 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
 EOF
index a1b9bab..119bb93 100644 (file)
@@ -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>
 
 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>
 <pre>
-editgrub.sh broken-guest.img /dev/sda1
+editgrub.sh broken-guest.img
 </pre>
 </pre>
+
+<p>
+See also <a href="http://libguestfs.org/virt-edit.1.html">virt-edit</a>.
+</p>
index 4cb8ee9..14a7861 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/sh -
 
 #!/bin/sh -
 
-guestfish -a "$1" -m "$2" vi /grub/grub.conf
+guestfish -a "$1" -i edit /boot/grub/grub.conf
index fd23add..9d9f2d4 100644 (file)
@@ -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>
 <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>
index 41816da..fa79b3e 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/sh -
 
 #!/bin/sh -
 
-guestfish -a "$1" --ro -m "$2" tgz-out "$3" "$4"
+guestfish --ro -a "$1" -m "$2" tgz-out "$3" "$4"
index b72f3ba..b1fe0aa 100644 (file)
@@ -9,3 +9,9 @@ Usage is very simple:
 <pre>
 iso2tar.sh cd.iso output.tar.gz
 </pre>
 <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 (file)
index 0000000..c37063c
--- /dev/null
@@ -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 (file)
index 0000000..0a1c4b0
--- /dev/null
@@ -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 (executable)
index 0000000..f781a7d
--- /dev/null
@@ -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 (file)
index 0000000..104ffe8
--- /dev/null
@@ -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 (file)
index 0000000..c8f8c88
--- /dev/null
@@ -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 (executable)
index 0000000..2f91f28
--- /dev/null
@@ -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 (file)
index 0000000..0e8c0d0
--- /dev/null
@@ -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 (file)
index 0000000..55b77fe
--- /dev/null
@@ -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 (file)
index 0000000..509ada1
--- /dev/null
@@ -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 (executable)
index 0000000..7dcc7da
--- /dev/null
@@ -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 (file)
index 0000000..ed64090
--- /dev/null
@@ -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 (file)
index 1a0ca3b..0000000
+++ /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 (executable)
index 17a7e77..0000000
+++ /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 (file)
index cc2f3a2..0000000
+++ /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 (file)
index 837186a..0000000
+++ /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 (file)
index d5a3676..0000000
+++ /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 (executable)
index 8d93f6d..0000000
+++ /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 (file)
index b50b9b4..0000000
+++ /dev/null
@@ -1 +0,0 @@
-List the RPMs installed inside a Fedora or RHEL virtual machine
\ No newline at end of file
index 7bed5c7..e27443f 100644 (file)
@@ -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>
 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>
index af40dd5..1e816f3 100644 (file)
@@ -1,36 +1,16 @@
 $ squashfs.sh
 $ squashfs.sh
-Parallel mksquashfs: Using 2 processors
+Parallel mksquashfs: Using 4 processors
 Creating 4.0 filesystem on test.sqsh, block size 131072.
 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
index 6b989a0..53774d5 100644 (file)
@@ -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>
 (<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>
index 3daaf2e..ac5bfca 100755 (executable)
@@ -1,12 +1,18 @@
 #!/bin/sh -
 
 datadir=/usr/share/man/man8
 #!/bin/sh -
 
 datadir=/usr/share/man/man8
+rm -f test.sqsh
 /sbin/mksquashfs $datadir 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
 EOF
+
+rm test.sqsh
index 7350549..ecb5c55 100644 (file)
@@ -21,5 +21,5 @@ course).
 </p>
 
 <p>
 </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>
 </p>
index 713e9e3..12d8c7a 100755 (executable)
@@ -1,11 +1,11 @@
 #!/bin/sh -
 
 guestfish <<EOF
 #!/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
 EOF
diff --git a/recipes/user-quota.html b/recipes/user-quota.html
new file mode 100644 (file)
index 0000000..f58d568
--- /dev/null
@@ -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 (executable)
index 0000000..1913bbe
--- /dev/null
@@ -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 (file)
index 0000000..774c166
--- /dev/null
@@ -0,0 +1 @@
+See which user is using most space
\ No newline at end of file