Frage

I am booting a virtual machine on Fedora 18 with qemu-kvm utility using following command.

qemu-kvm -m $MEMORY -net nic -net tap,ifname=tap0,script=no -drive file=ubuntu.img,index=0,media=disk,format=raw 

Is there a way to pass a script to VM at its boot time that runs after VM has launched.

I have searched out help for qemu-kvm but it does not provide any relevant information.

War es hilfreich?

Lösung

First of all, this is not about the KVM but the guest OS bootstrap. it should know nothing inside the guest OS when using KVM, for example, if the OS is booted or not.

There are 2 questions in this context:

  1. how it provide script or data from KVM hypervisor to the guest OS?
  2. how to activate a script at guest OS boot time?

According to question #1, you can use disk or network. for example, it you append additional disk/iso/vfat file to your VM so that it can be found inside the guest OS.

You can find lots of ways to run a script at Linux boot time.

As a summary, you can use cloud-init and its config drive extension.

Steps

  1. Use ubuntu cloud images which contains cloud-init already as your image instead of your ubuntu.img. Or make your own image with cloud-init installed via command sudo apt-get install cloud-init

  2. prepare a vfat or iso file by following the config drive spec. then append this line to your qemu-kvm command:

qemu-kvm -m $MEMORY -net nic -net tap,ifname=tap0,script=no -drive file=ubuntu.img,index=0,media=disk,format=raw -cdrom <your-config-drive-iso-file>.iso

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top