Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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  
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Hi Even, i have tried that already and get: mount -o loop,offset=512 -t ext4 Skrivbord/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 –  user78270 Apr 13 '11 at 13:09
    
Try an offset of 31232. I suspect that'll get you what you're looking for. –  Evan Anderson Apr 13 '11 at 13:24
    
That worked perfectly, could you please show me the math of that calculation? :) Thanks! –  user78270 Apr 13 '11 at 14:37
    
@user78270: I just used my gut and guessed. By default most Linux distro's fdisk will start the first partition on the first sector of the first cylinder of the second head of the disk. Since the "geometry" of this disk was 61 sectors per track I multiplied 61 by 512 to get the offset of the first sector of the second head of the disk, which came out to 31232. –  Evan Anderson Apr 13 '11 at 16:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.