为了以线性模式连接 Linux 文件/设备,我有这个dm-joinlinear.sh
脚本
在 Linux 系统中以线性模式将文件/设备连接在一起,感谢 telcoM
#!/bin/sh
usage() {
echo "Usage: ${0##*/} <target name> <component...>" >&2
exit 64 # EX_USAGE
}
if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "-?" ] || [ "$1" = "--help" ]
then
usage
fi
if [ -e "/dev/mapper/$1" ]
then
echo "ERROR: target $1 already exists." >&2
exit 73 # EX_CANTCREAT
fi
MAPNAME="$1"
shift
DMMAP=$(mktemp)
trap "rm -f $DMMAP" EXIT
sum=0
while [ "$1" != "" ]
do
if [ ! -e "$1" ]
then
echo "ERROR: $1 does not exist"
exit 66 # EX_NOINPUT
fi
if [ ! -b "$1" ]
then
echo "ERROR: $1 is not a block device"
exit 69 # EX_UNAVAILABLE
fi
srcN="$1"
sizeN=$(blockdev --getsz "$srcN")
echo "$sum $sizeN linear $srcN 0" >>$DMMAP
sum=$(expr $sum + $sizeN)
shift
done
dmsetup create $MAPNAME < $DMMAP
我运行脚本
./dm-joinlinear.sh one /dev/loop? /dev/loop??
或者
./dm-joinlinear.sh one /dev/mapper/file? /dev/mapper/file??
/dev/loop0 and /dev/mapper/file1 are the same
/dev/loop1 and /dev/mapper/file2 are the same
....
/dev/loop32 and /dev/mapper/file33 are the same
我可以使用以下脚本运行
dm-joinlinear.sh one /dev/loop[0-9] /dev/loop[1-2]? /dev/loop3[0-2]
或者
dm-joinlinear.sh one /dev/loop0 /dev/loop1 /dev/loop2 .... and so on up to /dev/loop32 (to long to write all down here all)
或者与删除“循环”并使用 mapper/file 相同,但从 1 开始而不是从 0 开始
我更喜欢使用 /dev/mapper/file 而不是 /dev/loop
但是我该如何表示dm-joinlinear.sh
他们必须加入多少台设备?值是parts.txt