How can a file created by dd be bigger than the partition?

4

1

A teacher told that in my Unix course and I would like to know how a 10GB partition can handle a 1TB file ?

Henley n

Posted 2018-03-11T22:16:24.047

Reputation: 143

1What is a "To"? Presumably you mean Terabyte / TB? – Attie – 2018-03-11T22:50:18.050

Answers

2

What your teacher is most likely referring to is something called "sparse files". These are files which grow as they are written to, with the underlying disk holding the magic - thus, provided that the filesystem is empty (and specifically writing 0's is not empty) its possible to create a 10 gig sparse file/block device using only a fraction of that on disk.

Look at this superuser link for more details on sparse files - especially the first response which explains how to do it in DD.

davidgo

Posted 2018-03-11T22:16:24.047

Reputation: 49 152

oh okay that's what i was thinking it's like a having "1000 m² of void in 10m²" in some way ? – Henley n – 2018-03-11T22:49:30.060

2The filesystem doesn't record the zeroes, but rather records the seek() (which can skip forward or backward in a file)... It's sort of like holding an IOU for n apples, rather than a bucket of n apples. – Attie – 2018-03-11T22:52:49.147

2Its a bit similar to those fake USB disks you get out of China which claim to be 128GIG, but are actually 4 gig - they just tell the OS they have more space then they do - but when you run out of actual space, bad things happen. (Of-course, sparse files are designed to grow as needed, so you don't have problems until its more then the underlying disk, and they probably won't silently drop all your data) – davidgo – 2018-03-11T22:55:53.637

lmao fanks for the explaination – Henley n – 2018-03-11T23:55:26.240