LinuxでSDカードを使う
Table of Contents
環境
CentOS 7
fdisk
デバイスの確認
[wurly@myserver /]$ dmesg | grep sdb [ 3.900041] sd 2:0:0:0: [sdb] Attached SCSI removable disk [2022741.305129] sd 3:0:0:0: [sdb] Attached SCSI removable disk [2322742.187686] sd 4:0:0:0: [sdb] Attached SCSI removable disk [2696029.542416] sd 5:0:0:0: [sdb] Attached SCSI removable disk [3564126.186068] sd 7:0:0:0: [sdb] Attached SCSI removable disk [4062899.105343] sd 7:0:0:0: [sdb] 63272960 512-byte logical blocks: (32.3 GB/30.1 GiB) [4062899.108432] sdb: sdb1 [4065382.265304] sdb: detected capacity change from 32395755520 to 0 [4065497.291300] sd 7:0:0:0: [sdb] 63272960 512-byte logical blocks: (32.3 GB/30.1 GiB) [4065497.293905] sdb: sdb1
fdisk
d で削除
n で p でプライマリパーティションを作成する(パラメータはすべてデフォルト)
w で 書き込み
[wurly@myserver /]$ sudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. コマンド (m でヘルプ): p Disk /dev/sdb: 32.4 GB, 32395755520 bytes, 63272960 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk label type: dos ディスク識別子: 0x00000000 デバイス ブート 始点 終点 ブロック Id システム /dev/sdb1 2048 63272959 31635456 83 Linux コマンド (m でヘルプ): w パーティションテーブルは変更されました! ioctl() を呼び出してパーティションテーブルを再読込みします。 ディスクを同期しています。 [wurly@myserver /]$
フォーマット
mkfs.ext4
$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1978592 inodes, 7908864 blocks
395443 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2155872256
242 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
ラベル
ラベルの確認、ラベルの設定、ラベルの確認
usb_sdcard1 というラベルを付ける
$ sudo e2label /dev/sdb1 $ sudo e2label /dev/sdb1 usb_sdcard1 $ sudo e2label /dev/sdb1 usb_sdcard1
マウント方法
ラベルを指定してマウントする
wurly:‾# mount LABEL=usb_sdcard1 /mnt/usb_sdcard1