[virt-tools-list] Scripting virt-install to automate image building

Anthony Shortland anthony.shortland at me.com
Tue Jan 21 07:36:19 UTC 2014


Hi Cole,

You're quite right, it was a poweroff issue. Well done! Once I realized that it's critical for the domain to end up in "shut off" state in order for virt-install to exit, things all fell into place.

Here's what I ended up with virt-install wise:

[root at oel63-virt tmp]# virt-install --name=minimal --ram=512 --vcpus=1 --accelerate --hvm --network network:default --disk=/var/lib/libvirt/images/minimal.img,size=3 --location=http://192.168.122.1/OracleLinux-R6-U3-Server-x86_64-dvd --graphics=none --noautoconsole --wait=-1 --noreboot --serial=file,path=/tmp/minimal.log --initrd-inject=/tmp/minimal-ks.cfg '--extra-args=ks=file:/minimal-ks.cfg console=ttyS0'

Starting install...
Retrieving file .treeinfo...                                                               | 3.0 kB     00:00 ... 
Retrieving file vmlinuz...                                                                 | 7.6 MB     00:00 ... 
Retrieving file initrd.img...                                                              |  58 MB     00:00 ... 
Allocating 'minimal.img'                                                                   | 3.0 GB     00:00     
Creating domain...                                                                         |    0 B     00:00     
Domain installation still in progress. Waiting for installation to complete.
.
.
.

Checking the domain state during installation:

[root at oel63-virt tmp]# virsh list --all
Id    Name                           State
----------------------------------------------------
52    minimal                        running


It is critical to make sure that the "poweroff" option is specified in Kickstart culminating in logging: 

.
.
.
powering off system
Power down.

... so that virt-install automatically exits with:

.
.
.
Domain has shutdown. Continuing.
Domain creation completed. You can restart your domain by running:
 virsh --connect qemu:///system start minimal
[root at oel63-virt tmp]# echo $?
0

... leaving the domain "shut off" state:

[root at oel63-virt tmp]# virsh list --all
Id    Name                           State
----------------------------------------------------
-     minimal                        shut off

Thanks for all your help,

Anthony.

> On Jan 20, 2014, at 6:45 AM, Cole Robinson <crobinso at redhat.com> wrote:
> 
>> On 01/19/2014 05:05 PM, Anthony Shortland wrote:
>> Hi Cole,
>> 
>> Thanks for the suggestions. Here's where I'm at now:
>> 
>> [root at oel63-virt tmp]# virt-install --name=minimal --ram=512 --vcpus=1
>> --accelerate --hvm --network network:default
>> --disk=/var/lib/libvirt/images/minimal.img,size=3
>> --location=http://192.168.122.1/OracleLinux-R6-U3-Server-x86_64-dvd --graphics=none
>> --noautoconsole --wait=-1 --serial=file,path=/tmp/minimal.log
>> '--extra-args=ks=http://192.168.122.1/kickstart/minimal-ks.cfg console=ttyS0'
>> 
>> Starting install...
>> Retrieving file .treeinfo...
>>                                                                                |
>> 3.0 kB     00:00 <x-apple-data-detectors://5> ... 
>> Retrieving file vmlinuz...
>>                                                                                  |
>> 7.6 MB     00:00 <x-apple-data-detectors://7> ... 
>> Retrieving file initrd.img...
>>                                                                               |
>> 58 MB     00:00 <x-apple-data-detectors://8> ... 
>> Allocating 'minimal.img'
>>                                                                                    |
>> 3.0 GB     00:00 <x-apple-data-detectors://10>     
>> Creating domain...
>>                                                                                          |
>>   0 B     00:00 <x-apple-data-detectors://11>     
>> Domain installation still in progress. Waiting for installation to complete.
>> 
>> ... I added "--serial=file,..." in order to log in the install, which ends as
>> follows:
>> 
>> .
>> ,
>> .
>> terminating anaconda...done
>> sending termination signals...done
>> sending kill signals...Done
>> disabling swap...
>>       /dev/dm-1
>> unmounting filesystems...
>>       /mnt/runtime done
>>       disabling /dev/loop0
>>       /dev/pts done
>>       /selinux done
>>       /mnt/sysimage/boot done
>>       /mnt/sysimage/dev/pts done
>>       /mnt/sysimage/dev/shm done
>>       /mnt/sysimage/dev done
>>       /mnt/sysimage/proc/bus/usb done
>>       /mnt/sysimage/proc done
>>       /mnt/sysimage/sys done
>>       /mnt/sysimage/selinux done
>>       /mnt/sysimage done
>> waiting for mdraid sets to become clean...
>> halting system
>> System halted.
>> 
>> ... the new Linux system is halted since I included the "shutdown"
>> (http://fedoraproject.org/wiki/Anaconda/Kickstart#shutdown) option in the
>> Kickstart file, but virt-install still does not exit.
>> 
>> What event signals completion of domain installation? How can it be triggered
>> from within the guest (which has the thread of execution with Kickstart)? Or
>> do I need to wrap all this in a script, set wait=0, track the logged output
>> and use some sort of virsh command to signal domain installation completion?
> 
> Maybe it's some halt vs poweroff issue? Not sure.
> 
> https://stackoverflow.com/questions/15460754/halt-and-poweroff
> 
> Try sticking a 'shutdown' at the end of your kickstart?
> 
> Whatever the issue is, it's unlikely a virt-install or libvirt issue, since
> they aren't in play if the VM tries to shut itself down.
> 
> Watching the serial output was only a suggestion if you can't get the VM to
> shutdown on its own, typically that shouldn't be required.
> 
> - Cole
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20140120/c4dd0502/attachment.htm>


More information about the virt-tools-list mailing list