Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How do I do a raw write to my CD drive /dev/scd0? I want to write a bootloader (that takes two sectors) directly onto a CD, is this possible?

share|improve this question

2 Answers 2

As CDs are not traditional block devices, writing via dd will likely not result in a usable CD. If you want to write an image to a CD, use the wodim tool (what used to be known as cdrecord).

wodim dev=/dev/cdrom file.iso

Alternatively, you can use the graphical Brasero Disc Burner application included in the default install of Ubuntu.

Note also that a different process is used to boot off a CD compared to booting off a block device like a hard disk. Rather than just executing code found in the first sectors of the image, it makes use of a process called the El Torito Bootable CD Specification. In effect there is a table in the CD image that says where to find boot loaders for one or more CPU architectures. The boot loader either exists directly on the CD itself, or inside a floppy disk image. In the latter case, the BIOS emulates a floppy drive backed by that image and boots as normal from there.

If you want to boot Linux from the CD, I would suggest using the ISOLINUX boot loader. A copy of the boot loader can be found in the syslinux package.

If you want to use some other custom boot code, the floppy emulation mode might be an easier choice.

share|improve this answer
    
I'm finding it amusing how two different people write almost identical answers within 2 minutes from each other :) –  Sergey Sep 6 '11 at 4:19

I see a couple of shortcomings with your approach...

Firstly, it is generally impossible to write arbitrary sectors on a CD-ROM - unlike the hard drives, optical media does not support random writes. Think about CD-R disks, opening/closing sessions and other stuff.

Secondly, the procedure of booting from a CD is quite different from booting from a HD - in some cases bootable cdroms use an image of a floppy or emulate a harddisk etc. See El Torito standard for more details

So, to make a bootable CD, I would imagine you need to prepare a bootable ISO image using ISOLINUX or some other boot loader. Burning that ISO to a CDROM using some standard program such as Brasero or K3b would produce a bootable disk.

share|improve this answer

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.