前回はPidoraのインストール&IP設定まで行いました。
最終目的はRaspberryPiで大容量WEBサーバーの構築なので、SDカードなんかでやってられません。今回はPidoraをHDDから起動させ、HDDの容量をフルにデータ領域として使えるように設定を行います。
簡単に言うとrootfsとswapをSDからHDDに移動します。
今回の作業は「studio propman」さんを参考にさせてもらいました。電子工作のスキルが羨ましいです。
とりあえずPidoraにログインします。前回の設定でIPは192.168.11.100に固定してあります。rootのパスワードはまだ変更してないので、raspberrypiです。
広告
USB-HDDの接続
ログインしたばかりですが、USB-HDDを接続するのを忘れました。
一端シャットダウンしてUSB-HDDを接続し直して再度電源投入
raspberryPiとHDDはUSBハブを介して↓こんな感じで接続されています。
ゴチャゴチャしてわかりにくくてすみません。USBハブはセルフパワーなので、電源的には問題ありません。
使用している電源(USBハブ)と周辺機器は過去の記事で紹介しているので、興味ある方は見てみてください。
HDDの認識を確認
Pidora上でHDDを認識しているか確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@raspi ~]# dmesg | grep sd [ 0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=626 bcm2708_fb.fbheight=386 bcm2708.boardrev=0xe bcm2708.serial=0x1fdc5987 smsc95xx.macaddr=B8:27:EB:DC:59:87 sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait quiet [ 1.292186] sdhci: Secure Digital Host Controller Interface driver [ 1.292197] sdhci: Copyright(c) Pierre Ossman [ 1.292312] sdhci: Enable low-latency mode [ 1.332604] sdhci-pltfm: SDHCI platform and OF driver helper [ 4.329776] sd 0:0:0:0: Attached scsi generic sg0 type 0 [ 4.331569] sd 0:0:0:0: [sda] 625142448 512-byte logical blocks: (320 GB/298 GiB) [ 4.332412] sd 0:0:0:0: [sda] Write Protect is off [ 4.332442] sd 0:0:0:0: [sda] Mode Sense: 3c 00 00 00 [ 4.333422] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA [ 4.392478] sda: sda1 sda2 [ 4.397696] sd 0:0:0:0: [sda] Attached SCSI disk [root@raspi ~]# |
sdaとして認識されているのがわかります。
1代目のハードディスクならほぼ間違いなくsdaとして認識されると思います。
ハードディスクのフォーマット
fdiskで領域を確保します。
1 2 3 4 5 |
fdisk /dev/sda Welcome to fdisk (util-linux 2.22.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): |
コマンドpで現在のパーディションテーブルを確認します。既に領域がある場合は削除しましょう。削除コマンドはdです。
1 2 3 4 5 6 7 8 9 10 |
Command (m for help): p Disk /dev/sda: 320.1 GB, 320072933376 bytes, 625142448 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: 0x9a1214f6 Device Boot Start End Blocks Id System Command (m for help): |
何もないので領域を作成していきます。
swap領域を作成します。コマンドnです。必要ないとは思いますが、適当に512Mとしました。
1 2 3 4 5 6 7 8 9 10 |
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-625142447, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-625142447, default 625142447): +512M Partition 1 of type Linux and of size 512 MiB is set |
swap領域なので、idを変更します。
1 2 3 4 |
Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): 82 Changed system type of partition 1 to 82 (Linux swap / Solaris) |
続いて残りの領域をrootfs用にします。同じくコマンドnです。
1 2 3 4 5 6 7 8 9 10 11 12 |
Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (1-4, default 2): Using default value 2 First sector (1050624-625142447, default 1050624): Using default value 1050624 Last sector, +sectors or +size{K,M,G} (1050624-625142447, default 625142447): Using default value 625142447 Partition 2 of type Linux and of size 297.6 GiB is set |
作成した領域を確認します。コマンドpです
1 2 3 4 5 6 7 8 9 10 11 |
Command (m for help): p Disk /dev/sda: 320.1 GB, 320072933376 bytes, 625142448 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: 0x9a1214f6 Device Boot Start End Blocks Id System /dev/sda1 2048 1050623 524288 82 Linux swap / Solaris /dev/sda2 1050624 625142447 312045912 83 Linux |
問題がなければ書き込んで終了します。コマンドはwです。
1 2 3 4 5 6 |
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@raspi ~]# |
スワップを作成します。
1 2 3 4 |
[root@raspi ~]# mkswap /dev/sda1 mkswap: /dev/sda1: warning: wiping old ext4 signature. Setting up swapspace version 1, size = 524284 KiB no label, UUID=cfe84777-1050-46a9-8dee-822e9dcfc957 |
rootfs用の領域をext4でフォーマットします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@raspi ~]# mkfs.ext4 /dev/sda2 mke2fs 1.42.3 (14-May-2012) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 19505152 inodes, 78011478 blocks 3900573 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 2381 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, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done |
約300GBの領域で30秒程で終わりました。
SDからrootfsを移動します
rootfsの/dev/mmcblk0p2を/dev/sda1に複写
ちょっと時間がかかります。
1 2 3 4 |
[root@raspi dev]# dd if=/dev/mmcblk0p2 of=/dev/sda2 bs=32M conv=noerror,sync 120+1 records in 121+0 records out 4060086272 bytes (4.1 GB) copied, 250.426 s, 16.2 MB/s |
ファイルシステムをチェックします。
エラーが出ますが、yで修復します。
その後再度チェックしてエラーが出ないことを確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[root@raspi dev]# e2fsck -f /dev/sda2 e2fsck 1.42.3 (14-May-2012) rootfs: recovering journal Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Free blocks count wrong (584772, counted=584757). Fix<y>? yes rootfs: ***** FILE SYSTEM WAS MODIFIED ***** rootfs: 63779/248000 files (0.1% non-contiguous), 399051/983808 blocks [root@raspi dev]# e2fsck -f /dev/sda2 e2fsck 1.42.3 (14-May-2012) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information rootfs: 63779/248000 files (0.1% non-contiguous), 399051/983808 blocks |
resize2fsで/dev/sda2を容量いっぱいに拡張します。これ結構時間かかります。
1 2 3 4 |
[root@raspi dev]# resize2fs /dev/sda2 resize2fs 1.42.3 (14-May-2012) Resizing the filesystem on /dev/sda2 to 78011478 (4k) blocks. The filesystem on /dev/sda2 is now 78011478 blocks long. |
作成した領域を適当にマウントして確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[root@raspi dev]# mkdir /tmp/test [root@raspi dev]# mount -t ext4 -o defaults /dev/sda2 /tmp/test [root@raspi dev]# cd /tmp/test/ [root@raspi test]# ll total 92 lrwxrwxrwx 1 root root 7 Jun 20 12:24 bin -> usr/bin drwxr-xr-x 2 root root 4096 Jun 20 12:09 boot drwxr-xr-x 2 root root 4096 Jun 20 12:09 dev drwxr-xr-x 105 root root 12288 Jun 20 14:47 etc drwxr-xr-x 2 root root 4096 Feb 26 16:55 home -rw------- 1 root root 7281 Jun 20 12:44 ks-log-info.txt lrwxrwxrwx 1 root root 7 Jun 20 12:24 lib -> usr/lib drwx------ 2 root root 16384 Jun 20 12:09 lost+found drwxr-xr-x 2 root root 4096 Feb 26 16:55 media drwxr-xr-x 2 root root 4096 Feb 26 16:55 mnt drwxr-xr-x 2 root root 4096 Feb 26 16:55 opt drwxr-xr-x 2 root root 4096 Jun 20 12:09 proc dr-xr-x--- 4 root root 4096 Jun 20 14:52 root drwxr-xr-x 17 root root 4096 Jun 20 12:44 run lrwxrwxrwx 1 root root 8 Jun 20 12:24 sbin -> usr/sbin drwxr-xr-x 2 root root 4096 Feb 26 16:55 srv drwxr-xr-x 2 root root 4096 Jun 20 12:09 sys drwxrwxrwt 2 root root 4096 Jun 20 12:44 tmp drwxr-xr-x 14 root root 4096 Jun 20 12:43 usr drwxr-xr-x 19 root root 4096 Jun 20 12:42 var |
ばっちりです。
ブート設定
/boot/cmdline.txt内の/dev/mmcblk0p2を/dev/sda2に変更します。
1 2 3 |
[root@raspi test]# vi /boot/cmdline.txt dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda2 ro rootfstype=ext4 rootwait quiet |
再起動して確認します。うまく行っていれば起動直後からHDDのアクセスランプが点滅するのを確認できると思います。
再起動完了後ログインして確認
1 2 3 4 5 6 7 8 9 10 |
[root@raspi ~]# df Filesystem 1K-blocks Used Available Use% Mounted on rootfs 307263584 1536768 291917676 1% / /dev/root 307263584 1536768 291917676 1% / devtmpfs 223248 0 223248 0% /dev tmpfs 223336 0 223336 0% /dev/shm tmpfs 223336 836 222500 1% /run tmpfs 223336 0 223336 0% /sys/fs/cgroup tmpfs 223336 4 223332 1% /tmp /dev/mmcblk0p1 51082 17590 33492 35% /boot |
rootfsがでっかくなりました!
swap設定
スワップを有効にします。次回再起動時から自動で有効化されるよう、fstabにも書いて起きます。
1 2 |
[root@raspi ~]# swapon /dev/sda1 [root@raspi ~]# vi /etc/fstab |
1 2 3 4 5 6 7 8 9 10 |
# # /etc/fstab # Created by anaconda # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # LABEL="rootfs" / ext4 defaults,noatime 1 1 LABEL="boot" /boot vfat noauto,comment=systemd.automount 1 2 /dev/sda1 swap swap defaults 0 0 |
再起動して確認します。
ここまできてなかなか起動しません。最後でfstabの記述をミスって起動しないのかと考えるも、モニタを繋いでない(HDMI映せるモニタ持ってません。)ので確認のしようがない。
pingを撃ってみると返答はあるので、2,3分待ったところログインできました。
起動時にファイルシステムのチェックでもしたのかもしれませんが、見えないのでわかりません。
とりあえず起動してよかった。
SWAPも認識してます。
これでやりたいことの環境が整いました。