HDD 増設 on Raspberry Pi 3 Model B (Raspbian)


HDD 増設 on Raspberry Pi 3 Model B (Raspbian Jessie 2016-05-10)

USB で HDD を接続し,fdisk を実行して,HDD の情報を表示します.

sudo fdisk -l


Disklabel type: dos
Disk identifier: 0x19dc05e9

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   137215   129024   63M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      137216 63272959 63135744 30.1G 83 Linux

Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 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
Disklabel type: dos
Disk identifier: 0x3fd74b11

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 976773167 976771120 465.8G 83 Linux

HDD をフォーマットします.sdX の X は任意のアルファベット小文字です.間違えると重要なデータが消えることになるので細心の注意を払います.

sudo fdisk /dev/sdX


Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): 

m を選択すると、ずらっとオプションが表示されます。

Command (m for help): m


   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

   d   delete a partition
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table

   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): d
No partition is defined yet!
Could not delete partition 81165

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-976773167, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-976773167, default 976773167): 

Created a new partition 1 of type 'Linux' and of size 465.8 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

再度,fdisk を実行してみます.

sudo fdisk -l


Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 976773167 976771120 465.8G 83 Linux

HDD を ext4 でフォーマットします.

sudo mkfs.ext4 /dev/sdX1


mke2fs 1.42.12 (29-Aug-2014)
/dev/sda1 contains a ext4 file system
	last mounted on /mnt/hdd on Wed Jun  1 06:29:06 2016
Proceed anyway? (y,n) y
Creating filesystem with 122096390 4k blocks and 30531584 inodes
Filesystem UUID: cddde517-ffbb-4caf-a551-ddb24663fcb2
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 

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

HDD をマウントするためのディレクトリを作成し,そこにマウントします.

sudo mkdir /mnt/hdd
sudo mount /dev/sdX1 /mnt/hdd

HDD にアクセスし,ファイルを作成してみます.

cd /mnt/hdd
sudo touch test.txt

OS 起動時に HDD が自動マウントされるようにします.

HDD の UUID を確認します.

sudo blkid /dev/sdX1


/dev/sda1: UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="ext4" PARTUUID="xxxxxxxx-xx"

/etc/fstab を開きます.

sudo vi /etc/fstab

HDD の情報を追記します.

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx       /mnt/hdd        ext4    defaults        0       0

OS を再起動します。

sudo reboot

増設した HDD が,自動でマウントされていることを確認します.

Raspberry Pi