MacFeeling Blog

マックな感じ …

Raspberry Piのセットアップ(USBメモリ認識編)Stretch版

公開 : | 0件のコメント

この記事は最終更新日から 約2年が経過しているので情報が古い可能性があります。

Raspberry PiにUSBカメラを接続して、motionで 動体検知対応のカメラとして機能させるまでの備忘録
今回はUSBメモリ認識編

(ターミナルのログは所々Jessieの時のものを使っています...)

環境は
USBカメラとの相性で、OS「Raspbian」はちょっと古いですがStretch版を利用
macOS Monterey 12.1
すべてマックのターミナル.appを使っての操作です。

motionを導入するにあたって、motionが作成する画像の保存先を外付けのUSBメモリにするための設定をしました。

参考ページ
rasbianにUSBメモリを認識させる - Qiita

ここも参考ページのままなのですが、一応説明を :wink_wp:

まず、Raspberry Piが起動している場合は、一旦終了させてから
USBメモリをRaspberry Piに接続。

USBメモリは飛び出している部分が小さいものが良かったので、SanDiskの16GBのもの(SDCZ33-016G-B35)を使いました。

Raspberry Piを起動させたら、
Macのターミナルを起動して、sshにて接続

まず、USBメモリが認識されているかを確認します。(入力するのは「」の中)
sudo fdisk -l」と入力してリターンキー

最後の方に /dev/sda1 というのが該当するもののようです。
以下の例では /dev/sda1 で進めていきます。(環境によっては違うかもしれませんので、その場合は置き換えてください。)

Disk /dev/sda: 14.6 GiB, 15631122432 bytes, 30529536 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: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1          32 30529535 30529504 14.6G  c W95 FAT32 (LBA)

パーティションを作成します
sudo fdisk /dev/sda1」と入力してリターンキー

Command (m for help):となったら新規の作成なので
n」と入力してリターンキー

Partition type
Select (default p):となったら
p」と入力してリターンキー

Partition number (1-4, default 1):となったら
1」と入力してリターンキー

First sector (2048-30529535, default 2048):となったら
2048」と入力してリターンキー

Last sector, +sectors or +size{K,M,G,T,P} (2048-30529535, default 30529535):となったら
30529535」と入力してリターンキー

Command (m for help):となったら書き込みをするので
w」と入力してリターンキー

pi@raspberrypi:~ $ sudo fdisk /dev/sda

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): 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-30529535, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-30529535, default 30529535): 30529535

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

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

再起動するので
sudo reboot」と入力してリターンキー

Raspberry Piが再起動したら、Macのターミナルを起動してssh接続をする。

パーティションが作成されているかを確認します。
sudo fdisk /dev/sda」と入力してリターンキー

Command (m for help):となったら
p」と入力してリターンキー

/dev/sda1 2048 30529535 30527488 14.6G 83 Linux
のようになっていればOKです。

Command (m for help): となったら
q」と入力してリターンキー

pi@raspberrypi:~ $ sudo fdisk /dev/sda

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): p
Disk /dev/sda: 14.6 GiB, 15631122432 bytes, 30529536 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: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 30529535 30527488 14.6G 83 Linux

Command (m for help): q

pi@raspberrypi:~ $ 

フォーマットします。

sudo mkfs.ext4 /dev/sda1」と入力してリターンキー

pi@raspberrypi:~ $ sudo mkfs.ext4 /dev/sda1
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 3815936 4k blocks and 954720 inodes
Filesystem UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
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   
done

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

UUIDの確認(後で使います)
sudo blkid /dev/sda1」と入力してリターンキー

$ sudo blkid /dev/sda1
/dev/sda1: UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="ext4"

UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"の部分をテキストエディタにコピーしておきます。

マウント用ディレクトリを作成
ここでは、参考ページと同じく/mnt/usb1というのにします。

sudo mkdir /mnt/usb1」と入力してリターンキー

設定ファイルを編集
sudo nano /etc/fstab」と入力してリターンキー

以下の行を追加
UUIDの確認で表示された、UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"を使って、#の行の前に追加。

UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" /mnt/usb1 ext4   defaults   0   2

問題なければ、「controlキー + o
File Name to Writeと下に表示されたらリターンキー
controlキー + x」で編集を終了します。

再起動します。
sudo reboot」と入力してリターンキー

Raspberry Piが再起動したら、Macのターミナルを起動してssh接続をする。

マウントされているかを確認します。

df」と入力してリターンキー

/dev/sda1 14892976 37264 14076144 1% /mnt/usb1
のようになっていればマウントされています。

$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root       15334608 3450516  11206488  24% /
devtmpfs          469540       0    469540   0% /dev
tmpfs             473872       0    473872   0% /dev/shm
tmpfs             473872    6432    467440   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             473872       0    473872   0% /sys/fs/cgroup
/dev/sda1       14892976   37264  14076144   1% /mnt/usb1
/dev/mmcblk0p1     64456   21016     43440  33% /boot
tmpfs              94776       0     94776   0% /run/user/1000

これでmotionインストールに向けての準備が完了しました。

次回、motion編です。

補足
Raspberry Piの終了について
sudo shutdown -h now」と入力してリターンキー

緑色のランプが何度か点滅して、赤色のランプのみの点灯になれば、コンセントから抜いて大丈夫です。

$ sudo shutdown -h now
Connection to 192.168.0.123 closed by remote host.
Connection to 192.168.0.123 closed.

コメントを残す

必須欄は * がついています




日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)