blkid: need to determine whether it is "safe" to overwrite a block device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I have a script that is supposed to automatically overwrite the contents
of the block device. Before the script does so, it performs a sanity
check: If the device contains anything valuable, it should not overwrite
anything:

/sbin/blkid -p "${device}" &>/dev/null
if [[ $? -eq 2 ]]; then
  # Nothing here, it is okay to overwrite
  do_evil_things "${device}"
fi

The reasons for using -p:
1) I do not want to check the cache, I only want to look at the device
itself.
2) -p will also return the PTTYPE=... value, so I don't accidently
overwrite a whole disk's partition table and contents.

While 2) is undocumented, it is another undocumented "feature" that bugs
me: If there is no file system, raid superblock or similar found, then
blkid will probe the partition table type, and output something like this:
PART_ENTRY_SCHEME="dos" PART_ENTRY_NUMBER="1"
It will return "0" (success), even though the partition did not contain
any file system (or anything else).

I think this behaviour is wrong for three reasons:
1) It is undocumented (at least in the manpage).
2) It cannot be altered (for example by the -u flag).
3) It has nothing to do with the _contents_ of the block device (which I
am interested in), but the context where the block device lies (which I
am not interested in).

I would wish I could have a way to use blkid in a way, such that I will
be able to determine (through its return value) whether a device
contains any known file system, raid superblock, partition table, ... -
anything I would not want to overwrite.

Regards
Thomas

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux