9

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)?

1 Answer 1

16

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.

7
  • 10
    Is this command different from dd if=debian.iso of=/dev/sdX?
    – user13742
    Sep 15, 2012 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, 2012 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) Sep 15, 2012 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. Sep 15, 2012 at 19:48
  • 2
    How about boot sector, will /dev/sdX afterwards boot as normal as the CD/DVD image?
    – math
    Sep 18, 2012 at 7:21

You must log in to answer this question.

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