Use Terminal to Eject a Stuck CD/DVD

Use this Terminal trick to force eject media without shutting down

A cd in a macbook disk drive
Epoxydude/Getty Images

Having a CD or DVD stuck in your Mac or an optical drive isn't a fun situation. While there are several ways to force the media to be ejected, most require you to shut down. If that presents a problem, you can use Terminal to force eject the CD or DVD without shutting down your Mac.

Terminal, an app included with the Mac OS, provides access to the Mac’s command line. The fact that the Mac has a command line is often a shock to Mac users and Windows switchers, but when you realize that OS X and the macOS are built using Unix components, it makes sense that a command line tool is available.

Perhaps even more important for the problem of a stuck CD or DVD in your optical drive is that Terminal includes a command for working with attached storage devices, such as an optical drive. This command, diskutil, can do a lot. It's the foundation for the Disk Utility app that's also included with the Mac.

You can make use of diskutil's ability to work with optical drives to force any stuck media in your optical drive to be ejected.

Use Terminal to Eject a Stuck CD or DVD

Launch Terminal, which is located at Applications > Utilities.

In the Terminal window, enter one of the following three commands:

If you have a single optical drive:

drutil eject

If you have both an internal and external optical drive, use the appropriate command below, depending on which drive has the stuck CD or DVD:

drutil eject internal drutil eject external 

Press Return or Enter after entering one of the above commands in Terminal.

The stuck CD or DVD should be ejected.

This should solve most stuck CD or DVD problems, but there's another method for ejecting a stuck CD or DVD. In this case, the problem occurs when you have more than one internal or external optical drive. In that condition, you can use a different command, diskutil, to eject a specific device.

To issue the proper form of the eject command, you need to know the physical device name used by OS X for the optical drive that has the stuck disk.

Use Diskutil to Eject a Specific Drive's Media

If it's not already open, launch Terminal, located in the Applications > Utilities folder.

To find out the optical drive's name, issue the following Terminal command:

diskutil list

A list of all the disks currently attached to your Mac is returned by diskutil. The Mac uses identifiers in the following format: diskx where x is a number.

The Mac counts drives starting at 0 and adding 1 for each additional device it finds. Examples of the identifier then are disk0, disk1, disk2, and so on.

Under each disk identifier, you'll see a number of disk segments, corresponding to partitions the base disk has been divided into. You may see entries like this:

diskutil list output

/dev/disk0

    
#:TYPENAMESIZEIDENTIFIER
0:GUID_partition_scheme 500 GBdisk0
1:EFIEFI209.7 MBdisk0s1
2:Apple_HFS Macintosh HD499.8 GBdisk0s2
3:Apple_Boot_RecoveryRecovery HD650 MBdisk0s3

/dev/disk1

    
#:TYPENAMESIZEIDENTIFIER
0:Apple_partition_scheme 7.8 GBdisk1
1:Apple_partition_map 30.7 KBdisk1s1
2:Apple_Driver_ATAPI 1 GBdisk1s2
3:Apple_HFSMac OS X Install6.7 GBdisk1s3

In this example, there are two physical disks (disk0 and disk1), each containing additional partitions. To locate the devices corresponding to your optical drives, find the entries that have a type name of Apple_Driver_ATAPI. Read across to find the identifier, and then use just the base name of the identifier in the diskutil eject command.

As an example:

The DVD that is stuck in the Mac shows up as disk1s3. The stuck disk has three partitions on it: disk1s1, disk1s2, and disk1s3. The Apple_Driver_ATAPI is a good way to distinguish which device is the optical drive, as it is only used with Apple’s Super Drive, and any third-party CD/DVD devices.

Once you have the optical drive's identifier in the example disk1, you're ready to use Terminal to eject the media from the specific drive.

At the Terminal prompt enter:

diskutil eject disk1

Press Enter or Return.

Remember to change the identifier in the above example to match the identifier you found using the diskutil list command.

Quit Terminal.

External DVD Drives

If the stuck media is in an external DVD drive, there is a good chance that it may have an emergency disk eject system. This simple system consists of a small hole usually located just below the DVD drive tray.

To eject a stuck DVD, unfold a paperclip and insert the now straight clip into the ejection hole. When you feel the paperclip pressed against an object, continue to push. The drive tray should start to eject. When the tray is open a small amount, you can pull the tray the rest of the way out.