How to check if a cdrom is in the tray remotely (via ssh)?
Solution 1
The output isn't quite as pretty as yours but it doesn't require you to install anything:
$ sudo lshw | awk '/\*-cd/,/con/' | sed -e 's/^[ \t]*//'
*-cdrom
description: DVD-RAM writer
product: DVD RW AD-7240S
vendor: Optiarc
physical id: 0.0.0
bus info: scsi@8:0.0.0
logical name: /dev/sr0
version: 1.00
capabilities: removable audio cd-r cd-rw dvd dvd-r dvd-ram
configuration: ansiversion=5 status=nodisc
*-cdrom
description: DVD-RAM writer
physical id: 0.0.0
bus info: scsi@9:0.0.0
logical name: /dev/cdrom
logical name: /dev/cdrw
logical name: /dev/dvd
logical name: /dev/dvdrw
logical name: /dev/sr1
logical name: /media/X3_Linux
capabilities: audio cd-r cd-rw dvd dvd-r dvd-ram
configuration: mount.fstype=iso9660 mount.options=ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500 state=mounted status=ready
Solution 2
Using hwinfo:
I think I just answered my own questions using the hwinfo
tool. This tool searches for and lists a bunch of useful information about the various devices on your computer.
It can be installed with sudo apt-get install hwinfo
.
It can also be run with the --<hwitem>
flag to only list info for a particular type of hardware (ie. cd drives) here are the options for this flag:
--<hwitem>
Probe for the particular hardware item. Available hardware items
are: all, bios, block, bluetooth, braille, bridge, camera,
cdrom, chipcard, cpu, disk, dsl, dvb, fingerprint, floppy,
framebuffer, gfxcard, hub, ide, isapnp, isdn, joystick, key‐
board, memory, modem, monitor, mouse, netcard, network, parti‐
tion, pci, pcmcia, pcmcia-ctrl, pppoe, printer, scanner, scsi,
smp, sound, storage-ctrl, sys, tape, tv, usb, usb-ctrl, vbe,
wlan, and zip.
Using the cdrom
flag I can find the information I need.
austin@austinvpn:/proc/scsi$ sudo hwinfo --cdrom
15: SCSI 100.0: 10602 CD-ROM
[Created at block.247]
Unique ID: KD9E.skIhcO_MyD1
Parent ID: 3p2J.7RBlinTaF34
SysFS ID: /class/block/sr0
SysFS BusID: 1:0:0:0
SysFS Device Link: /devices/pci0000:00/0000:00:1f.1/host1/target1:0:0/1:0:0:0
Hardware Class: cdrom
Model: "Lite-On LTN486S 48x Max"
Vendor: "Lite-On"
Device: "LTN486S 48x Max"
Revision: "YDS6"
Driver: "ata_piix", "sr"
Device File: /dev/sr0 (/dev/sg1)
Device Files: /dev/sr0, /dev/block/11:0, /dev/scd0, /dev/disk/by-path/pci-0000:00:1f.1-scsi-1:0:0:0, /dev/cdrom1
Device Number: block 11:0 (char 21:1)
Drive status: no medium
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #9 (IDE interface)
Drive Speed: 48
16: SCSI 101.0: 10602 CD-ROM
[Created at block.247]
Unique ID: nOPI.WcCe56A4L50
Parent ID: 3p2J.7RBlinTaF34
SysFS ID: /class/block/sr1
SysFS BusID: 1:0:1:0
SysFS Device Link: /devices/pci0000:00/0000:00:1f.1/host1/target1:0:1/1:0:1:0
Hardware Class: cdrom
Model: "SAMSUNG CD-R/RW SW-248F"
Vendor: "SAMSUNG"
Device: "CD-R/RW SW-248F"
Revision: "R602"
Driver: "ata_piix", "sr"
Device File: /dev/sr1 (/dev/sg2)
Device Files: /dev/sr1, /dev/block/11:1, /dev/scd1, /dev/disk/by-path/pci-0000:00:1f.1-scsi-1:0:1:0, /dev/cdrom, /dev/cdrw
Device Number: block 11:1 (char 21:2)
Drive status: no medium
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #9 (IDE interface)
Drive Speed: 48
As you can see, it reports, Drive status: no medium
for both drives--appearing to confirm that the CD is either not in the drive, the CD is unrecognizable, or the drive is broken.
Using hwinfo to find drive status:
If you didn't want to look through all the info hwinfo
lists, you could further automate the process with the following command:
sudo hwinfo --cdrom | grep 'Drive status:'
Which will quickly return whether there are CDs in any of the drives.
austin@austinvpn:/proc/scsi$ sudo hwinfo --cdrom | grep 'Drive status:'
Drive status: no medium
Drive status: no medium
I'm looking to see if there is a way to grep
the Model name at the same time, and I'll update this answer when I figure it out.
Hope this can help someone else!
edit:
Here is a slightly more useful command that will output the model name and device file as well (so if a medium is present, you will know which drive it is present in and where you can mount it from/ rip an image from).
sudo hwinfo --cdrom | grep -e 'Model' -e 'Drive status:' -e 'Device File:'
Here is what the output looks like:
austin@austinvpn:/proc/scsi$ sudo hwinfo --cdrom | grep -e 'Model' -e 'Drive status:' -e 'Device File:'
Model: "Lite-On LTN486S 48x Max"
Device File: /dev/sr0 (/dev/sg1)
Drive status: no medium
Model: "SAMSUNG CD-R/RW SW-248F"
Device File: /dev/sr1 (/dev/sg2)
Drive status: no medium
Related videos on Youtube
adempewolff
I've been using Ubuntu as my main system since 7.04 with a few short breaks using Windows or Fedora because of temporary hardware/software incompatibilities. I support FOSS projects like Ubuntu for a number of reasons but the biggest one is that the software works and it works well--often better than the non-free alternatives. I'm no guru but in my travels I've learned a thing or two about using/debugging/fixing problems in Ubuntu which I'm always happy to share with the community. If it hadn't been for the help I've received from the Ubuntu community over the past few years I probably wouldn't have gotten past my first month of using it much less to where I am today!
Updated on September 18, 2022Comments
-
adempewolff over 1 year
I have a server running Ubuntu 10.04 (it's on the other side of the world and I haven't built up the wherewithal to upgrade it remotely yet) and I have been told that there is a CD in one of it's two CD drives. I want to rip an image of the cd and then download it to my local computer (I don't need help with either of these steps).
However, I cannot seem to confirm whether or not there actually is a CD in the drive as I was told. It did not automatically mount anywhere (which I'm thinking might just be a result of it being a headless server not running X, nautilus, or any of the other nice user friendly things).
There are two CD drives connected via SCSI:
austin@austinvpn:/proc/scsi$ cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: ATA Model: WDC WD400EB-75CP Rev: 06.0 Type: Direct-Access ANSI SCSI revision: 05 Host: scsi1 Channel: 00 Id: 00 Lun: 00 Vendor: Lite-On Model: LTN486S 48x Max Rev: YDS6 Type: CD-ROM ANSI SCSI revision: 05 Host: scsi1 Channel: 00 Id: 01 Lun: 00 Vendor: SAMSUNG Model: CD-R/RW SW-248F Rev: R602 Type: CD-ROM ANSI SCSI revision: 05
However when I try mounting either of these devices (and every other device that could possibly be the cd-drive), it says
no medium found
:austin@austinvpn:/proc/scsi$ sudo mount -t iso9660 /dev/scd1 /cdrom mount: no medium found on /dev/sr1 austin@austinvpn:/proc/scsi$ sudo mount -t iso9660 /dev/scd0 /cdrom mount: no medium found on /dev/sr0 austin@austinvpn:/proc/scsi$ sudo mount -t iso9660 /dev/cdrom /cdrom mount: no medium found on /dev/sr1 austin@austinvpn:/proc/scsi$ sudo mount -t iso9660 /dev/cdrom1 /cdrom mount: no medium found on /dev/sr0 austin@austinvpn:/proc/scsi$ sudo mount -t iso9660 /dev/cdrw /cdrom mount: no medium found on /dev/sr1
Here are the contents of my
/dev
folder:austin@austinvpn:/proc/scsi$ ls /dev agpgart loop6 ram6 tty10 tty38 tty8 austinvpn loop7 ram7 tty11 tty39 tty9 block lp0 ram8 tty12 tty4 ttyS0 bsg mapper ram9 tty13 tty40 ttyS1 btrfs-control mcelog random tty14 tty41 ttyS2 bus mem rfkill tty15 tty42 ttyS3 cdrom net root tty16 tty43 urandom cdrom1 network_latency rtc tty17 tty44 usbmon0 cdrw network_throughput rtc0 tty18 tty45 usbmon1 char null scd0 tty19 tty46 usbmon2 console oldmem scd1 tty2 tty47 usbmon3 core parport0 sda tty20 tty48 usbmon4 cpu_dma_latency pktcdvd sda1 tty21 tty49 vcs disk port sda2 tty22 tty5 vcs1 dri ppp sda5 tty23 tty50 vcs2 ecryptfs psaux sg0 tty24 tty51 vcs3 fb0 ptmx sg1 tty25 tty52 vcs4 fd pts sg2 tty26 tty53 vcs5 full ram0 shm tty27 tty54 vcs6 fuse ram1 snapshot tty28 tty55 vcs7 hpet ram10 snd tty29 tty56 vcsa input ram11 sndstat tty3 tty57 vcsa1 kmsg ram12 sr0 tty30 tty58 vcsa2 log ram13 sr1 tty31 tty59 vcsa3 loop0 ram14 stderr tty32 tty6 vcsa4 loop1 ram15 stdin tty33 tty60 vcsa5 loop2 ram2 stdout tty34 tty61 vcsa6 loop3 ram3 tty tty35 tty62 vcsa7 loop4 ram4 tty0 tty36 tty63 vga_arbiter loop5 ram5 tty1 tty37 tty7 zero
And here is my
fstab
file:austin@austinvpn:/proc/scsi$ cat /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid -o value -s UUID' to print the universally unique identifier # for a device; this may be used with UUID= as a more robust way to name # devices that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc nodev,noexec,nosuid 0 0 /dev/mapper/austinvpn-root / ext4 errors=remount-ro 0 1 # /boot was on /dev/sda1 during installation UUID=ed5520ae-c690-4ce6-881e-3598f299be06 /boot ext2 defaults 0 2 /dev/mapper/austinvpn-swap_1 none swap sw 0 0
Am I missing something/doing something wrong, or is there just no CD in the drive or is the drive possibly broken? Is there any nice command to list devices with mountable media?
Thanks in advance for any help!
-
adempewolff over 11 yearsI was wondering if there would be a way to do it with installed software. I love questions like this because you can see so many different ways to do the same thing. I'd wager that creative use of
grep
, regular expressions, and another pipe or two could make this more "pretty"--but who knows if it'd be worth the time :P