diskparts: list disk partitions, including any ext2 labels
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Tue Mar 2 05:59:56 UTC 2004
On Mon, Mar 01, 2004 at 09:21:01PM -0500, D. Hugh Redelmeier wrote:
>
> I often upgrade the OS on a machine by installing a new version of the OS.
> When planning to do this, I often want a hard-copy of the partition layout
> as a worksheet.
>
> fdisk -l doesn't tell me quite enough: I'd like to know what is on the
> partitions. I label all my ext[23] partitions, but the labels don't show
> up in the fdisk output.
>
> Generally, I do an fdisk -l and then scrible on the results. As a
> labour-saving device, I've just written a script to do the annotation
> automatically.
>
> I'm posting it here to get some feedback:
> - do you find this useful?
> - what would you add to this?
> - is there a simpler way?
>
> Hugh Redelmeier
> hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org voice: +1 416 482-8253
>
> #!/bin/sh
>
> # diskparts: list disk partitions, including any ext2 labels
> # Synopsis: disparts [drive]...
> # D. Hugh Redelmeier 2004 March 1
>
> set -u
>
> # default to /dev/hda
> case "$#" in
> 0) set - /dev/hda
> ;;
> esac
>
> for drive
> do
> # oddity: the each line of the fdisk output is prepended with a backslash
> # to prevent any leading whitespace being discarded by the sh read command.
>
> /sbin/fdisk -l "$drive" | sed -e 's/^/\\/' |
> while read line
> do
> case "$line" in
> *Linux)
> vol=` echo "$line" | sed -e 's/ .*//' `
> lab=` /sbin/e2label "$vol" 2>/dev/null || echo '???'`
> line="$line: $lab"
> ;;
> esac
> echo "$line"
> done
> done
It seems to me, you're appending ext2 label or '???' to those partition
with 'Linux' tag. But, 'fdisk -l' will print out all known partitions
(/proc/partitions), so use that.
fdisk -l | awk '{print $1 ":" $0}' | while IFS=':' read vol line; do
case $line in
*Linux) echo "$line:" `e2label $vol 2>/dev/null || echo '???'` ;;
*) echo "$line" ;;
esac
done
or just go for the throat,
fdisk -l | awk '/Linux$/ {print $1}' | while read vol; do
echo "$vol:" `e2label $vol 2>/dev/null || echo '???'`
done
--
William Park, Open Geometry Consulting, <opengeometry-FFYn/CNdgSA at public.gmane.org>
Linux solution for data management and processing.
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list