How to manually mount a USB flash drive in a non-graphical environment
Environment
- Red Hat Enterprise Linux 4
- Red Hat Enterprise Linux 5
- Red Hat Enterprise Linux 6
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
Issue
- How do I mount a USB flash drive from the command line?
- How do I disconnect the USB flash drive?
Resolution
- Monitor the system messages log to see what device the USB key is assigned to.
- For RHEL 7 and earlier, run
tail -f /var/log/messagesas root. - For RHEL 8 and later, run
journalctl -fas root. lsblkcommand can be used to list all detected block devices.
-
Once a device node has been assigned to the key (
sdXywhereXis a letter andyis a partition number), press 'CTRL + C' to exit the tail. -
Create a directory to mount the device in:
# mkdir -p /mnt/usb -
Mount the appropriate partition from the USB drive into that new directory:
# mount /dev/sdXy /mnt/usb -
Use the USB drive via
/mnt/usb/ -
Unmount the filesystem.
# umount /mnt/usb -
Check if the filesystem has been unmountd.
# lsblk or # cat /proc/mounts | grep /mnt/sdXy -
Disconnect the USB drive.
Diagnostic Steps
- Review the system logs at
/var/log/messagesor injournalctlto determine which device the USB drive was added as. The following example presentssdb1:
# tail -n 18 -f /var/log/messages
Aug 2 11:01:32 host1 kernel: usb 1-8: new high speed USB device number 6 using ehci_hcd <----- New USB device
Aug 2 11:01:32 host1 kernel: usb 1-8: New USB device found, idVendor=0781, idProduct=5530
Aug 2 11:01:32 host1 kernel: usb 1-8: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Aug 2 11:01:32 host1 kernel: usb 1-8: Product: Cruzer
Aug 2 11:01:32 host1 kernel: usb 1-8: Manufacturer: SanDisk
Aug 2 11:01:32 host1 kernel: usb 1-8: SerialNumber: x
Aug 2 11:01:32 host1 kernel: usb 1-8: configuration #1 chosen from 1 choice
Aug 2 11:01:32 host1 kernel: scsi11 : SCSI emulation for USB Mass Storage devices
Aug 2 11:01:33 host1 kernel: scsi 11:0:0:0: Direct-Access SanDisk Cruzer 1.26 PQ: 0 ANSI: 5
Aug 2 11:01:33 host1 kernel: sd 11:0:0:0: Attached scsi generic sg2 type 0
Aug 2 11:01:33 host1 kernel: sd 11:0:0:0: [sdb] 62530624 512-byte logical blocks: (32.0 GB/29.8 GiB) <--- sdb
Aug 2 11:01:33 host1 kernel: sd 11:0:0:0: [sdb] Write Protect is off
Aug 2 11:01:33 host1 kernel: sd 11:0:0:0: [sdb] Assuming drive cache: write through
Aug 2 11:01:33 host1 kernel: sd 11:0:0:0: [sdb] Assuming drive cache: write through
Aug 2 11:01:33 host1 kernel: sdb: sdb1 <---------- partition on sdb1
Aug 2 11:01:33 host1 kernel: sd 11:0:0:0: [sdb] Assuming drive cache: write through
Aug 2 11:01:33 host1 kernel: sd 11:0:0:0: [sdb] Attached SCSI removable disk
SBR
Product(s)
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.