Friday, 25 April 2008

CD Burning Permissions in Linux

There are many options for burning CDs and DVDs in linux. This article is not about any particular disk burning tool. In some linux configurations, the normal users do not have exclusive rights to the cd burning device and this causes the burn process to fail. Although this can be solved by running the cd recording utility as root, it is not very elegant nor recommended for daily use.
Usually the permission problems crop up because the user doesn't have write access to the /dev/sg* devices. This can be solved by a simple
sudo chmod o+w /dev/sg*However, in many modern linux distributions, the /dev devices are created automatically at runtime by the udev daemon. So setting permissions like above will only last for that particular session. You can ofcourse modify /etc/rc.local or other startup script to change the permissions everytime on boot, but it is also a rather inelegant solution.

Ofcourse, there's more than one way to skin a rabbit. So if you're ok with the solutions I outlined above, you can forget about the rest of the article. If you get a thrill out of editing esoteric config files, keep reading . :)

The way I proceeded to solve the problem was by scanning through the /etc/udev directory. I noticed that there is a folder titled rules.d which contained a lot of scripts organized in a similar way to the scripts in /etc/rc.d directories. There are many scripts for lot of special devices on my system, but nothing that seemed specially setup for cd-roms or block devices. Therefore I proceeded to open up the most likely candidate titled /etc/udev/rules.d/50-udev-default.rules. Sure enough about halfway through the very lengthy file, I discovered the line where the /dev/sg* devices were being created. The line looks like
# block, tapes, block-releated
SUBSYSTEM=="block", GROUP="disk", MODE="0640"
SUBSYSTEM=="block", KERNEL=="sr[0-9]*", SYMLINK+="scd%n"
SUBSYSTEM=="scsi", KERNEL=="[0-9]*:[0-9]*", ACTION=="add", ATTR{type}=="0|7|14", ATTR{timeout}="60"
SUBSYSTEM=="scsi", KERNEL=="[0-9]*:[0-9]*", ACTION=="add", ATTR{type}=="1", ATTR{timeout}="900"
KERNEL=="hd*", SUBSYSTEMS=="ide", ATTRS{media}=="floppy", OPTIONS+="all_partitions"
KERNEL=="fd[0-9]", GROUP="floppy"
KERNEL=="fd[0-9]", ACTION=="add", ATTRS{cmos}=="?*", RUN+="create_floppy_devices -c -t $attr{cmos} -m %M -M 0640 -G floppy $root/%k"
KERNEL=="sch[0-9]*", GROUP="disk"
KERNEL=="sg[0-9]*", ATTRS{type}!="3|6", GROUP="disk", MODE="0640"
KERNEL=="ht[0-9]*|nht[0-9]*", GROUP="disk"
KERNEL=="pg[0-9]*", GROUP="disk"
KERNEL=="pt[0-9]*|npt[0-9]*", GROUP="disk"
KERNEL=="qft[0-9]*|nqft[0-9]*|zqft[0-9]*|nzqft[0-9]*|rawqft[0-9]*|nrawqft[0-9]*", GROUP="disk"
KERNEL=="rawctl", NAME="raw/%k", GROUP="disk"
SUBSYSTEM=="raw", KERNEL=="raw[0-9]*", NAME="raw/%k", GROUP="disk"
KERNEL=="pktcdvd[0-9]*", NAME="pktcdvd/%k"
KERNEL=="pktcdvd", NAME="pktcdvd/control"
KERNEL=="qft0", SYMLINK+="ftape"
SUBSYSTEM=="bsg", NAME="bsg/%k"
SUBSYSTEM=="aoe", NAME="etherd/%k", GROUP="disk"


Problem solved. All I needed to do was change the mode to 0660 and add myself to the disk group.
The modified line in /etc/udev/rules.d/50-udev-default.rules looks like
KERNEL=="sg[0-9]*", ATTRS{type}!="3|6", GROUP="disk", MODE="0660"

Then I added myself to the disk group.
sudo usermod -a -G disk januz
To make sure you're in the disk group, run
groups januz If the output contains 'disk', then you're done. The next time you reboot the machine, the cd recording devices will be writable by you and the cd recording tools won't be throwing out any nasty permission errors.

No comments: