4

I have a iscsi disk 2TB large. I make backup of that disk every week. The backup script copies the image of the whole iscsi disk into a file on my NFS. Unfortunately, it does not copy the image in one piece, but splits it into chunks 1TB in size. So in my case, I have two 1TB files (plus one config file):

-r--r----- 1 root root 1099511627776 May 10 02:12 Backup-LUN-itmp-lun-0.000
-r--r----- 1 root root 1099500093440 May 10 03:50 Backup-LUN-itmp-lun-0.001
-rw-r--r-- 1 root root           251 May 10 03:50 Backup-LUN-itmp-lun-0.conf

Now I need to access my backup. Normally, if it was one file, I would map it to /dev/loop0 and then mount it as normal disk. But in my case, I cannot map two files to /dev/loop0. One option would be to cat those two files to create one large file, but I don't have extra 2TB space, and besides this is not a good solution anyway.

Can somebody please suggest a solution?

UPDATE

I have tried using dmsetup with linear target, as suggested by Andreas Wiese, but I get following error.

dmsetup create my-backup << EOF
> 0 2147483648 linear Backup-LUN-itmp-lun-0.000 0
> 2147483648 2147461120 linear Backup-LUN-itmp-lun-0.001 0
> EOF
device-mapper: reload ioctl on my-backup failed: Invalid argument
Command failed

dmesg contains following error:

device-mapper: table: 254:0: linear: dm-linear: Device lookup failed
device-mapper: ioctl: error adding target to table
1

1 Answer 1

8

What you want to do could be accomplished using Device Mapper (to be configured via dmsetup(8)). If the data in the two files is really a linear dump of your volume, you could create a DM device composed of several block devices which you could create from the files from loop-devices, similar to this:

# losetup /dev/loop0 /path/to/Backup-LUN-itmp-lun-0.000
# losetup /dev/loop1 /path/to/Backup-LUN-itmp-lun-0.001
# size1=$(blockdev --getsz /dev/loop0)
# size2=$(blockdev --getsz /dev/loop1)
# dmsetup create my-backup << EOF
0 $size1 linear /dev/loop0 0
$size1 $size2 linear /dev/loop1 0
EOF

This reads a table describing your DM device from stdin and creates a block-device called /dev/mapper/my-backup which you should be able to use like any other block-device.

The table format is

<start-sector> <length> <target> <target-args>

<start-sector> and <length> describe start and length (in sectors of 512 bytes) of a part of your DM device, <target> would be linear for, well, linear assembly. The arguments for the linear target are the device to use and the offset inside the device (so if for example your backup software writes some kind of header in front of the dump you could skip this), in this example it's 0 which would be appropriate for a raw dump.

Thus the above example assembles the my-backup device so that the first part is mapped from Backup-LUN-itmp-lun-0.000 (via loop0) and the second part from Backup-LUN-itmp-lun-0.000 (via loop1).

In case your backup isn't just a linear dump (like using dd and splitting the output into multiple files) you could try to get lucky with the other DM targets.

Edit: DM only maps block devices, not files, so added the losetup part. With this you could also use blockdev --getsz and won't have to worry about sizes, as the example shows.

4
  • I get an Invalid argument error, please see my update. Also, how do I get the correct sector numbers? Just divide the bytes by 512 ? Commented May 11, 2014 at 14:56
  • Yes, as long as the files are multiples of 512 bytes, dividing the size by 512 bytes would be correct. Sorry, I had the second line in the table wrong. As explained in the text the second argument is the length of the mapping itself, so in your case it would be 2147461120. I edited my answer accordingly. Commented May 11, 2014 at 15:11
  • dmesg contains dm-linear: Device lookup failed. Could it be that I am missing something in my (custom build) kernel? I have Device mapper support compiled in, and crypt target as well. But I don't see linear target option anywhere in menuconfig. Commented May 11, 2014 at 15:11
  • Sorry, I messed it up. See update, now it should hopefully be complete (even without the need to calculate sizes by hand). linear target is supported if device mapper support is enabled, it's a default target of DM. Commented May 11, 2014 at 15:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.