korechi’s diary

とあるVR/ARエンジニアのブログ

USBメモリをコマンドから使用する(CentOS)

簡単そうに見えて意外とできない、コマンドラインからUSBデバイスを使用する方法をまとめました。
コマンドは3つだけ。
1. dmesgでデバイス名を確認 USBをさしてから

$ dmesg

をして、

usb-storage: device found at 4
usb-storage: waiting for device to settle before scanning
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usb-storage: device scan complete
scsi 7:0:0:0: Direct-Access     Lexar    USB Flash Drive  8.07 PQ: 0 ANSI: 4
sd 7:0:0:0: [sdb] 15659008 512-byte logical blocks: (8.01 GB/7.46 GiB)
sd 7:0:0:0: Attached scsi generic sg2 type 0
sd 7:0:0:0: [sdb] Write Protect is off
sd 7:0:0:0: [sdb] Mode Sense: 23 00 00 00
sd 7:0:0:0: [sdb] Assuming drive cache: write through
sd 7:0:0:0: [sdb] Assuming drive cache: write through
 sdb: sdb1
sd 7:0:0:0: [sdb] Assuming drive cache: write through
sd 7:0:0:0: [sdb] Attached SCSI removable disk

sdb: sdb1と出ている、sdb1がデバイス名です。
2. マウント用のディレクトリを作成し、マウント

$ sudo mkdir /mnt/flash
$ sudo mount -t vfat /dev/sdb1 /mnt/flash

これで、/mnt/flash以下にUSBがマウントされるため、そこで作業を行う。
アンマウントするには

$ sudo umount /mnt/flash