Guide to boot from iscsi in libvirt's virt-manager (ibft)

I could not found anywhere online some guide on how to set-up a virtual environment in virt-manager with iscsi boot.
So here it is.

1- Setup an iscsi environment

Example setup:

In this example we are using a distant baremetal machine as iscsi server (target) for the sake of simplicity, so we can use default networking option (NAT) in virt-manager. We could also install it on localhost but we’d have to tweak the network, as NAT does not let us access services on the VM’s host. We will call this distant machine the_iscsi_target.

So, on the_iscsi_target:

  • install the package “tgt”
  • create a 20G file that will be used as virtual disk:
dd if=/dev/zero of=/opt/iscsi bs=1G count=20
  • put this into /etc/tgt/conf.d/iscsi-target.conf:
<target iqn.2016-02.openqa.de:for.openqa>
        backing-store /opt/iscsi-disk
</target>

(iqn.2016-02.openqa.de:for.openqa is just for example, but will work as-is if you want).

  • Start the iscsi server as follows:
nohup /usr/sbin/tgtd  && tgt-admin --update ALL --force ; while pgrep tgtd &> /dev/null; do sleep 100; done &
  • Open port 3260 in firewall.
  • From another machine, verify that your setup works:
$ iscsiadm --mode discovery -t sendtargets --portal the_iscsi_target

Should return:

IP_OF_the_iscsi_target:3260,1 iqn.2016-02.openqa.de:for.openqa

2 - Setup virt-manager to use IPXE

  • Download http://boot.ipxe.org/ipxe.iso (easy way) or compile it following the instructions here: iPXE - open source boot firmware [download] (can be useful if we suspect something does not work with the current stable release).
  • Mount the iso or extract the files.
  • in virt-manager, go to boot options, activate direct kernel boot button, in kernel path indicate the path to the file ipxe.lkrn from the iso that you mounted or extracted, in kernel arguments put

dhcp && sanhook iscsi:IP-OR-HOSTNAME-OF-the_iscsi_target::3260:1:iqn.2016-02.openqa.de:for.openqa

  • Start the VM, for several seconds you should see the IPXE screen
  • once in grub, add the following parameter: withiscsi=1.

3 - Use the installed system

After installation we should be able to boot in the system by using “boot from hard disk” option in the cdrom’s bootloader,

OR

replace

dhcp && sanhook iscsi:IP-OR-HOSTNAME-OF-the_iscsi_target::3260:1:iqn.2016-02.openqa.de:for.openqa

by

dhcp && sanboot iscsi:IP-OR-HOSTNAME-OF-the_iscsi_target::3260:1:iqn.2016-02.openqa.de:for.openqa

The argument “sanhook” attaches the iscsi volume but does not try to boot from it. It is necessary if you want to boot from cdrom. The sanboot argument, in the contrary, makes you boot directly to the iscsi volume and does not allow you to use the cdrom.

Documentation:

The documentation for ibft is unfortunately sparse. I found not much online to achieve this. but here is something:

http://etherboot.org/wiki/commandline