Last month I installed Ubuntu 12.04 LTS on KVM, but the VM cannot mount any iSCSI partition after successful installation. After googling, I made a solution, mounting kvm image file, modifying a network script file, and then re-create the initial ramdisk file. Hereby is my notes with script.
A script to (un-)mount kvm image
#!/bin/sh
case “$1” in
start)
losetup /dev/loop0 ~sammy/mykvm.img
kpartx -av /dev/loop0
mount /dev/mapper/loop0p1 /mnt/
mount -o bind /dev /mnt/dev
mount -o bind /proc /mnt/proc
chroot /mnt/
;;
stop)
umount /mnt/dev
umount /mnt/proc
umount /mnt/
kpartx -dv /dev/loop0
losetup -d /dev/loop0
;;
esac
Mount iSCSI partition with open-iscsi:
$ ip addr add 192.168.0.3/24 dev eth0
$ ip link set dev eth0 up
$ route add default gw 192.168.0.1
$ modprobe iscsi-tcp
$ iscsid -f &
$ iscsiadm -m discovery
$ iscsiadm -m node -T iqn.123313133:myvol-1234-5678-90 -p 192.168.0.2 –login
$ mount /dev/sdb1 /mymountpt
done.
Viewing existing initial RAMdisk content
$ cp /boot/initrd.img /boot/initrd.gz
$ gunzip /boot/initrd.gz
$ mkdir -p /tmp2; cd /tmp2
$ cpio -id < /boot/initrd
Re-generating an initial RAMdisk file:
$ vim /usr/share/initramfs-tools/scripts/local-top/iscsi
$ mkinitramfs -o /boot/sammy-initrd.img
Notes to static IP required hosts, you can add the following lines before configure_networking at try_configure_networking()
# eth1
ip addr add 192.168.0.2/24 dev eth0
ip link set dev eth0 up
touch /tmp/net-eth0.conf
Reference:
https://bugs.launchpad.net/ubuntu/+source/open-iscsi/+bug/1033498
https://launchpadlibrarian.net/112095602/Ubuntu-iscsi.patch
https://bugs.launchpad.net/ubuntu/+source/partman-iscsi/+bug/1047998