dd command not filling device

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.

Asked By: Peter bill

||

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.

Answered By: Ljm Dullaart
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.