virt-sysprep --enable customize --root-password password:123456 -a /dev/sdX
Tag Archives: virt-sysprep
$ cat /tmp/test.bat echo Hello I am a batch file $ virt-customize -a win7.qcow2 --firstboot /tmp/test.bat
Next time the guest boots, check the log file in
C:\Program Files\Red Hat\Firstboot\log.txt
This works well for me in Windows 7 guests. It ought to work in other Windows guests too. So far the only other Windows flavour I tested was W2K3 where the service crashed for some unfathomable reason (I’m not very patient with debugging Windows problems).
So let us know how it goes and we’ll try to fix the bugs as we go along.
As we’re hard at work on the 1.26 release of libguestfs which is going to be a blockbuster, with massive improvements to virt-builder, a rewritten and much more flexible and robust appliance, a new guest customization tool, loads of new virt-sysprep features, rewritten virt-make-fs, and lots more .. it’s worth mentioning that libguestfs is 5 years old today.
The first commit was:
commit 28d760 Author: rjones <rjones> Date: Tue Mar 3 08:58:37 2009 +0000 Build environment set up for libguestfs.
One use for this is to use nbdkit’s xz plugin as a source, to easily create new images from highly compressed templates. In the example below nbdkit transparently (and in RAM) uncompresses the disk image, serving it up over
/tmp/sock (a socket):
$ nbdkit -r -f -U /tmp/sock \ /usr/lib64/nbdkit/plugins/nbdkit-xz-plugin.so \ file=f17x64.img.xz
Virt-resize fetches the image from the socket† and writes & resizes it to the destination file:
$ truncate -s 20G /tmp/output.img # adjust target size $ virt-resize 'nbd://?socket=/tmp/sock' /tmp/output.img $ killall nbdkit; rm /tmp/sock
You can then use virt-sysprep to set the hostname and run configuration scripts in the output image.
† Unfortunately you also have to temporarily disable SELinux for this to work, because SELinux prevents qemu from connecting to the NBD socket. Grrrr.
$ virt-sysprep \ --root-password password:123456 \ --password joe:file:/tmp/secret -a guest.img
You shouldn’t normally specify the cleartext password on the command line, although it’s useful for testing. You should usually provide a file containing the password, ensuring that it is not readable by other users on the system (ie. mode 0600).
Nothing earth-shattering …
Support for setting UUIDs on filesystems. In particular, virt-sysprep will now choose random UUIDs for each filesystem in the guest (previously it only did this for LVM2 objects).
There’s a new add-drive-scratch API (and equivalent
scratch in guestfish) which creates a temporary drive which is automatically discarded when the libguestfs handle closes.
You can now use:
guestfish -N filename=fs
to select an alternate name for the prepared disk image instead of the old
And lots of bug fixes …
- Several APIs have been reimplemented so they don’t suffer from arbitrary protocol limits.
- Python bindings handle optional arguments properly now.
- The tar-out command has several extra (optional) arguments for choosing a range of compression types and other features.
- You can now use rsync to do incremental updates to / backups of your guests.
sshis included in virt-rescue
- virt-sysprep will now assign fresh UUIDs to your PVs and VGs
In libguestfs ≥ 1.19.32 you can now use the virt-sysprep to add “firstboot” scripts to Linux guests. These scripts run exactly once the next time the guest boots, so you can use them to customize the guest in an infinite number of ways: Installing software, changing logos and desktop backgrounds, adding user accounts, etc.
To use this, simply use the
--firstboot option on the command line as many times as required:
$ virt-sysprep -a guest.img \ --firstboot ./yum-update.sh \ --firstboot ./set-desktop.sh