In order to test joining 3 files linearly on my Linux system, I do:
fallocate -l 100M file1.image
fallocate -l 150M file2.image
fallocate -l 50M file3.image
and then I run losetup
:
losetup /dev/loop1 file1.image
losetup /dev/loop2 file2.image
losetup /dev/loop3 file3.image
I found this script for joining two files:
#!/bin/sh
# Join 2 devices together
size1=`blockdev --getsz $1`
size2=`blockdev --getsz $2`
echo "0 $size1 linear $1 0
$size1 $size2 linear $2 0" | dmsetup create joined
And I start it with
./join.sh /dev/loop1 /dev/loop2
it works with two devices, they are joined together into one:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop1 7:1 0 100M 0 loop
└─joined 253:10 0 250M 0 dm
loop2 7:2 0 150M 0 loop
└─joined 253:10 0 250M 0 dm
I then remove the "joined" device with dmsetup remove joined
and adjust the script for 3 device files:
#!/bin/sh
# Join 3 devices together
size1=`blockdev --getsz $1`
size2=`blockdev --getsz $2`
size3=`blockdev --getsz $3`
echo "0 $size1 linear $1 0
$size1 $size2 linear $2 0
$size2 $size3 linear $3 0" | dmsetup create joined
start it with
./join.sh /dev/loop1 /dev/loop2 /dev/loop3
device-mapper: reload ioctl on joined (253:10) failed: Das Argument ist ungültig
Command failed.
But it fails with the error above. What am I doing wrong?
dmesg
device-mapper: table: 253:10: linear: Gap in table (-EINVAL)
device-mapper: ioctl: error adding target to table
at
I found a way to use mdadm
to join linearly and when I tried it, it works. I did:
dd if=/dev/zero bs=1M count=100 of=a.img
dd if=/dev/zero bs=1M count=50 of=b.img
dd if=/dev/zero bs=1M count=150 of=c.img
losetup -f
/dev/loop0
for i in a b c; do losetup -f $i.img; done
mdadm --build /dev/md0 -l linear -n 3 /dev/loop[012]
mdadm: array /dev/md0 built and started.
cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md0 : active linear loop2[2] loop1[1] loop0[0]
307200 blocks super non-persistent 64k rounding
unused devices: <none>
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 100M 0 loop
└─md0 9:0 0 300M 0 linear
loop1 7:1 0 50M 0 loop
└─md0 9:0 0 300M 0 linear
loop2 7:2 0 150M 0 loop
└─md0 9:0 0 300M 0 linear
Why does the dmsetup
way not work with 3 devices?
What is the difference between the dmsetup
and mdadm
ways?
What is dmsetup
for ...?
And is mdadm
for raid?
Have i done a raid0 with 3 different disk sizes? is that possible?
dmsetup
you did understand, which parts you didn't understand, what other research you have done to understand the parts you didn't understand, and why that failed. That way, you prevent answerers wasting their time and yours by repeating stuff you already know, or repeating stuff you already read and didn't understand.