====== USBメモリのマウント先固定 ======
バックアップに使用しているUSBメモリのマウント先を、物理ポートに対応させたマウントポイントに設定する。
* 参考情報[[https://qiita.com/titilat/items/018d3e1bb845b382c45e?utm_source=pocket_saves|USBメモリを指すポートによって、マウント先を固定する方法]]
===== 物理ポートの確認 =====
lsusbコマンドでUSBメモリの使用している物理ポートを確認する。
下記の場合は**Port 4: Dev 4**とわかる。
pi@raspberrypi:~ $ lsusb -t
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
|__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
|__ Port 4: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 480M
===== by-pathの確認 =====
マウントポイントからby-pathの情報を確認する。
/media/usb1のデバイスは**/dev/sda1**でありby-pathは**platform-3f980000.usb-usb-0:1.4:1.0-scsi-0:0:0:0-part1**であるとわかる。
pi@raspberrypi:~ $ df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
/dev/root 29G 8.6G 20G 31% /
devtmpfs 430M 0 430M 0% /dev
tmpfs 462M 0 462M 0% /dev/shm
tmpfs 462M 7.6M 455M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 462M 0 462M 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 49M 204M 20% /boot
tmpfs 93M 4.0K 93M 1% /run/user/1000
/dev/sda1 29G 1.6M 29G 1% /media/usb02
pi@raspberrypi:~ $
pi@raspberrypi:~ $ ls -al /dev/disk/by-path
合計 0
drwxr-xr-x 2 root root 140 7月 5 13:08 .
drwxr-xr-x 7 root root 140 7月 5 13:08 ..
lrwxrwxrwx 1 root root 13 7月 5 13:08 platform-3f202000.mmc -> ../../mmcblk0
lrwxrwxrwx 1 root root 15 7月 5 13:08 platform-3f202000.mmc-part1 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 15 7月 5 13:08 platform-3f202000.mmc-part2 -> ../../mmcblk0p2
lrwxrwxrwx 1 root root 9 7月 5 13:08 platform-3f980000.usb-usb-0:1.2:1.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 7月 5 13:08 platform-3f980000.usb-usb-0:1.2:1.0-scsi-0:0:0:0-part1 -> ../../sda1
===== マウントポイントの設定 =====
残念ながらこの設定は**OSを起動不能**にする場合がある。\\
by-pathをfstabに設定する。
/dev/disk/by-path/platform-3f980000.usb-usb-0:1.2:1.0-scsi-0:0:0:0-part1 /media/usb1 vfat defaults,umask=000 0 0
* USBメモリはVFATフォーマットで市販されていることが多く、VFATファイルシステムではパーミッション設定はできないため、umaskオプションで、マウント時のパーミッションを設定する。
===== マウントポイントの設定2 =====
もっと単純な方法がある。\\
- USBメモリにラベルを付ける。
- ラベルでfstabにマウントポイントを設定する。
- ただし起動時のマウントではなく、systemd.automountにマウントしてもらう。(noauto)
- VFATなのでchmod/chownはできないので、マウントポイントにumaskでパーミッションを設定する。
まずはラベル設定ツールを導入する。
$ sudo apt search mtools
$ sudo apt-get install mtools
デバイス情報を調べてラベルを設定する。
$ sudo fdisk -l
Disk /dev/sda: 28.7 GiB, 30765219840 bytes, 60088320 sectors
Disk model: SanDisk 3.2Gen1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/sda1 32 60088319 60088288 28.7G c W95 FAT32 (LBA)
$ sudo mlabel -i /dev/sda1 ::BACKUP
fstabにマウントポイントやオプションを設定する。
LABEL=BACKUP /media/pi/BACKUP vfat defaults,noauto,user,rw,noexec,umask=000 0 0
再起動してマウントされるかどうかを確認する。
$ df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
/dev/root 29G 8.7G 20G 32% /
devtmpfs 430M 0 430M 0% /dev
tmpfs 462M 0 462M 0% /dev/shm
tmpfs 462M 7.6M 455M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 462M 0 462M 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 49M 204M 20% /boot
tmpfs 93M 4.0K 93M 1% /run/user/1000
/dev/sdb1 29G 125M 29G 1% /media/pi/LEXAR
/dev/sda1 29G 132M 29G 1% /media/pi/BACKUP
===== ext4ディスクのボリュームラベル設定 =====
* [[usbメモリのext4フォーマット|]]
* ボリュームラベルの変更