All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Saout <christophe@saout.de>
To: "Dimitry V. Ketov" <Dimitry.Ketov@avalon.ru>
Cc: linux-kernel@vger.kernel.org
Subject: RE: Partitioned loop device..
Date: 18 Jul 2003 16:20:27 +0200	[thread overview]
Message-ID: <1058538027.19986.3.camel@chtephan.cs.pocnet.net> (raw)
In-Reply-To: <E1B7C89B8DCB084C809A22D7FEB90B3840AB@frodo.avalon.ru>

[-- Attachment #1: Type: text/plain, Size: 743 bytes --]

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

[-- Attachment #2: dmsetup-partitions --]
[-- Type: text/x-sh, Size: 1784 bytes --]

#!/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

  parent reply	other threads:[~2003-07-18 14:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-15 18:32 Partitioned loop device Dimitry V. Ketov
2003-07-15 21:15 ` Lars Marowsky-Bree
2003-07-18 14:20 ` Christophe Saout [this message]
2003-07-18 19:10   ` Mr. James W. Laferriere
2003-07-18 23:57     ` Christophe Saout
  -- strict thread matches above, loose matches on Subject: below --
2003-07-16  8:59 Dimitry V. Ketov
2003-07-16 13:51 ` Kevin Corry
2003-07-15  8:46 Dimitry V. Ketov
2003-07-15 15:01 ` Kevin Corry
2003-07-15 15:53   ` Josh Litherland
2003-07-15 16:04     ` Kevin Corry
2003-07-15 16:05     ` Herbert Pötzl
2003-07-17  2:44     ` kernel
2003-07-15  7:10 Dimitry V. Ketov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1058538027.19986.3.camel@chtephan.cs.pocnet.net \
    --to=christophe@saout.de \
    --cc=Dimitry.Ketov@avalon.ru \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.