2

I have a surplus 120GB SSD that I want to completely clear of data. With the drive unmounted, I ran

sudo dd if=/dev/urandom of=/dev/sda bs=4M

but it stopped after copying 8GB, reporting “dd: error writing '/dev/sda': No space left on device”.

lsblk showed the correct device name, and a capacity of 112GB.

I tried several variations of the dd command, with different values for bs; with and without status=progress; and even after mounting the device. Every attempt stopped after writing the exact same amount of data (7996309504 bytes).

Why did dd claim a 120GB drive was full, after writing only 8GB?

I even reformatted with gnome-disks, but dd behaved just the same.

In desperation, I mounted the partition and tried:

sudo dd if=/dev/urandom of=/dev/sda1 bs=4M status=progress

which ran to completion, reporting:

120033123840 bytes (120 GB, 112 GiB) copied

It is usual to require device names with dd, so I was surprised when a partition worked. Can anyone explain what was going on?

Edit after some comments

Maybe @ljm is onto something. ls shows I have an ordinary file called '/dev/sda', of size 8GB. file says it is a data file. Where it came from, I don't know. Why its size is limited, I don't know. Is it safe to remove it?

I also have a block special file /dev/sda1.

9
  • Either the drive is reporting a wrong size or the drive is broken. Time for the trash can.
    – paladin
    Commented Mar 4 at 15:56
  • Could you try 1) a whole device TRIM using blkdiscard, 2) ATA secure erase using hdparm, 3) ATA enhanced secure erase using hdparm? Commented Mar 4 at 16:05
  • Trash is certainly an option, AFTER I wipe it. I have been using it for years, with no sign that it's wrong size or broken. I used to have Windows 7 on it - in 8 GB!?! Anyway, WHY did the final dd copy 120GB?
    – Peter bill
    Commented Mar 4 at 16:07
  • 3
    What does ls -l /dev/sda say? Or df /? Commented Mar 4 at 16:49
  • 1
    Not so unusual scenario. Similar question: Regain full disk space after copying a small image file to a large USB device. Commented Mar 4 at 18:21

1 Answer 1

2

When you unmount a disk, the disk has a tendency to disappear. So when you unmounted the device, the device file probably also disappeared. The remedy is normally to plug-out and plug-in.

When the device file /dev/sda was gone, dd assumed that you wanted to create a normal file /dev/sda. Even though it is under /dev, it is still a normal file, not a device. Your dd will continue until the partition is full, which might very well 8GB.

7
  • /dev is (usually) a different partition to / Commented Mar 4 at 18:05
  • 2
    I've never seen the device node disappear when it was unmounted. This would cause major problems if (for instance) you use automount. You also unmount a device, not a file.
    – doneal24
    Commented Mar 4 at 18:57
  • 2
    Likewise. It disappears when the device is ejected or otherwise removed, but not when it's simply unmounted Commented Mar 4 at 19:06
  • 1
    The beginning of this answer is poorly worded: "a tendency to disappear" suggests a non-deterministic behavior. Sole umount does not make the device node disappear. Still, in GUI "remove safely" or so most likely ends with an action equivalent to udisksctl power-off … and this may make the node disappear, e.g. at least for USB it does. The question does not specify if it's a USB device nor how the OP "unmounted" it. Commented Mar 4 at 19:16
  • 1
    If the OP used umount from the CLI, then the device file does not disappear. If the OP used one of the many GUIs, then the "unmount" in the GUI may have been an eject under the hood. Because I do not know which way the OP unmounted the device, I worded it a bit vague. Commented Mar 5 at 9:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .