Red Hat Bugzilla – Bug 1019388
firstboot scripts (virt-builder, virt-sysprep) don't work for Debian 6 & 7 guests
Last modified: 2016-09-01 06:19:46 EDT
Description of problem:
virt-sysprep and virt-builder have various --firstboot options
which let you inject scripts that run once the first time the
guest is booted. However they do not work for Debian 6 & 7
guests (they do work for other guests).
Version-Release number of selected component (if applicable):
Steps to Reproduce:
virt-builder debian-6 --firstboot-command "echo HELLO WORLD"
(or use debian-7 instead of debian-6). After the guest has been
created, boot it up and check to see if the /root/virt-sysprep-firstboot.log
file exists and contains the magic string.
No log file created and it doesn't contain the magic string.
Log file created and it contains the magic string.
Is it because we're not running update-rc.d?
(In reply to Richard W.M. Jones from comment #0)
> Is it because we're not running update-rc.d?
Since Debian 6 (or for sure Debian 7) the SysV boot has become dependency-based, so just adding the init script and manually creating the symlinks is not enough.
But running update-rc.d or insserv is not an option, so in case firsrboot.ml should basically do something similar to what insserv does, i.e. fiddle with the services dependencies adding our own firstboot script service.
I am using Debian testing with libguestfs version 1.26.2.
This bug is still present with debian 7 images at least (I didn't test with anything else).
Here is a workaround :
You need to run update-rc.d (previously reported) with a "--run-command" option.
For example :
virt-sysprep -a /path/to/image.img --firstboot /path/to/firstboot_script --run-command 'update-rc.d virt-sysprep-firstboot defaults'
So probably using the update-rc.d command (comment 2) in
install_sysvinit_debian would work
I really don't like running guest commands for sysprep
operations. It would be better to `virt-diff' the guest
before and after update-rc.d to see what it does.
I have done `virt-diff' the guest before and after update-rc.d.
Here is the differences :
- the file /etc/init.d/.depend.start has changed
--- etc1/init.d/.depend.start 2014-06-25 15:39:24.000000000 +0200
+++ etc2/init.d/.depend.start 2014-07-02 22:17:37.000000000 +0200
@@ -1,4 +1,4 @@
-TARGETS = killprocs motd rpcbind nfs-common rsyslog exim4 atd cron acpid ssh bootlogs single rmnologin rc.local
+TARGETS = killprocs motd rpcbind nfs-common rsyslog exim4 atd cron acpid ssh bootlogs single virt-sysprep-firstboot rmnologin rc.local
@@ -6,5 +6,6 @@
single: killprocs bootlogs motd
+virt-sysprep-firstboot: rpcbind nfs-common rsyslog exim4 atd bootlogs motd cron acpid ssh
rmnologin: rpcbind nfs-common rsyslog exim4 atd bootlogs motd cron acpid ssh
rc.local: rpcbind nfs-common rsyslog exim4 atd bootlogs motd cron acpid ssh
- the symlink /etc/rc2.d/S99virt-sysprep-firstboot has changed
Before: /etc/rc2.d/S99virt-sysprep-firstboot -> /etc/init.d/virt-sysprep-firstboot
After: /etc/rc2.d/S20virt-sysprep-firstboot -> ../init.d/virt-sysprep-firstboot
- the symlink /etc/rc3.d/S99virt-sysprep-firstboot has changed
Before: /etc/rc3.d/S99virt-sysprep-firstboot -> /etc/init.d/virt-sysprep-firstboot
After: /etc/rc3.d/S20virt-sysprep-firstboot -> ../init.d/virt-sysprep-firstboot
- the symlink /etc/rc5.d/S99virt-sysprep-firstboot has changed
Before: /etc/rc5.d/S99virt-sysprep-firstboot -> /etc/init.d/virt-sysprep-firstboot
After: /etc/rc5.d/S20virt-sysprep-firstboot -> ../init.d/virt-sysprep-firstboot
I think that only the /etc/init.d/.depend.start is relevant.
Instead of doing:
--run-command 'update-rc.d virt-sysprep-firstboot defaults'
you can just do:
insserv doesn't exactly the same thing (ie it gives the same 'virt-diff').
Thanks, this is all interesting and useful information for when
we (or someone) comes to fix this.
Fixed upstream in libguestfs >= 1.35.3 and >= 1.34.2.