1

I have a 2TB disk that I have overwritten with random data. fdisk confirms that the device has no recognized partition table. Yet, I see these 5 device files for the disk: /dev/sdc{,1,2,3,4}

i.e.

# for i in /dev/sdc{,1,2,3,4} ; do fdisk -l -u $i ; done

Disk /dev/sdc: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdc1: 555.1 GiB, 595985804288 bytes, 1164034774 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdc2: 1.6 TiB, 1781956913152 bytes, 3480384596 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdc3: 928.5 GiB, 997001973760 bytes, 1947269480 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdc4: 1 TiB, 1153125198336 bytes, 2252197653 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Again, the device has no partition table:

# fdisk /dev/sdc 

Welcome to fdisk (util-linux 2.25.2). 
Changes will remain in memory only, until you decide to write them. 
Be careful before using the write command. 

Device does not contain a recognized partition table. 
Created a new DOS disklabel with disk identifier 0x56b93c1d. 

Command (m for help): p 
Disk /dev/sdc: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors 
Units: sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes / 512 bytes 
I/O size (minimum/optimal): 512 bytes / 512 bytes 
Disklabel type: dos 

Why are there partition devices--i.e. why is there /dev/sdc{1,2,3,4} and not just /dev/sdc? Further, why do the partitioned devices have sizes that do not add up to 1.8TiB?

3

Linux doesn't re-read the partition table except on boot (or disk connect) or when explicitly told to do so (e.g., by fdisk after writing one, or by using partx or blockdev --rereadpt). So until you do one of those, sdc[1-4] will continue to exist.

The easiest fix would be to call partprobe to instruct the kernel to re-read the partition table on all devices, or partprobe /dev/sdc to re-read the partition table only on that disk. Or you could use fdisk to write that empty partition table, then fdisk will do the same thing as partprobe.

Note also that the kernel won't re-read it if the disk (or rather any of its partitions) are in use (e.g., as a filesystem, swap, LVM PV, etc.). Of course, if any were in use, you've got a problem as you just wiped them.

Finally, if you've already tried forcing a reread, it's possible your random data just happens to match a partition table signature. Linux supports a lot of different partition table formats (the list is chosen when compiling the kernel), and the signature on some of them is as small as one byte—so there is a 1/256 chance that random data matches. Others have longer signatures, so much lower chance. I'm not sure what the overall chance is, but a quick check of the kernel logs will show which partition table format the kernel recognized.

  • 1
    I actually had forced a re-read and was seeing the partition device files. I assumed that fdisk (and partx) reporting no partition table eliminated the possibility of a random effect causing the kernel to create partition devices--surprisingly, that is not the case. while true ; do ( readonly x=/dev/sdc ; head -c 311296 /dev/urandom > $x ; blockdev --rereadpt $x ) ; ls /dev/sdc1 && break ; done stops after roughly 8 or 9 iterations on my system (on average). – Lotney Apr 10 '17 at 19:16
  • ...So, I don't understand how fdisk/partx are reporting no partition table, while the kernel is creating partition devices. – Lotney Apr 10 '17 at 19:18
  • 1
    @Lotney Kernel supports a lot more partition table formats than fdisk. Overwriting with 0s should be safe. – derobert Apr 10 '17 at 19:20
  • I see. What bytes is the kernel looking at to make that determination? – Lotney Apr 10 '17 at 19:21
  • @Lotney each format is different, but it's going to be either the first few sectors of the disk, or the last few. You'd have to check the kernel source code to see which bytes exactly, I recall there being dozens of partition table formats... – derobert Apr 10 '17 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.