先日raspberry pi2にCentOS 7.2を入れたときたときのメモ(1)。
32GBのmicroSDカードにインストールしたんですが、raspberry pi2向けのCentOSって/領域に/tmpと/boot以外のディレクトリが設定されているのに、インストール直後の容量は2GBしかないんですね。なので未使用の領域を使い切るように変更してみました。
[root@centos-rpi2 ~]# df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
/dev/root 2.0G 835M 999M 46% /
〜 以下略
[root@centos-rpi2 ~]#
調べていたら、/root/README に拡張の方法が記載されてる、とのことだったので読んでみたら、/領域を拡張したければこれ実行してね!との記載があったので早速実行…してみたんですが、エラー吐いて失敗しました。
[root@centos-rpi2 ~]# cat /root/README
== CentOS 7 userland ==
If you want to automatically resize your / partition, just type the following (as root user):
/usr/local/bin/rootfs-expand
[root@centos-rpi2 ~]#
[root@centos-rpi2 ~]# /usr/local/bin/rootfs-expand
Extending partition 3 to max size ....
/usr/bin/growpart: 行 170: シリンダ数*4、16*: 構文エラー: オペランドが予期されます (エラーのあるトークンは "シリンダ数*4、16*")
Resizing ext4 filesystem ...
resize2fs 1.42.9 (28-Dec-2013)
The filesystem is already 524288 blocks long. Nothing to do!
Done.
[root@centos-rpi2 ~]#
ので、以下のサイトを参考に手動で拡張することに。
Raspberry Piでパーティションを拡張する – UbuntuによるEco Linuxサーバ構築記
まずは/領域が使っているパーティションの確認を。
[root@centos-rpi2 /]# fdisk -l
〜 中略
デバイス ブート 始点 終点 ブロック Id システム
/dev/mmcblk0p1 2048 1026047 512000 c W95 FAT32 (LBA)
/dev/mmcblk0p2 1026048 2074623 524288 82 Linux swap / Solaris
/dev/mmcblk0p3 2074624 6268927 2097152 83 Linux
Disk /dev/sda: 1000.2 GB, 1000204883968 bytes, 1953525164 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xf34a8ee0
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 2048 1953525163 976761558 83 Linux
[root@centos-rpi2 /]#
/領域のパーティションが /dev/mmcblk0p3 ということを確認して、 拡張作業に。
root@centos-rpi2 /]# fdisk /dev/mmcblk0
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/mmcblk0: 31.3 GB, 31268536320 bytes, 61071360 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x00089999
デバイス ブート 始点 終点 ブロック Id システム
/dev/mmcblk0p1 2048 1026047 512000 c W95 FAT32 (LBA)
/dev/mmcblk0p2 1026048 2074623 524288 82 Linux swap / Solaris
/dev/mmcblk0p3 2074624 6268927 2097152 83 Linux
コマンド (m でヘルプ): d ←パーティション削除を指定
パーティション番号 (1-3, default 3): 3 ←削除対象として /dev/mmcblk0p3 を指定
Partition 3 is deleted
コマンド (m でヘルプ): p ←/dev/nncblk0p3 が削除されたことを確認
Disk /dev/mmcblk0: 31.3 GB, 31268536320 bytes, 61071360 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x00089999
デバイス ブート 始点 終点 ブロック Id システム
/dev/mmcblk0p1 2048 1026047 512000 c W95 FAT32 (LBA)
/dev/mmcblk0p2 1026048 2074623 524288 82 Linux swap / Solaris
コマンド (m でヘルプ): n ←新規パーティション作成
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p ←primaryを指定
パーティション番号 (3,4, default 3): 3 ←こだわりはないので、デフォルトを指定
最初 sector (2074624-61071359, 初期値 2074624): ←リターンキーを押下して初期値を指定
初期値 2074624 を使います
Last sector, +sectors or +size{K,M,G} (2074624-61071359, 初期値 61071359): ←最大値である初期値を指定
初期値 61071359 を使います
Partition 3 of type Linux and of size 28.1 GiB is set
コマンド (m でヘルプ): w ←書き込み
パーティションテーブルは変更されました!
ioctl() を呼び出してパーティションテーブルを再読込みします。
WARNING: Re-reading the partition table failed with error 16: デバイスもしくはリソースがビジー状態です.
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)
ディスクを同期しています。
ここで一回OSをリブートして、/領域のサイズが2GBのまま変わっていないこと、ただしmmcblk0p3のブロックサイズは変わってることを確認しました。
[root@centos-rpi2 /]# systemctl reboot
Connection to *.*.*.* closed by remote host.
〜 中略
[root@centos-rpi2 ~]# df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
/dev/root 2.0G 835M 999M 46% /
〜 中略
[root@centos-rpi2 ~]#
[root@centos-rpi2 ~]# fdisk -l
Disk /dev/mmcblk0: 31.3 GB, 31268536320 bytes, 61071360 sectors
Units = sectors of 1 * 512 = 512 bytes
〜 中略
/dev/mmcblk0p1 2048 1026047 512000 c W95 FAT32 (LBA)
/dev/mmcblk0p2 1026048 2074623 524288 82 Linux swap / Solaris
/dev/mmcblk0p3 2074624 61071359 29498368 83 Linux
Disk /dev/sda: 1000.2 GB, 1000204883968 bytes, 1953525164 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xf34a8ee0
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 2048 1953525163 976761558 83 Linux
[root@centos-rpi2 ~]#
そして、いよいよ/領域をresize2fsでリサイズします。
[root@centos-rpi2 ~]# resize2fs /dev/mmcblk0p3
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mmcblk0p3 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 4
The filesystem on /dev/mmcblk0p3 is now 7374592 blocks long.
[root@centos-rpi2 ~]#
resize2fsが終了したらdfで確認、めでたく/領域が28GBとなりました。
[root@centos-rpi2 ~]# df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
/dev/root 28G 840M 26G 4% /
〜 中略
[root@centos-rpi2 ~]#
よし、これで目一杯使えるようになったぞ。使いきれる気はしないけど。