Failed to write nulls to HD

Using XFCE.
Could someone please explain why the following fails (logged in as root)…

localhost:/home/ion # fdisk /dev/sdc

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


Command (m for help): p
Disk /dev/sdc: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: TOSHIBA MQ01ABD0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 6468A424-9088-4415-86C9-4683B0A5159F

Device         Start       End   Sectors   Size Type
/dev/sdc1       2048    206847    204800   100M EFI System
/dev/sdc2     206848    239615     32768    16M Microsoft reserved
/dev/sdc3     239616 975685296 975445681 465.1G Microsoft basic data
/dev/sdc4  975685632 976771071   1085440   530M Windows recovery environment

Command (m for help): q

localhost:/home/ion # dd if=/dev/null of=/dev/sdc bs=512 status=progress
0+0 records in
0+0 records out
0 bytes copied, 9.503e-05 s, 0.0 kB/s
localhost:/home/ion # 

@ionmich use /dev/zero

1 Like

I still remember you made the same mistake some years ago.

/dev/null does point to what is colloquially called “a black hole”. Which means that all that is put into it will vanish (gone, never be seen again, …) and nothing can come out of it. That last means that when a read is done, a EOF (end of file) indication is given. Because there is nothing. No bytes whatsoever.

You probaly want to copy bytes of value x'00' and there is a source for that. It is /dev/zero.

A language barrier? “zero” is not the same as “null”.

2 Likes

Yes thank you that worked. Now I thought /dev/null represented 0 Hex as opposed to zero, 30 Hex and I didn’t quite understand hcvv’s explanation. Is he saying that nulls can’t be written to a drive? I don’t think it matters what character I use to wipe the drive, I’m just curious.

One thing is obvious. Your memory is better that mine.

“/dev/null” does not emit nulls. Any attempt to read from “/dev/null” just get an end-of-file indication. Use “/dev/zero” for nulls.

“null” is nothing! No bytes, no contents.

A “zero” byte has 8 bits, all value 0, makes the value of the byte ‘x00’.

x’30’ might represent an ASCII character “0”. And has nothing to do with /dev/zero .

You might try to study

man null

which shows the same as

man zero

And just for the joy of it: Clean delete USB

No, for zero bytes. “Null” is something different: Null Definition & Meaning - Merriam-Webster

As I said: a language barrier.

I’m learning. Thank you.

Hopefully Merriam-Webster’s definition of “having no value” will stay in my ageing brain. As opposed to having value zero, or any number.

Which is absolutely irrelevant. This is not about some metaphysical concept or definition in a human language. The /dev/null is the device (file) which returns EOF (end of file) for every read. Period. That it happens to coincide with your interpretation of the English word null does not add anything to how this device is defined and implemented in UNIX.

Inferring the functionality of a program from its similarity to some human language words is fallacy. Creating a device /dev/foobar with the same device number will provide the same functionality even though its name does not include null.

I am glad you value the way I try to get the message about /dev/null over in a way that, as I hope, may stick longer then two years.

1 Like

Technically, for every megabyte of data swallowed by /dev/null a tiny stream of Hawking radiation is released by /dev/urandom. This can be observed for example with careful use of head --bytes=1 /dev/urandom | xxd -b | cut -d' ' -f2

I guess you left that out for pedagogical purposes.

1 Like

:wink:

(and at least 10 characters of radiation).

:upside_down_face:

> man 4 null

   Data written to the /dev/null and /dev/zero special files is discarded.

   Reads  from /dev/null always return end of file (i.e., read(2) returns 0), whereas reads from /dev/zero always
   return bytes containing zero ('\0' characters).

Personally, when I want to re-initialise an old disk – make it appear to be “empty” – I use the following:

 # dd if=/dev/urandom of=/dev/sd? iflag=fullblock bs=1G count=2 status=progress
 # dd if=/dev/zero of=/dev/sd? iflag=fullblock bs=1G count=2 status=progress

Occasionally, I increase the value of the ‘count’ parameter.


If the disk is so old that it has to be recycled, I open it, dismantle the rotating parts and, physically destroy them and then, I take the electronic bits and pieces to the recycling point … :smiling_imp:

  • I haven’t yet decided what I’ll do when an SSD needs to be passed on to the recycling facilities – possibly overheat it with a welding-torch before getting rid of it … :zap:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.