[fedora-virt] Is it possible to automatically swap CD during Fedora install in KVM?

Cole Robinson crobinso at redhat.com
Thu Mar 11 15:16:50 UTC 2010


On 03/11/2010 08:47 AM, James Laska wrote:
> On Thu, 2010-03-11 at 16:24 +0800, Li Ming wrote:
>> Hi,
>>
>>      I want to use python to write an auto-test script to test fedora 
>> install CD in KVM,my idea is: use virt-install to create a guest with 
>> arguments --cdrom FedoraCD.iso, then the guest will boot with CD,with 
>> the kickstart or something, the install will automatically 
>> continue,after CD1 is finished, the anaconda will prompt to insert CD2, 
>> I want all this automatic,meaning my script should detect the CD1 
>> completed,and then swap to CD2, then the install continue. Is this 
>> possible for libvirt? I have successfully written a script to do DVD 
>> text install(totally imitate DVD install),you can see it at[1], I know 
>> for CD,it's a challenge,you suggestion is very important to me.
>>
>> *[1] 
>> http://git.fedorahosted.org/git/autoqa.git?p=autoqa.git;a=blob;f=tests/anaconda/dvd_install.py;h=5bcd3500cb724ac49753619e83911a034435cb3e;hb=5e78f629dc6b8315812585ba9d5b4801145fb5f7
> 
> One approach, which might not reflect how users really install using CD
> media, would be to attach all CD media required to the guest during the
> install.  The installer will always check the attached optical devices
> for the disc it's looking for before prompting the user.  I've done this
> in the past, but it has the limitation that you can only attach a
> certain number of IDE CDROM devices to the guest at a time.
>
> With Xen, there was the xenstore-write command which could be used to
> change the ISO used for an attached block device.  I'm not sure if there
> is a similar command using just libvirt?
> 

This can be done with libvirt/virsh, it's just unintuitive. Say your VM has a
<disk> block like:

    <disk type='file' device='cdrom'>
      <driver name='qemu'/>
      <target dev='hdc' bus='ide'/>
      <source file='/some/path/to/media.iso'/>
      <readonly/>
    </disk>

Copy that into its own file (say, 'test.xml') and change the <source> line so
it looks like:

    <disk type='file' device='cdrom'>
      <driver name='qemu'/>
      <target dev='hdc' bus='ide'/>
      <source file='/some/path/to/NEWMEDIA.iso'/>
      <readonly/>
    </disk>

Then for the running VM, use:

virsh attach-device VMNAME test.xml

Full on removing the <source> line will leave the CDROM empty, you still need
to use 'attach-device' though. We should really have a convenience command
'eject' or something like that.

- Cole


More information about the virt mailing list