Linux CD / DVD Locked and Drive Is Not Opening / Ejecting CD

I‘ve Ubuntu Linux Installed on HP Desktop system. When I press the eject button my DVD / CD ROM nothing happens. Linux is not ejecting my CD/DVD and I had to reboot my computer to just get CD/DVD out of drive. How do I fix this issue?

You don’t have to reboot the system to just eject CD / DVD from drive. Sometime Linux locks down your CD / DVD if a process reading / accessing file / directory on that DVD / CD.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements None
Est. reading time 2m

Getting Your CD/DVD Out Of Drive

Simply right click on CD / DVD icon and select Eject / Unmount option. Press eject button to get the cd/dvd out. If this failed, try following method to eject the cd:

Find Out CD/DVD drive mount location

Run df or mount command to find out location, enter the following at terminal / shell prompt:
$ df
Sample output:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              92G   22G   66G  25% /
varrun               1013M  140K 1013M   1% /var/run
varlock              1013M     0 1013M   0% /var/lock
udev                 1013M   88K 1013M   1% /dev
devshm               1013M     0 1013M   0% /dev/shm
lrm                  1013M   34M  979M   4% /lib/modules/2.6.22-14-generic/volatile
/dev/sda1              98G   19G   79G  20% /media/sda1
/dev/sda5             274G  185G   89G  68% /share
/dev/scd0             3.5G  3.5G     0 100% /media/cdrom0

In this example, my CD / DVD device name is /dev/scd0 and mounted under /media/cdrom0. Now issue the following command as root user:

Warning: Following command may result into data loss. Sometime fuser command will kill all process on the system. You have been warned.

$ sudo fuser -km /media/cdrom0
# fuser -km /media/cdrom0

Now you may able to eject CD or DVD from the drive.

See also

Related: See How to forcefully remove unmount a Linux disk partition / device using lsof and fuser command.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 9 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
9 comments… add one
  • mircea Jun 26, 2008 @ 17:35

    I think there is an alternative to this method. The “eject” command. You can use it from a terminal or simpler from the “Run application” dialog (e.g. Alt+F2 in Gnome).

  • Jeff Schroeder Jun 29, 2008 @ 19:45

    You might also try disallowing the kernel from locking the cdrom. Sometimes a rogue process will hold onto the drive for no real reason. This way is often much cleaner than killing the process.

    # Temporarily unlock the cdrom
    echo 0 > /proc/sys/dev/cdrom/lock

    # Permanently unlock the cdrom
    echo “” >> /etc/sysctl.conf

    Can you switch your blog to reCaptcha? It helps to translate old books and is a better captcha than yours.

  • Arfy Mar 23, 2009 @ 8:10

    Nice, but my cdrom is not mounted. A disk is stuck in there after some IO errors. I’m guessing a scratch or smudge is on the disk. The drive hardware seems to have given up entirely, and is still locked. The “eject” command is useless:

    eject: CD-ROM eject command failed

    fuser and lsof show nothing, because the drive is no longer mounted. The program I was running (watching a movie in xine) has long since given up and I was allowed to exit. Xine is not running now.

    I suppose I’ll look for a paperclip … :o(

    — Nate

    • nameless warrior Jan 21, 2014 @ 12:22

      have you tried:
      $ eject sr0

  • Psylem Jul 28, 2009 @ 2:41

    Nothing here works for me. Drive will not open and I don’t know why. Tried the old paperclip method to force the door open, but of course it doesn’t recognise the disk.

    /proc/sys/dev/cdrom/lock = 1 but I can’t overwrite it, even as root. The system knows there is no disk in the drive and nothing is mounted anywhere.

    “ps aux | grep cd” shows the following…
    root 43 0.0 0.0 0 0 ? S< 08:17 0:00 [kmmcd]

    Any ideas? I'm just going to do a reboot, but for future reference I'd love to find a solution.

  • L Oct 12, 2009 @ 2:41

    you know if you’re using

    sudo echo 0 > lock

    it wont work, need to do something like:

    sudo bash
    echo 0 > lock

  • d May 8, 2011 @ 2:21

    You may have to run the umount and fuser commands with sudo on macs.

    sudo umount -f /dev/disk1s0

  • Robert Riches Jan 11, 2014 @ 23:11

    I would recommend extreme caution in attempting “fuser -km /media/cdrom”. I just finished using alt-sysrq to reboot my Debian Wheezy (7) system after “fuser -km /media/cdrom” apparently killed the init process and likely everything else. (Yes, I should have tried the command as a non-root user before trying it as root.) The machine was still answering pings, but the keyboard and console were dead, and sshd was refusing connections. Oh, and the root filesystem needed some (automatic) repairs upon reboot.

  • Jan Forejtnik Jan 15, 2014 @ 14:04

    This command has turned my Debian Wheezy into vegetable. I strongly recommend not using it.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum