Mounting image files created for iSCSI target daemon

disk-imageiscsimount

I have recently installed a iSCSI environment on a Ubuntu Server. In this system i have used images created with the following command:

dd if=/dev/zero of=/storage/lun1.img bs=1024k count=20000

as seen on: http://www.howtoforge.com/using-iscsi-on-ubuntu-9.04-initiator-and-target

They have then been partitioned and formated via the iSCSI initiator.

The problem i have now is that i would like to mount these images, if the iSCSI server goes down to get the data.

How do I mount these image files?


fdisk lun4.img:

Disk lun4.img: 0 MB, 0 byte  
33 heads, 61 sectors/track, 0 cylinders  
Units = sectors of 2013 · 512 = 1030656 byte  
Sector size (logical/physical): 512 bytes / 512 bytes  
I/O size (minimum/optimal): 512 bytes / 512 bytes  

Device Boot     Start        End     Blocks    Id  System  
lun4.img1               1        1017     1023580   83  Linux

mount -o loop,offset=512 -t ext4 lun4.img /mnt

mount: wrong fs type, bad option, bad superblock on /dev/loop0,  
missing codepage or other error  
In some cases useful info is found in syslog - try  
dmesg | tail or so  

Best Answer

Assuming they're formatted with a filesystem your kernel supports you can mount them by using a loopback mount. A loopback mount allows you to mount a file as though it's a block device.

If you've partitioned the virtual "disks" that the image files represent you'll have to do some hackery with the mount command to loopback mount the filesystems in the partitions. You can see what I'm talking about in this article. Basically, you're telling the mount command to seek a specified offset into the file. That offset corresponds to the starting location of the partition inside the file.

Related Topic