diff options
author | Richard Jones <rjones@redhat.com> | 2009-04-25 11:34:18 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2009-04-25 11:34:18 +0100 |
commit | b86d7b975629ae099ad9a137ced6f23b17c1531a (patch) | |
tree | 32a35026cfc3bf5adbd7f04004d3d543f94072ee /recipes | |
parent | ae17137f643c33f0ad8f61dc1abe4800815ddcc3 (diff) | |
download | libguestfs-b86d7b975629ae099ad9a137ced6f23b17c1531a.tar.gz libguestfs-b86d7b975629ae099ad9a137ced6f23b17c1531a.tar.xz libguestfs-b86d7b975629ae099ad9a137ced6f23b17c1531a.zip |
Added guestfish recipes.
Diffstat (limited to 'recipes')
-rw-r--r-- | recipes/LICENSE | 2 | ||||
-rw-r--r-- | recipes/README | 26 | ||||
-rw-r--r-- | recipes/clone.example | 20 | ||||
-rw-r--r-- | recipes/clone.html | 19 | ||||
-rwxr-xr-x | recipes/clone.sh | 15 | ||||
-rw-r--r-- | recipes/editgrub.html | 17 | ||||
-rwxr-xr-x | recipes/editgrub.sh | 3 | ||||
-rw-r--r-- | recipes/show-devices.example | 14 | ||||
-rw-r--r-- | recipes/show-devices.html | 7 | ||||
-rwxr-xr-x | recipes/show-devices.sh | 10 | ||||
-rw-r--r-- | recipes/tar2vm.example | 8 | ||||
-rw-r--r-- | recipes/tar2vm.html | 23 | ||||
-rwxr-xr-x | recipes/tar2vm.sh | 11 |
13 files changed, 175 insertions, 0 deletions
diff --git a/recipes/LICENSE b/recipes/LICENSE new file mode 100644 index 00000000..d15411e5 --- /dev/null +++ b/recipes/LICENSE @@ -0,0 +1,2 @@ +All the scripts in the recipes/ subdirectory may be freely +copied without any restrictions. diff --git a/recipes/README b/recipes/README new file mode 100644 index 00000000..6a1f7288 --- /dev/null +++ b/recipes/README @@ -0,0 +1,26 @@ +This directory contains guestfish-based shell which give some useful +recipes to follow. + +These also get copied to the website here: +http://et.redhat.com/~rjones/libguestfs/recipes.html + +The format for each recipe is: + + foo.sh Shell script, using guestfish. + foo.html HTML snippet describing the recipe (should start + with <h2>..</h2> giving the title of the recipe) + foo.example Plain text snippet showing example output. + +Everything in the recipes/ directory may be used and distributed +without restrictions. + +To run a script before libguestfs has been installed, you can do +something like this: + + LIBGUESTFS_PATH=.. PATH=../fish:$PATH ./show-devices.sh disk.img + +You can apply these recipes in your own programs by translating the +guestfish commands into API calls in the language of your choice. The +translation is a simple 1-1 mapping. + +Got a useful tip or recipe? Please contribute ... diff --git a/recipes/clone.example b/recipes/clone.example new file mode 100644 index 00000000..8e8a1c1a --- /dev/null +++ b/recipes/clone.example @@ -0,0 +1,20 @@ +$ clone.sh /tmp/test.img /tmp/new.img /dev/sda1 192.168.1.1 newmachine +204800+0 records in +204800+0 records out +104857600 bytes (105 MB) copied, 2.02821 s, 51.7 MB/s +write-file /etc/resolv.conf "nameserver 192.168.1.1" 0 +write-file /etc/HOSTNAME "newmachine" 0 +sync + +$ guestfish -a /tmp/new.img -m /dev/sda1 + +Welcome to guestfish, the libguestfs filesystem interactive shell for +editing virtual machine filesystems. + +Type: 'help' for help with commands + 'quit' to quit the shell + +><fs> cat /etc/resolv.conf +nameserver 192.168.1.1 +><fs> cat /etc/HOSTNAME +newmachine diff --git a/recipes/clone.html b/recipes/clone.html new file mode 100644 index 00000000..a9998e18 --- /dev/null +++ b/recipes/clone.html @@ -0,0 +1,19 @@ +<h2>Clone and edit a virtual machine</h2> + +<p> +This script shows how you might have a library of premade +virtual machines ready for cloning, but as a final step you +use libguestfs or guestfish to customize some configuration +files inside the VM before it's ready to go. +</p> + +<p> +In this simple recipe, we overwrite the <code>/etc/resolv.conf</code> file +with a new nameserver entry, and change <code>/etc/HOSTNAME</code>. +</p> + +<p> +There are lots of possible improvements to this script, such as +using qcow snapshots so that cloned VMs share storage with their +"parent" preimages. +</p> diff --git a/recipes/clone.sh b/recipes/clone.sh new file mode 100755 index 00000000..e3fc11cf --- /dev/null +++ b/recipes/clone.sh @@ -0,0 +1,15 @@ +#!/bin/sh - + +preimage="$1" +newimage="$2" +root="$3" +nameserver="$4" +hostname="$5" + +dd if="$preimage" of="$newimage" + +guestfish -a "$newimage" -m "$root" <<EOF +write-file /etc/resolv.conf "nameserver $nameserver" 0 +write-file /etc/HOSTNAME "$hostname" 0 +sync +EOF diff --git a/recipes/editgrub.html b/recipes/editgrub.html new file mode 100644 index 00000000..7d7a43b7 --- /dev/null +++ b/recipes/editgrub.html @@ -0,0 +1,17 @@ +<h2>Fix an unbootable VM by editing /boot/grub/grub.conf</h2> + +<p> +If you messed up your VM and made it unbootable, it's +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 +</pre> diff --git a/recipes/editgrub.sh b/recipes/editgrub.sh new file mode 100755 index 00000000..4cb8ee9c --- /dev/null +++ b/recipes/editgrub.sh @@ -0,0 +1,3 @@ +#!/bin/sh - + +guestfish -a "$1" -m "$2" vi /grub/grub.conf diff --git a/recipes/show-devices.example b/recipes/show-devices.example new file mode 100644 index 00000000..ccab9ef4 --- /dev/null +++ b/recipes/show-devices.example @@ -0,0 +1,14 @@ +$ show-devices.sh /dev/mapper/Guests-RHEL53PV32 +run +list-devices +/dev/sda +list-partitions +/dev/sda1 +/dev/sda2 +pvs +/dev/sda2 +vgs +VolGroup00 +lvs +/dev/VolGroup00/LogVol00 +/dev/VolGroup00/LogVol01 diff --git a/recipes/show-devices.html b/recipes/show-devices.html new file mode 100644 index 00000000..f89a8ea8 --- /dev/null +++ b/recipes/show-devices.html @@ -0,0 +1,7 @@ +<h2>Display the devices, partitions, LVs, VGs and PVs in a guest image</h2> + +<p> +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> diff --git a/recipes/show-devices.sh b/recipes/show-devices.sh new file mode 100755 index 00000000..6fd2b75b --- /dev/null +++ b/recipes/show-devices.sh @@ -0,0 +1,10 @@ +#!/bin/sh - + +guestfish -a "$1" <<EOF +run +list-devices +list-partitions +pvs +vgs +lvs +EOF diff --git a/recipes/tar2vm.example b/recipes/tar2vm.example new file mode 100644 index 00000000..97a054f4 --- /dev/null +++ b/recipes/tar2vm.example @@ -0,0 +1,8 @@ +tar2vm.sh ../libguestfs-1.0.10.tar.gz /tmp/test.img 10M +alloc /tmp/test.img 10M +run +sfdisk /dev/sda 0 0 0 , +mkfs ext3 /dev/sda1 +mount /dev/sda1 / +tgz-in ../libguestfs-1.0.10.tar.gz / +umount-all diff --git a/recipes/tar2vm.html b/recipes/tar2vm.html new file mode 100644 index 00000000..6a063c66 --- /dev/null +++ b/recipes/tar2vm.html @@ -0,0 +1,23 @@ +<h2>Make a virtual machine out of a tarball</h2> + +<p> +This script shows how you might generate a whole virtual +machine, or a disk image for a virtual machine, starting +with a tarball that contains the content for the machine. +</p> + +<p> +The usage is: +</p> + +<pre> +tar2vm.sh input.tar.gz output.img 100M +</pre> + +<p> +where (for example) <code>100M</code> is the size of the output +disk image. You have to specify a size that is large enough to contain all +the contents of the tarball, but not too large that there is too much +wasted space (unless you want to give the VM extra working space of +course). +</p> diff --git a/recipes/tar2vm.sh b/recipes/tar2vm.sh new file mode 100755 index 00000000..d71a5ef2 --- /dev/null +++ b/recipes/tar2vm.sh @@ -0,0 +1,11 @@ +#!/bin/sh - + +guestfish <<EOF +alloc $2 $3 +run +sfdisk /dev/sda 0 0 0 , +mkfs ext3 /dev/sda1 +mount /dev/sda1 / +tgz-in $1 / +umount-all +EOF |