---
title: Mounting KVM image file for open-iscsi modification
url: https://sammy.hk/mounting-kvm-image-file-for-open-iscsi-modification/
author: Sammy Fung
published: 2013-01-10T22:39:46+08:00
modified: 2021-06-01T00:43:14+08:00
description: "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, mo…"
categories: ["開放源碼"]
tags: [ubuntu]
source: https://sammy.hk
---
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 &amp;
$ 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 &lt; /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://launchpadlibrarian.net/112095602/Ubuntu-iscsi.patch)
[ https://bugs.launchpad.net/ubuntu/+source/partman-iscsi/+bug/1047998](< https://bugs.launchpad.net/ubuntu/+source/partman-iscsi/+bug/1047998>)

### 相關文章：

1. [成功在 notebook 的 Ubuntu 上設定 Compiz 3D compositing](https://sammy.hk/%e6%88%90%e5%8a%9f%e5%9c%a8-notebook-%e7%9a%84-ubuntu-%e4%b8%8a%e8%a8%ad%e5%ae%9a-compiz-3d-compositing/ "成功在 notebook 的 Ubuntu 上設定 Compiz 3D compositing")
2. [F-Spot 與我的 Gallery 相簿](https://sammy.hk/f-spot-%e8%88%87%e6%88%91%e7%9a%84-gallery-%e7%9b%b8%e7%b0%bf/ "F-Spot 與我的 Gallery 相簿")
3. [Ubuntu 7.10 在我的 P30 上閃屏問題](https://sammy.hk/ubuntu-710-%e5%9c%a8%e6%88%91%e7%9a%84-p30-%e4%b8%8a%e9%96%83%e5%b1%8f%e5%95%8f%e9%a1%8c/ "Ubuntu 7.10 在我的 P30 上閃屏問題")
4. [\[Presentation\] My Linux Experience: Ubuntu on netbook](https://sammy.hk/ubuntuonnetbook/ "[Presentation] My Linux Experience: Ubuntu on netbook")
