recipes: Refresh guestfish recipes.

This commit is contained in:
Richard W.M. Jones
2010-12-21 17:23:08 +00:00
parent b1ca8b5fbb
commit 49b2ae2e69
36 changed files with 177 additions and 166 deletions

View 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");
pre.example {
font-weight: bold;
width: 40em;
border: 1px solid #c00;
div.example pre {
/*font-weight: bold;*/
width: 40em;
border: 1px solid #c00;
}

View File

@@ -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,&,\&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>'

View 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
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>

View File

@@ -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

View 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>
<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>

View File

@@ -1,3 +1,3 @@
#!/bin/sh -
guestfish -a "$1" -m "$2" vi /grub/grub.conf
guestfish -a "$1" -i edit /boot/grub/grub.conf

View 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>
<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>

View File

@@ -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"

View File

@@ -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>

29
recipes/list-apps.example Normal file
View File

@@ -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:
}

9
recipes/list-apps.html Normal file
View File

@@ -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>

6
recipes/list-apps.sh Executable file
View File

@@ -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

1
recipes/list-apps.title Normal file
View File

@@ -0,0 +1 @@
List the apps (eg. RPMs) installed inside a virtual machine

3
recipes/list-files.html Normal file
View File

@@ -0,0 +1,3 @@
<p>
List the files in a virtual machine.
</p>

5
recipes/list-files.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh -
guestfish --ro -a "$1" -i find0 / - |
tr '\000' '\n' |
sort

1
recipes/list-files.title Normal file
View File

@@ -0,0 +1 @@
List the files and directories in a virtual machine

View File

@@ -0,0 +1,2 @@
$ product-name.sh win.img
Windows 7 Enterprise

View File

@@ -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>

6
recipes/product-name.sh Executable file
View File

@@ -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

View File

@@ -0,0 +1 @@
Get the operating system "Product Name" string

View File

@@ -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>

View File

@@ -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

View File

@@ -1 +0,0 @@
Repartition and resize a block device

View File

@@ -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

View File

@@ -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>

View File

@@ -1,3 +0,0 @@
#!/bin/sh -
guestfish -a "$1" --ro -m "$2" command "rpm -qa"

View File

@@ -1 +0,0 @@
List the RPMs installed inside a Fedora or RHEL virtual machine

View 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>
<p>
See
also <a href="http://libguestfs.org/virt-filesystems.1.html">virt-filesystems</a>.
</p>

View File

@@ -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

View 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>
<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>

View File

@@ -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

View File

@@ -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>

View File

@@ -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

6
recipes/user-quota.html Normal file
View File

@@ -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>

13
recipes/user-quota.sh Executable file
View File

@@ -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

1
recipes/user-quota.title Normal file
View File

@@ -0,0 +1 @@
See which user is using most space