RaspbianをSDの最大容量まで使えるようにする方法

目次

  1. 1. はじめに
  2. 2. SSHでRaspberry Piに接続
  3. 3. SDのパーティションを変更
  4. 4. タイムゾーンの設定
  5. 5. Raspbianのアップデート
  6. 6. Raspberry Piのファームウェアを更新

はじめに

前回は、RaspbianをMicroSDカードに書き込むところまで書きました。

Raspberry Pi2(Raspbian)の初期設定 | Gazee

https://gazee.net/develop/raspberry-pi-raspbian-setup/

今回は、以下の内容を行っていきます。

  • SDカードを最大容量まで使うために、パーティションの変更
  • タイムゾーンをJSTに変更
  • Raspbianのアップデート
  • RaspberryPiのファームウェアをアップデート

SSHでRaspberry Piに接続

デフォルトの設定は以下のようになっています。

  • ユーザ名:pi
  • パスワード:raspberry

Teratermなどのターミナルでログインが可能です。

SDのパーティションを変更

Win32 Disk Imagerを使ってRaspbianをMicroSDに書き込んだ場合、使用できるディスク領域が最大2GB程度になってしまいます。これはRaspbianのイメージが容量の小さいSDカードを想定しているためです。

このままだとMicroSDカードの容量を使い切ることができないので設定を行います。

これから入力するコマンドの中でStart sectorLast sector環境によって違います

  • Start sector:pコマンドを実行した結果の/dev/mmcblk0p2Start値(今回の例だと131072)
  • End sector:空欄

上記を踏まえ以下のようにコマンドを実行していきます。以下のログは設定済みのRaspbianを利用しているため、初期状態のRaspbianとは構成が若干ことなりますが、問題ありません。

sudo fdisk -uc /dev/mmcblk0
Command (m for help): p
Device         Boot  Start      End  Sectors Size Id Type
/dev/mmcblk0p1        8192   131071   122880  60M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      131072 62945279 62814208  30G 83 Linux

Command (m for help): d
Pertition number (1-4): 2

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number: 2
First sector(...): 131072
Last sector(...): [空欄でEnter]

Command (m for help): w

sudo reboot

sudo resize2fs /dev/mmcb1k0p2

sudo reboot

自分で入力しなければならない部分だけまとめると以下のようになります。

sudo fdisk -uc /dev/mmcblk0
p
d
2
n
p
2
131072
[空欄でEnter]
w

sudo reboot

sudo resize2fs /dev/mmcb1k0p2

sudo reboot

タイムゾーンの設定

Raspbianのタイムゾーンを日本標準時(JST)に変更します。

echo "Asia/Tokyo" | sudo tee /etc/timezone
sudo dpkg-reconfigure --frontend noninteractive tzdata

Raspbianのアップデート

sudo apt-get update
sudo apt-get upgrade

Raspberry Piのファームウェアを更新

この作業を行う場合は、アップデートが終了するまで絶対に電源を切らないでください。RaspberryPiが壊れて起動しなくなる可能性があります。

sudo rpi-update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10670  100 10670    0     0  37886      0 --:--:-- --:--:-- --:--:-- 37971
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** We're running for the first time
 *** Backing up files (this will take a few minutes)
 *** Backing up firmware
 *** Backing up modules 4.1.19-v7+
#############################################################
WARNING: This update bumps to rpi-4.4.y linux tree
Be aware there could be compatibility issues with some drivers
Discussion here:
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=144087
##############################################################
Would you like to proceed? (y/N)
 *** Downloading specific firmware revision (this will take a few minutes)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   168    0   168    0     0    203      0 --:--:-- --:--:-- --:--:--   203
100 50.2M  100 50.2M    0     0  2071k      0  0:00:24  0:00:24 --:--:-- 2304k
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 4.4.7+
 *** depmod 4.4.7-v7+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to f063c24a8307ae57040eda58f4751a97efdf7ab8
 *** A reboot is needed to activate the new firmware