Mount a CD, USB key or disk on Linux (fstab and UUID)
Detect an optical drive, mount a media, identify a disk by UUID and configure fstab.
This page gathers the commands to detect an optical drive, mount a CD, a USB key or a disk on Linux, and make a mount permanent through /etc/fstab using the disk UUID.
Detect the optical drive
dmesg | egrep -i --color 'cdrom|dvd|cd/rw|writer'
lsblk
less /proc/sys/dev/cdrom/info
Mount a CD or DVD
sudo mkdir -p /media/cdrom
sudo mount /dev/sr0 /media/cdrom
Unmount afterwards with sudo umount /media/cdrom.
Mount a remote directory with sshfs
sudo sshfs -o allow_other,default_permissions user@fileserver:/remote/path /mnt/fileserver/
List mounts and disk space
findmnt
cat /proc/mounts
mount -l
df -h
Identify a disk by its UUID
sudo blkid
Example output (dummy UUIDs):
/dev/sdb1: UUID="00000000-0000-0000-0000-000000000000" BLOCK_SIZE="4096" TYPE="ext4"
/dev/sda1: UUID="00000000-0000-0000-0000-000000000000" BLOCK_SIZE="4096" TYPE="ext4"
To make the mount permanent:
- Note the UUID with
sudo blkid. - Back up
/etc/fstab. - Replace
/dev/sdXwithUUID=xxxxin/etc/fstab. - Test with
sudo mount -a. - Check with
df -h.
Automatic mount of a removable disk
With udisks (without fstab):
udisksctl mount -b /dev/sdb1
udisksctl unmount -b /dev/sdb1
Notes
- An error in
/etc/fstabcan prevent the system from booting: test withsudo mount -abefore rebooting.