Subject: bug#21877: [parted-Bugs][313055] fdisk -l is not as read-only as I'd hoped

From: <[email-masked]>
Date: Wed, 11 Nov 2015 13:30:45 +0000

parted-Bugs item #313055 was changed at 2015-11-11 13:30 by Gareth Randall
You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=410685&aid=313055&group_id=30287

Status: Open
Priority: 3
Submitted By: Edward Welbourne (eddy-guest)
Assigned to: Nobody (None)
Summary: fdisk -l is not as read-only as I'd hoped 
Category: Unspecified
Group: Version &lt; 1.6.25
Resolution: None

Initial Comment:
I have a partition I made ages ago, that I've not been using - and I've forgotten which file-system type I put on it (if any).  I initially supposed I'd used ext3 (since that's what I used for all the *other* partitions created at the same time) but mounting it as such failed, saying it wasn't an ext3 partition.
So I googled and found http://nst.sourceforge.net/nst/docs/user/ch04s03.html which suggested using fdisk -l; the man page said it lists the partition table on a device - which sounded promising.
However (once I'd duly logged in as root to have sufficient privilege ...), when I ran fdisk -l on it, (after its copyright preamble) it said: <quote>

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Disk /dev/dm-1: 740 GB, 740135370240 bytes
255 heads, 63 sectors/track, 89983 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks   Id  System
</quote>
... and "Building a new DOS disklabel." definitely comes under the heading of unwanted behaviour vigorously in conflict with the principle of least surprise.  I thought I was running a read-only command - I do not have delusions of knowing what I'm doing, so I start by gathering information using commands that won't mess with things, until I've satisfied myself that I have enough of a clue that it's not entirely stupid to try what I think I should do next.  Having one of my information-gathering commands make changes was a scary shock.

Now, OK, it's only made changes in memory, so it hasn't *really* changed the device, but all the same it's not really appropriate for a "list the contents" command to *modify* the thing it's meant to be listing.
Being a complete innocent, as concerns disk partitioning, I'm left in the unpleasant situation of not knowing what to do about the "in memory" disk label that I don't want and probably (but I don't know) need to get rid of if I want to find out what's actually there.  So the fact that it's only in memory is *not* entirely harmless !  (The message could beneficially be expanded to say what I need to do to tell fdisk to undo the in-memory changes, i.e. restore the status quo ante, in whatever situations it *is* appropriate for it to take this action and produce this message.)

(... and, of course, producing the headers for a table, when there's no data to put under them as a table, is a waste of output.  But that really is harmless.)

fdisk -v says: <quote>
GNU Fdisk 1.2.4
</quote>

----------------------------------------------------------------------

Comment By: Gareth Randall (gareth-guest)
Date: 2015-11-11 13:30

Message:
This is the bug list for the parted program, not fdisk, so can this bug be closed?

(However, I agree with your view that fdisk's "Building a new DOS disklabel" is worrying when you first see it.)

----------------------------------------------------------------------

You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=410685&aid=313055&group_id=30287