2

I used a dd command to write directly to /dev/sdc (an externally mounted hdd 1TB size) to test various writing speeds in a raw mode. (I don't care about any data on the disk). Now the size of the disk as reported by fdisk or gparted is the size of the data I wrote, and I cannot figure out how to get the full disk size back.

The command I used was:

dd if=/dev/urandom of=/dev/sdc bs=4096 count=[big number]

As shown below, if I write 128KB of data using this command, then fdisk reports the drive as only 128KB in size. When I try to write up to 1TB of data, it stops at 30GB with device full error.

I have tried deleting and recreating partition tables, but since the software only recognizes the smaller drive size, that doesn't help.

How do I get the full drive size back?

P.S. I also tried writing from if=/dev/zero instead. That goes at 5GB/s and stops at the same 32GB spot.

P.P.S. I also tried removing power from the drive and restarting it, thinking there was something in memory causing the problem. Same issue.

# fdisk -l /dev/sdc

Disk /dev/sdc: 29.5 GiB, 31633203200 bytes, 61783600 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

#try to write to entire drive:
# dd if=/dev/zero of=/dev/sdc bs=65536 count=15258788 status=progress

26753171456 bytes (27 GB, 25 GiB) copied, 5.00001 s, 5.4 GB/s
dd: error writing '/dev/sdc': No space left on device
482685+0 records in
482684+0 records out
31633203200 bytes (32 GB, 29 GiB) copied, 5.89003 s, 5.4 GB/s

# dd if=/dev/urandom of=/dev/sdc bs=65536 count=2 status=progress
2+0 records in
2+0 records out
131072 bytes (131 kB, 128 KiB) copied, 0.000660426 s, 198 MB/s

# fdisk -l /dev/sdc
Disk /dev/sdc: 128 KiB, 131072 bytes, 256 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

# dd if=/dev/urandom of=/dev/sdc bs=65536 count=15258788 status=progress
31624462336 bytes (32 GB, 29 GiB) copied, 136 s, 233 MB/s     
dd: error writing '/dev/sdc': No space left on device
482685+0 records in
482684+0 records out
31633203200 bytes (32 GB, 29 GiB) copied, 136.038 s, 233 MB/s
  • 8
    Sounds like you have a file on your root device rather than a device at /dev/sdc. What does ls -l /dev/sdc say? – icarus Jan 11 '18 at 18:18
  • #ls -l /dev/sdc -rw-r--r-- 1 root root 31633203200 Jan 11 13:09 /dev/sdc wow! How do I fix that? – dan grunberg Jan 11 '18 at 18:33
  • 1
    I deleted the /dev/sdc and /dev/sdc1 files (they were not block devices but just files), and re-plugged the drive. /dev/sdc appeared and fdisk -l /dev/sdc reports the correct size. I think all is well. Somehow, I must have done the dd command when the drive was not plugged in and it created the files in /dev instead. After that, things went downhill quickly. @icarus if you write up your comment as an answer, I will accept it. Thank you. – dan grunberg Jan 11 '18 at 18:43
  • @icarus You should make that an answer. – Hauke Laging Jan 11 '18 at 19:22
-1

For some reason the block special device file /dev/sdc didn't exist, perhaps because the drive wasn't connected at the time. The dd command then created the file as a normal file, probably on the root filesystem, which gives the observed results.

  • Why the downvote? The answer fits the facts and is accepted. – icarus Dec 23 '18 at 18:17

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.