====== USBメモリのext4フォーマット ====== 市販されているUSBメモリは、ほぼVFATフォーマットである。\\ Linuxにもマウントできるが、パーミッション設定に制約がある。\\ そこでext4でフォーマットして使用することにする。 ===== デバイスの確認 ===== フォーマットの前にデバイス情報を確認する。 ==== USBデバイス情報の確認 ==== 該当するデバイスの情報を確認する。\\  => iManufacturer 1 Lexar pi@raspberrypi:~ $ sudo 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 2: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 480M |__ Port 5: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 480M pi@raspberrypi:~ $ sudo lsusb -v -s 1:5 Bus 001 Device 005: ID 21c4:0cc7 Device Descriptor: bLength 18 (中略) iManufacturer 1 Lexar iProduct 2 USB Flash Drive iSerial 3 04BBVG2A7A90AAQB (略) ==== ドライブ情報の確認 ==== ドライブとしてのデバイス情報を確認する。\\  => sdb1 vfat LEXAR 4460-FFDC pi@raspberrypi:~ $ lsblk -f NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINT sda └─sda1 vfat BACKUP 2948-B992 28.3G 1% /media/pi/BACKUP sdb └─sdb1 vfat LEXAR 4460-FFDC mmcblk0 ├─mmcblk0p1 vfat boot 70A2-8001 203.8M 19% /boot └─mmcblk0p2 ext4 rootfs a1fafd2b-1ef0-4fe8-8ac1-ad33bbb48642 18.6G 32% / ==== パーティションの再作成とフォーマット ==== VFATパーティションを削除し、Linuxパーティションを作成する。 pi@raspberrypi:~ $ sudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sdb: 28.9 GiB, 31037849600 bytes, 60620800 sectors Disk model: USB Flash Drive 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: 0x1e5e705b Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 60620799 60618752 28.9G c W95 FAT32 (LBA) Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-60620799, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-60620799, default 60620799): Created a new partition 1 of type 'Linux' and of size 28.9 GiB. Command (m for help): p Disk /dev/sdb: 28.9 GiB, 31037849600 bytes, 60620800 sectors Disk model: USB Flash Drive 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: 0x1e5e705b Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 60620799 60618752 28.9G 83 Linux Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. パーティションテーブルを確認する。 pi@raspberrypi:~ $ sudo fdisk -l /dev/sdb Disk /dev/sdb: 28.9 GiB, 31037849600 bytes, 60620800 sectors Disk model: USB Flash Drive 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: 0x1e5e705b Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 60620799 60618752 28.9G 83 Linux ext4でフォーマットする。 $ sudo mkfs -t ext4 /dev/sdb1 フォーマットと同時にボリュームラベルを設定してもよい。 $ sudo mkfs -t ext4 -L extdisk /dev/sdb1 ===== ボリュームラベルの変更 ===== ボリュームラベルを変更するにはe2labelコマンドを使用する。\\ 2番目のパラメーターを省略したときは、現在のラベルが表示される。 $ sudo e2label /dev/sdb1 extdisk2 $ sudo e2label /dev/sdb1 extdisk2 ===== マウントポイント ===== ''/etc/fstab/''にラベル名で起動時に自動マウントする設定を追加する。 ただし、起動時に取り外しているなどマウントできない状況での起動に影響を与えないため、**nofail**オプションを追加する。 LABEL=BACKUP /media/pi/BACKUP ext4 defaults,user,rw,noexec,nofail 0 0