lkml.org 
[lkml]   [2003]   [Jul]   [18]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
SubjectRE: Partitioned loop device..
FromChristophe Saout <>
Date18 Jul 2003 16:20:27 +0200
Am Di, 2003-07-15 um 20.32 schrieb Dimitry V. Ketov:

> > You can already use Device-Mapper to create "partitions" on 
> > your loop devices, 
> You're right but I want _partitions_ but not "partitions" ;)
> It should appears like a real hardware disk, not virtual one.

I just hacked up an ugly small shell script, that uses sfdisk and
dmsetup to create the partition devices over any block device.

Just dmsetup-partitions /dev/loop0 or something.

It will then create devices /dev/mapper/loop0p1, etc... just like hda1
and so on. To remove them use "dmsetup remove loop0p1", etc...

--
Christophe Saout <christophe@saout.de>
Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
#!/bin/sh
SFDISK="`which sfdisk`"
DMSETUP="`which dmsetup`"
if test -z "$1"; then
	echo "Syntax: $0 <block device>"
	exit 1
fi
DEVDIR="`dirname \"\$1\"`"
DEVFILE="`basename \"\$1\"`"
if ! echo "$DEVDIR" | grep '^/' &> /dev/null; then
	DEVDIR="`pwd`/$DEVDIR/"
else
	DEVDIR="$DEVDIR/"
fi
while echo "$DEVDIR" | grep '/\./' &> /dev/null; do
	DEVDIR="`echo \"\$DEVDIR\" | sed -e 's/\/\.\//\//g'`"
done
while echo "$DEVDIR" | grep '/[^/][^/]*/\.\./' &> /dev/null; do
	DEVDIR="`echo \"\$DEVDIR\" | sed -e 's/\/[^/][^/]*\/\.\.\//\//g'`"
done
DEVICE="$DEVDIR$DEVFILE"
if ! test -b "$DEVICE" -a -r "$DEVICE"; then
	echo "Error: Block device $1 can't be accessed"
	exit 1
fi
if ! test -n "$SFDISK" -a -x "$SFDISK"; then
	echo "Error: sfdisk utility not found"
	exit 1
fi
if ! test -n "$DMSETUP" -a -x "$DMSETUP"; then
	echo "Error: dmsetup utility not found"
	exit 1
fi
if test -L "$DEVICE"; then
	DEVICE_="`readlink \"\$DEVICE\"`"
	DEVDIR_="`dirname \"\$DEVICE_\"`"
	DEVFILE_="`basename \"\$DEVICE_\"`"
	if ! echo "$DEVDIR_" | grep '^/' &> /dev/null; then
		DEVDIR_="$DEVDIR$DEVDIR_/"
	else
		DEVDIR_="$DEVDIR_/"
	fi
	while echo "$DEVDIR_" | grep '/\./' &> /dev/null; do
		DEVDIR_="`echo \"\$DEVDIR_\" | sed -e 's/\/\.\//\//g'`"
	done
	while echo "$DEVDIR_" | grep '/[^/][^/]*/\.\./' &> /dev/null; do
		DEVDIR_="`echo \"\$DEVDIR_\" | sed -e 's/\/[^/][^/]*\/\.\.\//\//g'`"
	done
	DEVICE_="$DEVDIR_$DEVFILE_"
else
	DEVICE_="$DEVICE"
fi
TMP="/tmp/partscript.$$"
"$SFDISK" -d "$DEVICE" | grep "^ *$DEVDIR" | sed -e 's/[=,]/ /g' | awk '{ print $1 " " $4 " " $6 }' | \
while read DEV START SIZE; do
	DEV="`echo \"\$DEV\" | sed -e 's/^\/dev\///' -e 's/\//-/g'`"
	test "$SIZE" -gt 0 || continue
	echo $DEV $START $SIZE
	echo "0 $SIZE linear $DEVICE_ $START" > $TMP
	"$DMSETUP" create $DEV $TMP
done
\
 
 \ /
  Last update: 2005-03-22 12:46    [from the cache]
©2003-2008