cp command to make bootable iso image usb

9

3

A lot of discussions exist here on making a bootable USB stick. Debian manual on installing Wheezy suggest the following:

# cp debian.iso /dev/sdX
# sync

Making sure the USB device is first unmounted.

Debian manual page.

I have done this in preparation to install wheezy. It seem to work, because the ISO image is all that is seen on the USB and usable size is that of the image. Remains to see if it will boot and so on.

Now, can somebody elaborate why this work. I thought a cp command like this is similar to a drag and drop, (apart from the USB being unmounted).

Tompa

Posted 2013-07-17T13:15:33.193

Reputation: 193

Answers

7

Devices in Linux are files. /dev/sda or /dev/sdb are files as well. So what you do is replace the /dev/sdX file with the dot-ISO file, which you can then mount and use as a device.

What sync does, is it forces the changed blocks on the virtual device (/dev/sda file) to be updated on the actual disk.

Ashtray

Posted 2013-07-17T13:15:33.193

Reputation: 1 489

2So the magic part of this is to perform the cp command on an unmounted device (file). It's like it was common knowledge when reading debian manual, and maybe it is? Anyway, it did work, my new machine booted the USB and wheezy installed, thanks. – Tompa – 2013-07-18T10:09:17.527

3

A possibly better way of doing it is with dd. which does byte copy. the syntax would be

dd if=debian.iso of=/dev/sdX

and the command will need to be run as root. dd allows you to have more control if you want it. Check out it's man page here or Debian instructions on how to create a bootable USB stick here.

(Where sdX maybe the full name of the drive, with the number, for instance /dev/sdc1.)

Mobius

Posted 2013-07-17T13:15:33.193

Reputation: 238

And this command I guess is to be performed with a mounted device? – Tompa – 2013-07-18T10:09:55.530

@Tompa, actually it doesn't matter. It would probably be better to use an unmounted device because you are overwriting the entire partition structure that is formatted in say fat or ext3 or ntfs and replacing it with the cdrom or dvd format (usually UDF). If the operating system is writing to the filesystem while it gets overwritten it could be a bad thing. the block device /dev/sdx basically is a virtual file allowing binary access to the entire harddrive. – Mobius – 2013-07-18T14:26:14.343