summaryrefslogtreecommitdiff
path: root/create-vm
diff options
context:
space:
mode:
authorLars Wirzenius <liw@exolobe2.liw.fi>2019-06-11 05:46:16 +0000
committerLars Wirzenius <liw@exolobe2.liw.fi>2019-06-11 05:46:16 +0000
commitb81d7a2219785d64ee7cb2c5fa222f91e81ce64a (patch)
treed876fc2717374329687d2c87eb36f10c1c47bdb7 /create-vm
parent5935ef1891b3410687aede6181e4413ce0f5e21b (diff)
downloadansibleness-b81d7a2219785d64ee7cb2c5fa222f91e81ce64a.tar.gz
Change: set /etc/hostname of new VM before initial boot
Diffstat (limited to 'create-vm')
-rwxr-xr-xcreate-vm14
1 files changed, 14 insertions, 0 deletions
diff --git a/create-vm b/create-vm
index 2202eb0..ca689ae 100755
--- a/create-vm
+++ b/create-vm
@@ -84,6 +84,20 @@ unxz < "$basepath" |
pv --size "$size" |
sudo ionice -c3 tee "$lvpath" > /dev/null
+# Edit /etc/hostname
+verbose "Set hostname on new system to $name"
+mnt="$(mktemp -d)"
+for part in $(sudo kpartx -asv "$lvpath" | awk '/^add map / { print $3 }')
+do
+ sudo mount "/dev/mapper/$part" "$mnt"
+ if [ -e "$mnt/etc/hostname" ]
+ then
+ echo "$name" | sudo tee "$mnt/etc/hostname"
+ fi
+ sudo umount "$mnt"
+done
+sudo kpartx -dsv "$lvpath"
+
# Create VM.
verbose "Creating VM"
virt-install --connect qemu:///system \