Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

eject

Eject removable media.

Synopsis

eject [options] [device|mountpoint]

Operation

Ejects removable media (CD-ROM, USB drives, etc.) by trying multiple eject methods in sequence until one succeeds. Automatically unmounts the device (and its partitions) before ejecting.

Eject methods (tried in order)

  1. CD-ROM (-r): CDROMEJECT ioctl (0x5309)
  2. SCSI (-s): SG_IO ioctl with SCSI START_STOP command (works for USB mass storage)
  3. Floppy (-f): FDEJECT ioctl
  4. Tape (-q): MTIOCTOP with MTOFFL

If a specific method is requested via flags, only that method is tried.

Tray operations

  • --trayclose (-t): Close tray via CDROMCLOSETRAY (0x5319)
  • --traytoggle (-T): Query status via CDROM_DRIVE_STATUS (0x5326), then close or open accordingly

Lock/unlock

  • --manualeject on: Lock hardware eject button via CDROM_LOCKDOOR (0x5329, arg=1)
  • --manualeject off: Unlock via CDROM_LOCKDOOR (arg=0)

Inputs

SourcePurpose
Device argument or /dev/cdromTarget device to eject
/proc/mountsFind mounted filesystems for auto-unmount
/sys/block/*/devResolve partitions to whole disk

Outputs

  • Device ioctls to eject/close/lock media
  • Calls umount(8) to unmount before ejecting

Ioctls

IoctlValueDescription
CDROMEJECT0x5309Eject CD-ROM media
CDROMCLOSETRAY0x5319Close CD-ROM tray
CDROM_LOCKDOOR0x5329Lock/unlock hardware eject button
CDROM_DRIVE_STATUS0x5326Query tray open/closed status
SG_IO0x2285Send SCSI commands (START_STOP for eject)
FDEJECT0x025aEject floppy disk

SCSI commands (via SG_IO)

CommandOpcodeDescription
ALLOW_MEDIUM_REMOVAL0x1eUnlock media before eject
START_STOP0x1bLoEj=1, Start=0 → eject media

Command-line options

OptionDescription
-a, --auto <on|off>Toggle auto-eject mode
-c, --changerslot <N>Select CD changer slot
-d, --defaultDisplay default device name
-F, --forceForce eject, skip device type check
-f, --floppyUse floppy eject method
-i, --manualeject <on|off>Lock/unlock hardware eject button
-M, --no-partitions-unmountDon’t unmount other partitions
-m, --no-unmountDon’t unmount at all
-n, --noopShow device but take no action
-p, --procUse /proc/mounts instead of /etc/mtab
-q, --tapeUse tape drive offline command
-r, --cdromUse CD-ROM eject command
-s, --scsiUse SCSI eject commands
-T, --traytoggleToggle tray open/close
-t, --traycloseClose CD-ROM tray
-v, --verboseVerbose output
-h, --helpDisplay help
-V, --versionDisplay version

Exit codes

CodeMeaning
0Success
1Failure

Permissions

Requires sufficient permissions to open the device (typically root or membership in cdrom/disk group).

Not yet implemented

  • -X, --listspeed (list CD-ROM speeds)
  • -x, --cdspeed (set CD-ROM speed)
  • -c, --changerslot (CD changer slot selection)
  • -a, --auto (auto-eject mode)
  • UUID= / LABEL= device specifiers
  • Partition-to-whole-disk resolution via sysfs