LoginSignup
18
22

More than 5 years have passed since last update.

rasbianにUSBメモリを認識させる

Posted at

USBメモリを接続する

USBメモリをraspberry pi につなぎ再起動。

$ sudo fdisk -l

Disk /dev/sda: 16.2 GB, 16231956480 bytes
64 heads, 32 sectors/track, 15480 cylinders, total 31703040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System

でディスクが認識されているかを確認。
Disk /dev/sda で認識されるはず。

USBメモリをフォーマットする

$ sudo fdisk /dev/sda

Command (m for help):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-31703039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-31703039, default 31703039):
Using default value 31703039

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

パーティションを作成。

$ sudo fdisk /dev/sda
Command (m for help): p

Disk /dev/sda: 16.2 GB, 16231956480 bytes
64 heads, 32 sectors/track, 15480 cylinders, total 31703040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    31703039    15850496   83  Linux

確認するとLinuxのパーティションが作成されている。

$ sudo mkfs.ext4 /dev/sda1
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
991232 inodes, 3962624 blocks
198131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4060086272
121 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

パーティションをフォーマットする。

USBメモリを起動時にマウントする

$ sudo blkid /dev/sda1
/dev/sda1: UUID="XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" TYPE="ext4"

UUIDを確認する。

$ sudo mkdir /mnt/usb1

マウント用ディレクトリを作成する。

$ sudo vi /etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

起動時のマウント設定ファイルを確認。

$ sudo vi /etc/fstab
/proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
UUID="xxxxxxxxxxxxxxxxxxxxxxxxxx" /mnt/usb1 ext4      defaults        0       2
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

調べたUUIDと先ほど作成したマウントディレクトリを元にマウント設定を追加。

$ sudo reboot

再起動してマウントポイントにアクセスできるかを確認する。

18
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
22