Red Hat Bugzilla – Bug 988863
virt-sysprep --firstboot option writes incorrect "99" (instead of "S99") sysv-init-style start up script
Last modified: 2013-12-25 19:12:15 EST
+++ This bug was initially created as a clone of Bug #988860 +++ Description of problem: When you use virt-sysprep on a pre-systemd guest (eg. RHEL 6 guest), with the --firstboot option, it writes a start-up script called /etc/rc.d/rc3.d/99virt-sysprep-firstboot This is of course wrong. The file should be called /etc/rc.d/rc3.d/S99virt-sysprep-firstboot ^NB As a result of the incorrect name, the firstboot script does not run. Version-Release number of selected component (if applicable): libguestfs 1.20.9, 1.22.4, 1.23.10 Note I have fixed this upstream already: https://github.com/libguestfs/libguestfs/commit/44c5026d9e06cf5f01098608ddd0aa4acb7bb6eb This bug exists so that I can check the fix goes into RHEL 6 & RHEL 7. How reproducible: 100% Steps to Reproduce: Create a small shell script that "does something useful". eg. It could touch a file at a known location. export LIBGUESTFS_TRACE=1 virt-sysprep --firstboot ./some-script.sh -a RHEL6.guest Try to boot the guest. Observe whether or not the firstboot script ran when the guest booted (eg. was the file touched?) Additional info: The bug was found by Nick Strugnell.
Can reprodece with libguestfs-1.20.9-6.el6.x86_64: [root]# cat some-script.sh #!/bin/bash touch /home/usefulfile [root]# virt-sysprep --firstboot ./some-script.sh -a RHEL-Server-6.4-64-hvm.raw /home/usefulfile then, boot up the rhel6.4 guest, and there is no /home/usefulfile
I can not find libguestfs 1.20.9, 1.22.4, 1.23.10 for RHEL6.5 from https://brewweb.devel.redhat.com. So, I skip the reproduce step. Also, I can not find libguestfs-1.20.10-1.el6 from https://brewweb.devel.redhat.com, so I choose libguestfs-1.20.10-3.el6 to Verify this bug. Verified: 1. Install libguestfs-1.20.10-3.el6 on RHEL6.5 host. 2. Create test script: [host]#cat touch.sh #!/bin/bash touch /root/1.20.10-2.el6.txt 3. Execute the following command: [host]#export LIBGUESTFS_TRACE=1 [host]#virt-sysprep --firstboot ./touch.sh -a kvm-6.5-64-1.img 4. Login the guest check whether the is a /root/1.20.10-2.el6.txt on guest Result: /root/1.20.10-2.el6.txt file exists on the guest. This is the "virt-sysprep --firstboot ./touch.sh -a kvm-6.5-64-1.img" command output: libguestfs: trace: is_dir "/etc/systemd" libguestfs: trace: is_dir = 0 libguestfs: trace: mkdir_p "/etc/rc.d/rc2.d" libguestfs: trace: mkdir_p = 0 libguestfs: trace: mkdir_p "/etc/rc.d/rc3.d" libguestfs: trace: mkdir_p = 0 libguestfs: trace: mkdir_p "/etc/rc.d/rc5.d" libguestfs: trace: mkdir_p = 0 libguestfs: trace: ln_sf "/usr/lib/virt-sysprep/firstboot.sh" "/etc/rc.d/rc2.d/S99virt-sysprep-firstboot" libguestfs: trace: ln_sf = 0 libguestfs: trace: ln_sf "/usr/lib/virt-sysprep/firstboot.sh" "/etc/rc.d/rc3.d/S99virt-sysprep-firstboot" libguestfs: trace: ln_sf = 0 libguestfs: trace: ln_sf "/usr/lib/virt-sysprep/firstboot.sh" "/etc/rc.d/rc5.d/S99virt-sysprep-firstboot" libguestfs: trace: ln_sf = 0 libguestfs: trace: write "/usr/lib/virt-sysprep/scripts/1381992707-gpsyazqb-touch-sh" "#!/bin/bash\x0a\x0atouch /root/1.20.10-3.el6.txt\x0a\x0a" libguestfs: trace: internal_write "/usr/lib/virt-sysprep/scripts/1381992707-gpsyazqb-touch-sh" "#!/bin/bash\x0a\x0atouch /root/1.20.10-3.el6.txt\x0a\x0a" virt-sysprep called "/etc/rc.d/rc2.d/S99virt-sysprep-firstboot".
(In reply to Lingfei Kong from comment #4) > I can not find libguestfs 1.20.9, 1.22.4, 1.23.10 for RHEL6.5 from > https://brewweb.devel.redhat.com. So, I skip the reproduce step. Also, I can > not find libguestfs-1.20.10-1.el6 from https://brewweb.devel.redhat.com, so > I choose libguestfs-1.20.10-3.el6 to Verify this bug. Correct: This is a new feature in RHEL 6. > Verified: > 1. Install libguestfs-1.20.10-3.el6 on RHEL6.5 host. > 2. Create test script: > [host]#cat touch.sh > #!/bin/bash > > touch /root/1.20.10-2.el6.txt > > 3. Execute the following command: > [host]#export LIBGUESTFS_TRACE=1 > [host]#virt-sysprep --firstboot ./touch.sh -a kvm-6.5-64-1.img > > 4. Login the guest check whether the is a /root/1.20.10-2.el6.txt on guest > Result: /root/1.20.10-2.el6.txt file exists on the guest. > > > This is the "virt-sysprep --firstboot ./touch.sh -a kvm-6.5-64-1.img" > command output: > libguestfs: trace: is_dir "/etc/systemd" > libguestfs: trace: is_dir = 0 > libguestfs: trace: mkdir_p "/etc/rc.d/rc2.d" > libguestfs: trace: mkdir_p = 0 > libguestfs: trace: mkdir_p "/etc/rc.d/rc3.d" > libguestfs: trace: mkdir_p = 0 > libguestfs: trace: mkdir_p "/etc/rc.d/rc5.d" > libguestfs: trace: mkdir_p = 0 > libguestfs: trace: ln_sf "/usr/lib/virt-sysprep/firstboot.sh" > "/etc/rc.d/rc2.d/S99virt-sysprep-firstboot" > libguestfs: trace: ln_sf = 0 > libguestfs: trace: ln_sf "/usr/lib/virt-sysprep/firstboot.sh" > "/etc/rc.d/rc3.d/S99virt-sysprep-firstboot" > libguestfs: trace: ln_sf = 0 > libguestfs: trace: ln_sf "/usr/lib/virt-sysprep/firstboot.sh" > "/etc/rc.d/rc5.d/S99virt-sysprep-firstboot" > libguestfs: trace: ln_sf = 0 > libguestfs: trace: write > "/usr/lib/virt-sysprep/scripts/1381992707-gpsyazqb-touch-sh" > "#!/bin/bash\x0a\x0atouch /root/1.20.10-3.el6.txt\x0a\x0a" > libguestfs: trace: internal_write > "/usr/lib/virt-sysprep/scripts/1381992707-gpsyazqb-touch-sh" > "#!/bin/bash\x0a\x0atouch /root/1.20.10-3.el6.txt\x0a\x0a" > > > virt-sysprep called "/etc/rc.d/rc2.d/S99virt-sysprep-firstboot". It'd be nice to test if, when the guest boots up, it actually runs the firstboot script. I have recently fixed a lot of bugs in this area of the code, but *hopefully* none of those bugs affect RHEL guests so this ought to work. To verify this: qemu-kvm -drive file=disk.img,snapshot=on -m 1024 When the guest boots, log in and verify that /root/virt-sysprep-firstboot.log exists and any firstboot actions/logs that you were expecting to happen did happen.
(In reply to Richard W.M. Jones from comment #5) > When the guest boots, log in and verify that /root/virt-sysprep-firstboot.log > exists and any firstboot actions/logs that you were expecting to > happen did happen. Sorry, I'm not quite understand about "any firstboot actions/logs that you were expecting to happen did happen", Could you explain more about it? I boot RHEL6.5 guest with "/usr/libexec/qemu-kvm -drive file=kvm-6.5-64-1.img,snapshot=on -m 1024", then login the guesst, and found there is a /root/virt-sysprep-firstboot.log file exist, but there are only three lines inside the file, I can not get more infromation from virt-sysprep-firstboot.log. [guest]cat #/root/virt-sysprep-firstboot.log = = = Running /usr/lib/virt-sysprep/scripts/1381993196-gpsyazqb-touch-sh = = = = = = Running /usr/lib/virt-sysprep/scripts/1381993196-gpsyazqb-touch-sh = = = = = = Running /usr/lib/virt-sysprep/scripts/1381993196-gpsyazqb-touch-sh = = =
(In reply to Lingfei Kong from comment #6) > I boot RHEL6.5 guest with "/usr/libexec/qemu-kvm -drive > file=kvm-6.5-64-1.img,snapshot=on -m 1024", then login the guesst, and found > there is a /root/virt-sysprep-firstboot.log file exist, but there are only > three lines inside the file, I can not get more infromation from > virt-sysprep-firstboot.log. > > [guest]cat #/root/virt-sysprep-firstboot.log > = = = Running /usr/lib/virt-sysprep/scripts/1381993196-gpsyazqb-touch-sh = = > = > = = = Running /usr/lib/virt-sysprep/scripts/1381993196-gpsyazqb-touch-sh = = > = > = = = Running /usr/lib/virt-sysprep/scripts/1381993196-gpsyazqb-touch-sh = = > = It looks like the script ran 3 times. That might be a bug ... You can put some echo commands into the script, and they should appear in the log file.
In fact I did the test for two times before the test in Comment 4(use the same guest image and test script: touch.sh), this would explain why there are three lines inside /root/virt-sysprep-firstboot.log. And this time I delete /root/virt-sysprep-firstboot.log and the files I have touched. Doing the test with a test.sh script: [host]#cat test.sh #!/bin/bash touch /root/1.20.10-3.el6.txt echo "Hello World" 1. [host]#virt-sysprep --firstboot ./test.sh -a kvm-6.5-64-1.img 2. [host]#/usr/libexec/qemu-kvm -drive file=kvm-6.5-64-1.img,snapshot=on -m 1024 -vnc :0 login the guest and check /root/virt-sysprep-firstboot.log, happy to see: [guest]cat #/root/virt-sysprep-firstboot.log = = = Running /usr/lib/virt-sysprep/scripts/1381993196-gpsyazqb-test-sh = = = Hello World that's to say firstboot actions/logs what I am expecting to happen and only ran 1 time. So, this bug is fixed.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. http://rhn.redhat.com/errata/RHSA-2013-1536.html