Bug 1159651

Summary: virt-sysprep firstboot script is not deleted if it reboot a RHEL 7 guest
Product: Red Hat Enterprise Linux 6 Reporter: j.vandeville
Component: libguestfsAssignee: Pino Toscano <ptoscano>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.6CC: huzhan, jherrman, leiwang, mbooth, ptoscano, rjones, wshi
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.20.11-12.el6 Doc Type: Bug Fix
Doc Text:
Due to an incorrect implementation of the libguestfs firstboot scripts runner, the firstboot scripts logged only the last executed script instead of all executed scripts. In addition, firstboot scripts that cause booting to stop, such as a script that reboots the guest, were unintentionally executed on every boot. These problems have now been fixed.
Story Points: ---
Clone Of:
: 1160043 (view as bug list) Environment:
Last Closed: 2015-07-22 05:56:11 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1160043    

Description j.vandeville 2014-11-02 17:00:03 UTC
Description of problem:

I use a very simple script to update my VM at first boot :

yum clean all
yum -y update
reboot

On rhel6.x guest, the script is deleted but on rhel7 guest, the script is never deleted and the guest is stuck in a infinity loop of reboot. If I remove the "reboot" command, the script is correctly deleted.

Version-Release number of selected component (if applicable):

libguestfs-tools-1.20.11-11.el6.x86_64

Steps to Reproduce:
1. Create a RHEL7 VM on a RHEL6.6 host
2. Create a simple script with the reboot command
3. Use virt-sysprep --enable firstboot --firstboot script.sh -d rhel7_guest
4. Launch the VM

Actual results:

The script is never deleted and the guest is stuck in a infinity loop of reboot

Expected results:

The script should be deleted after its first execution

Additional info:

Comment 2 Pino Toscano 2014-11-03 19:50:46 UTC
This bug is not specific to RHEL guests, but practically on any guest.

Basically, /usr/lib/virt-sysprep/firstboot.sh (which is the helper script created by virt-sysprep/builder/customize to run the first boot scripts) does the following:

  if test "$1" = "start"
  then
    for f in $d/* ; do
      if test -x "$f"
      then
        echo '=== Running' $f '===' 2>&1 | tee $logfile
        $f 2>&1 | tee $logfile
        rm -f $f
      fi
    done
  fi

so, each first boot script is deleted only after it has been completed. Needless to say, if a script does not return then it is not removed, and thus executed again at the next boot.

Patch posted to the mailing list to attempt working around such situations:
  https://www.redhat.com/archives/libguestfs/2014-November/msg00005.html

Comment 3 j.vandeville 2014-11-03 20:52:29 UTC
It's working with RHEL6.X guest. The script is always deleted, even if it reboot the system

Comment 4 Richard W.M. Jones 2014-11-03 22:15:50 UTC
This patch has been accepted upstream and should fix the
issue for all RHEL and other guests:

https://www.redhat.com/archives/libguestfs/2014-November/msg00007.html

Comment 5 Pino Toscano 2014-11-04 08:09:31 UTC
Fixed with upstream commit
https://github.com/libguestfs/libguestfs/commit/f8ed15462fbb03c5b19972361f2a2e6fed4c5f02
which is in libguestfs >= 1.29.5.

Comment 7 Chao Zhang 2014-12-11 06:44:59 UTC
Verify with libguestfs-tools-1.20.11-12.el6.x86_64


Steps to verify:

1. Create a RHEL7 VM on a RHEL6.6 host
#virsh define RHEL-Server-7.0-64-hvm.xml

2. Create a simple script with the reboot command
#cat script.sh
yum clean all
yum -y update
reboot

3. Use virt-sysprep --enable firstboot --firstboot script.sh -d rhel7_guest
#virt-sysprep --enable firstboot --firstboot script.sh -d rhel7_guest

4. Launch the VM
Launch the guest. The script has been deleted after its first execution.

Comment 9 errata-xmlrpc 2015-07-22 05:56:11 UTC
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.

https://rhn.redhat.com/errata/RHBA-2015-1444.html