Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Upon cloning a base image, I need to reconfigure basic settings. Regenerating the ssh host key, changing static IP assignments, setting the host name, etc.

Because of the network setup, DHCP is not an option. That more or less rules out SSHing in with a predefined key or running a startup script since I can't provide the IP externally.

I'd most like to mount the filesystem of the new machine on Dom0, but the lvm volumes are exported and it appears to be Bad Form to import them so the Dom0 machine can see them.

What's your best suggestion for altering files in a cloned VM before boot? Must be non-interactive, and I'm going to guess out the gate that scripting access via xe console is not going to work well.

share|improve this question
I'm sure there are good reasons, but I'm curious to hear more about why DHCP isn't an option. Thanks! – Jed Daniels Mar 23 '12 at 5:19

You should do what some deployment systems (Open Nebula for instance) do - create a tiny second drive consisting of the personalization data.

Configure your image to expect this second drive to be there (perhaps with a known UUID or filesystem name) and if it is there, read out the personalization data and apply it to the OS during boot.

The other cool option that Open Nebula does is actually embed the IP address into the MAC address. Decode that inside your domU and you're set!

Or, just use IPv6 autoconfig. :)

share|improve this answer
+1 These are the two solutions that I was going to propose, although I'd like to know more about why DHCP isn't an option. I usually just use DHCP and configure my DHCP server with static entries for MACs that I assign to the VMs (ok, not really, I clone the VMs, then run a script that collects their MACs and generates the appropriate dhcpd.conf block, which I then stick into my dhcpd server before booting them; but same difference really). – Jed Daniels Mar 23 '12 at 5:18

Because of the network setup, DHCP is not an option. That more or less rules out SSHing in with a predefined key or running a startup script since I can't provide the IP externally.

What about using a static IP as a "build IP", boot the image on this known IP with a known key and kick off a script that logs in, reconfigures, and reboots?

share|improve this answer

Configure the base image to

  • auto-ip
  • download a configuration tarball
    • via ftp or something simple
    • base the tarball name on something unique to the machine, like the MAC addy
    • from a known address (eg or fe80::1)
  • unpack the tar to apply the configuration
  • reboot

Also has the ability to get really creative if you want; auto-generate the tarball on download request, possibly based on database information, and generally based on a configuration skeleton.

share|improve this answer
up vote 0 down vote accepted

Apparently, vgexport/vgimport is not necessary to move drives from one system to another. It is an administrative policy tool to prevent access to volumes in the time it takes to move them.

vgchange -a y marked all volumes as usable, but that didn't help me because they're not direct partitions. They're virtual disk images that have partition tables inside them.

Then I came across the script below at Direct attachment of disks to the VM... adjust as needed, the re-call to unmount.

# 2011
if [ ! -n "$1" -o ! -n "$2" -o ! -n "$3" ]; then
echo "Usage: $0 <target vm uuid> <control domain uuid> <mount|umount>"
exit 1

case "$3" in
if [ -f /tmp/tmpvbd ]; then
echo "VBD allready exists!"
exit 1

# Get uuid of vm you want to configure
VMUUID=`xe vbd-list vm-uuid=$1 params=vdi-uuid empty=false --minimal`

# Create VBD link to VM VDI on dom0
NEWVM=`xe vbd-create vm-uuid=$2 vdi-uuid=$VMUUID device=1`

# Plug it to dom0
xe vbd-plug uuid=$NEWVM

VM_VDEV=`xe vbd-list uuid=$NEWVM params=device --minimal`1

# Lag
sleep 1

# Mount it
mount /dev/$VM_VDEV /mnt/newvm

echo $NEWVM > /tmp/tmpvbd
# Do what ever you like
# ....


if [ ! -f /tmp/tmpvbd ]; then
echo "No VBDs mounted?"
exit 1

umount /mnt/newvm

NEWVM=`cat /tmp/tmpvbd`

# Unplug
xe vbd-unplug uuid=$NEWVM

xe vbd-destroy uuid=$NEWVM

rm -f /tmp/tmpvbd

exit $?
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.