14

I've seen various questions asked (and answered) regarding how to detect the size of various media on a GNU/Linux system, and in particular how much space has been used on an optical drive. But is there anything I can do to detect the capacity of a CD-R(W) (i.e. is it a 650 / 700 / ... MB CD-RW)?

I suspect that cdrecord / wodim is able to detect that before it even attempts to burn an ISO, but so far I haven't been able to use it to obtain the information I want.

EDIT: I intend to use this information in a script I'm writing, so I'm only interested in command line tools (whose output I would parse). I'd also prefer a solution based on tools that are available by default on most systems.

Anthony Labarre
  • 273
  • 2
  • 9

3 Answers3

8

With cdrwtool from udftools:

cdrwtool -i -d /dev/cdrom

The capacity in bytes is

cdrwtool -i -d /dev/cdrom | awk '$1 == "free_blocks" {print $3 * 2048}'

With dvd+rw-mediainfo from dvd+rw-tools (mainly known for growisofs):

dvd+rw-mediainfo /dev/dvd

You need write access to the DVD drive to issue the special command needed to obtain information on blank media.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • Unfortunately `cdrwtool` does not do the job (at least on Debian Wheezy): free_blocks is 0, although only 416 out of 700 MBs of my CD-RW are used. – Anthony Labarre Dec 18 '13 at 16:27
  • @AnthonyLabarre Hmmm. Sorry about that. I did check but only with a CD-R. – Gilles 'SO- stop being evil' Dec 18 '13 at 18:34
  • Use `cdrecord -minfo -v`. – schily Sep 16 '15 at 10:55
  • @schily Post that as an answer. And make sure you specify that it only works with your version of cdrecord, not with the cdrkit fork that most people have these days. – Gilles 'SO- stop being evil' Sep 16 '15 at 11:03
  • Why do you believe I need to mention this as it applies to the original version of the tools since Autumn 2004. – schily Sep 16 '15 at 11:07
  • Fails with udftools 1.0.0b3-14.2ubuntu1 shipped with Ubuntu 14.04 LTS. The output of `cdrwtool -i -d /dev/cdrom` is `using device /dev/cdrom; 1405KB internal buffer; setting write speed to 12x; wait_cmd: Operation not permitted; Command failed: bb 00 ff ff 08 40 00 00 00 00 00 00 - sense 00.00.00; set speed` (semicolons are mine) – XavierStuvw Jan 20 '18 at 14:12
2

I was looking for this information too. I took a punt and tried:

$ fdisk -l /dev/cdrom

and it appears to work:

Disk /dev/cdrom: 4.4 GiB, 4700372992 bytes, 2295104 sectors
Units: sectors of 1 * 2048 = 2048 bytes
Sector size (logical/physical): 2048 bytes / 2048 bytes
I/O size (minimum/optimal): 2048 bytes / 2048 bytes

which concurred with dvd+rw-mediainfo:

Track Size:            2295104*2KB
READ CAPACITY:         2295104*2048=4700372992

I tried a CD (which doesn't work with dvd+rw-mediainfo):

Disk /dev/cdrom: 560.7 MiB, 587880448 bytes, 287051 sectors
Units: sectors of 1 * 2048 = 2048 bytes
Sector size (logical/physical): 2048 bytes / 2048 bytes
I/O size (minimum/optimal): 2048 bytes / 2048 bytes

Here's a pre-recorded DVD:

Disk /dev/cdrom: 7.8 GiB, 8393883648 bytes, 4098576 sectors
Units: sectors of 1 * 2048 = 2048 bytes
Sector size (logical/physical): 2048 bytes / 2048 bytes
I/O size (minimum/optimal): 2048 bytes / 2048 bytes

It doesn't work with discs that haven't been written to or with audo CDs.

I'd still like to find a single solution that works for all kinds of discs, however.

starfry
  • 7,302
  • 6
  • 47
  • 69
1

The original cdrtools are available at:

https://sourceforge.net/projects/cdrtools/files/

If you have wodím, you do not have a real cdrecord but a fork created by some unfriendly Debian people based on the state of May 2004. At that time, -minfo was not yet available.

-minfo was added around Autumn 2004 and enhanced since then, e.g. to support DVDs and BluRay media as well.

cdrecord -minfo

delivers basic information about the media state while

cdrecord -minfo -v

adds more information, e.g. information about the media manufacturer.

What you like to get (the capacity of the medium) is printed amongst further information about whether the medium is still writable or appendable and what the remaining capacity is.

schily
  • 18,806
  • 5
  • 38
  • 60
  • wodim 9:1.1.11-2ubuntu3 shipped with Ubuntu 14.04 LTS does not like the command `cdrecord -minfo -v` and returns a message `wodim: Bad Option: -minfo` – XavierStuvw Jan 20 '18 at 14:06
  • ...neither on 16.04 or 18.04. – user292812 Mar 12 '20 at 08:32
  • Ubuntu is an unmaintained distro, they did not upgrade cdrtools since May 2004. I am sorry but I cannot help here. You need to compile and install recent software by your own. Get it here: http://sourceforge.net/projects/schilytools/files/ – schily Mar 12 '20 at 11:23