Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm creating a live-USB and don't understand precisely: what happens when I copy a file (or even a file system) directly to a device node (as opposed to a file system)?

share|improve this question
add comment

1 Answer

up vote 16 down vote accepted

The shell will open the device /dev/sdX. All output of the cat command, which ends up being the contents of debian.iso, is written directly to that device.

The end result is that debian.iso is written byte-for-byte to the start of the disk underlying /dev/sdX.

In effect, the device node makes it appear that the low-level contents of your storage medium behave as a single file. You're writing into this "file", and therefore writing into the storage medium. This philosophy is known as "everything is a file" and is considered one of the defining features of a Unix system.

share|improve this answer
9  
Is this command different from dd if=debian.iso of=/dev/sdX? –  Herman Torjussen Sep 15 '12 at 15:55
2  
@htor, not significantly, but dd gives you more control over block sizes, the default being implementation-dependent (eg. 1 or 512 bytes). With dd you can potentially choose a better size for your block device, like 4096 bytes. –  mrb Sep 15 '12 at 17:38
    
Thanks, Jim. Does that mean, that by executing this command, I overwrite MBR with partition table and FAT partition on my flash and fill it with ISO-9660 file system with its 2048-byte sectors and bootloader somewhere in? I don't know, how it's meant to work, cause El Torito bootable CD specification allow several modes of action of that CD image - floppy emulation, hard drive emulation and no emulation. Could you also explain, what sense it makes to tell dd (if I use it instead), what size of blocks it should use, if block size is determined by file system (i.e. they must be 2048 byte on ISO) –  Bob Sep 15 '12 at 19:00
2  
@Bob Except with tape drives, the block size you pass to dd influences performance, but not what data is read and written. There is no relationship between the dd block size and the CD block size or the filesystem block size. A few megabytes will typically give you the best performance, though cat can be quicker than dd. –  Gilles Sep 15 '12 at 19:48
2  
How about boot sector, will /dev/sdX afterwards boot as normal as the CD/DVD image? –  math Sep 18 '12 at 7:21
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.