0

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  
Evan Anderson
  • 141,881
  • 20
  • 196
  • 331
user78270
  • 3
  • 1
  • 3

2 Answers2

1

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.

Evan Anderson
  • 141,881
  • 20
  • 196
  • 331
  • 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
1

With fdisk, "virtualdiskname".img then "p", start sector per track info can be checked (in my case, starts = 48). Then with "v", the sector size can be checked and after your formula the result can be used to offset value:

[sector per track] * [sector size] = offset value

mount -o loop,offset=result -t ext4 virtualdiskname.img /mount-folder
Guest
  • 11
  • 1
  • This does not answer the question. Once you earn enough reputation, you can comment on the answer. – Jim G. Dec 22 '15 at 23:02