grubを両方のハードディスクにインストールする
今日はソフトウェアRAIDを組んでいる場合の話です。
環境はCentOSです。
ブート領域をRAIDにする事も多いと思います。
普通にインストールすると、grubが一本目のディスクにしか
インストールされません。
このままだと1本目のディスクが壊れた時に、
何か別の手段を取らないとブートできないという事態になります。
自分用メモも兼ねてまとめます。
ディスクパーティションの確認
今回のマシンはハードディスクを2本付けており、
それぞれソフトウェアRAID1の構成にしています。
「sfdisk」の結果はこんな感じです。
# sfdisk -l /dev/sda ディスク /dev/sda: シリンダ数 30401、ヘッド数 255、63 セクタ/トラック ユニット = 8225280 バイトのシリンダ、1024 バイトのブロック、0 から数えます Device Boot Start End #cyls #blocks Id System /dev/sda1 * 0+ 12 13- 104391 fd Linux raid 自動検出 /dev/sda2 13 522 510 4096575 fd Linux raid 自動検出 /dev/sda3 523 30400 29878 239995035 fd Linux raid 自動検出 /dev/sda4 0 - 0 0 0 空 # sfdisk -d /dev/sda # /dev/sda のパーティションテーブル unit: sectors /dev/sda1 : start= 63, size= 208782, Id=fd, bootable /dev/sda2 : start= 208845, size= 8193150, Id=fd /dev/sda3 : start= 8401995, size=479990070, Id=fd /dev/sda4 : start= 0, size= 0, Id= 0 # sfdisk -l /dev/sdb ディスク /dev/sdb: シリンダ数 30401、ヘッド数 255、63 セクタ/トラック ユニット = 8225280 バイトのシリンダ、1024 バイトのブロック、0 から数えます Device Boot Start End #cyls #blocks Id System /dev/sdb1 * 0+ 12 13- 104391 fd Linux raid 自動検出 /dev/sdb2 13 522 510 4096575 fd Linux raid 自動検出 /dev/sdb3 523 30400 29878 239995035 fd Linux raid 自動検出 /dev/sdb4 0 - 0 0 0 空 # sfdisk -d /dev/sdb # /dev/sdb のパーティションテーブル unit: sectors /dev/sdb1 : start= 63, size= 208782, Id=fd, bootable /dev/sdb2 : start= 208845, size= 8193150, Id=fd /dev/sdb3 : start= 8401995, size=479990070, Id=fd /dev/sdb4 : start= 0, size= 0, Id= 0
同様に「fdisk」の結果です。
# fdisk -l /dev/sda Disk /dev/sda: 250.0 GB, 250059350016 bytes 255 heads, 63 sectors/track, 30401 cylinders Units = シリンダ数 of 16065 * 512 = 8225280 bytes デバイス Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 fd Linux raid 自動検出 /dev/sda2 14 523 4096575 fd Linux raid 自動検出 /dev/sda3 524 30401 239995035 fd Linux raid 自動検出 # fdisk -l /dev/sdb Disk /dev/sdb: 250.0 GB, 250059350016 bytes 255 heads, 63 sectors/track, 30401 cylinders Units = シリンダ数 of 16065 * 512 = 8225280 bytes デバイス Boot Start End Blocks Id System /dev/sdb1 * 1 13 104391 fd Linux raid 自動検出 /dev/sdb2 14 523 4096575 fd Linux raid 自動検出 /dev/sdb3 524 30401 239995035 fd Linux raid 自動検出
「df」コマンドの結果、「/etc/fstab」「/proc/mdstat」はこんな感じです。
# df -k Filesystem 1K-ブロック 使用 使用可 使用% マウント位置 /dev/md2 232475456 4531404 215944308 3% / /dev/md0 101018 25440 70362 27% /boot tmpfs 1669748 0 1669748 0% /dev/shm # cat /etc/fstab /dev/md2 / ext3 defaults 1 1 /dev/md0 /boot ext3 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/md1 swap swap defaults 0 0 # cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sdb1[1] sda1[0] 104320 blocks [2/2] [UU] md1 : active raid1 sdb2[1] sda2[0] 4096448 blocks [2/2] [UU] md2 : active raid1 sdb3[1] sda3[0] 239994944 blocks [2/2] [UU] unused devices: <none>
grubのインストール
まず、grubの設定を確認します。
「root(hd0,0)」となっているので、一本目のハードディスクのみ指定されています。
# cat /boot/grub/grub.conf # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/md2 # initrd /initrd-version.img #boot=/dev/md0 default=2 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz #hiddenmenu title CentOS (2.6.18-194.26.1.el5xen) root (hd0,0) kernel /xen.gz-2.6.18-194.26.1.el5 module /vmlinuz-2.6.18-194.26.1.el5xen ro root=/dev/md2 module /initrd-2.6.18-194.26.1.el5xen.img title CentOS (2.6.18-194.26.1.el5debug) root (hd0,0) kernel /vmlinuz-2.6.18-194.26.1.el5debug ro root=/dev/md2 initrd /initrd-2.6.18-194.26.1.el5debug.img title CentOS (2.6.18-194.26.1.el5) root (hd0,0) kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=/dev/md2 initrd /initrd-2.6.18-194.26.1.el5.img
先に2本目のディスクにgrubをインストールします。
# grub Probing devices to guess BIOS drives. This may take a long time. GNU GRUB version 0.97 (640K lower / 3072K upper memory) [ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename.] grub> root (hd1,0) root (hd1,0) Filesystem type is ext2fs, partition type 0xfd grub> setup (hd1) setup (hd1) Checking if "/boot/grub/stage1" exists... no Checking if "/grub/stage1" exists... yes Checking if "/grub/stage2" exists... yes Checking if "/grub/e2fs_stage1_5" exists... yes Running "embed /grub/e2fs_stage1_5 (hd1)"... 15 sectors are embedded. succeeded Running "install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/grub.conf"... succeeded Done. grub> quit quit
2本目のディスクからもブートできるように設定を追加します。
(今回は区別できるよう、タイトルに「-disk2」を入れています)
# cat /boot/grub/grub.conf # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/md2 # initrd /initrd-version.img #boot=/dev/md0 default=2 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz #hiddenmenu title CentOS (2.6.18-194.26.1.el5xen) root (hd0,0) kernel /xen.gz-2.6.18-194.26.1.el5 module /vmlinuz-2.6.18-194.26.1.el5xen ro root=/dev/md2 module /initrd-2.6.18-194.26.1.el5xen.img title CentOS (2.6.18-194.26.1.el5debug) root (hd0,0) kernel /vmlinuz-2.6.18-194.26.1.el5debug ro root=/dev/md2 initrd /initrd-2.6.18-194.26.1.el5debug.img title CentOS (2.6.18-194.26.1.el5) root (hd0,0) kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=/dev/md2 initrd /initrd-2.6.18-194.26.1.el5.img # root (hd1,0) title CentOS (2.6.18-194.26.1.el5xen)-disk2 root (hd1,0) kernel /xen.gz-2.6.18-194.26.1.el5 module /vmlinuz-2.6.18-194.26.1.el5xen ro root=/dev/md2 module /initrd-2.6.18-194.26.1.el5xen.img title CentOS (2.6.18-194.26.1.el5debug)-disk2 root (hd1,0) kernel /vmlinuz-2.6.18-194.26.1.el5debug ro root=/dev/md2 initrd /initrd-2.6.18-194.26.1.el5debug.img title CentOS (2.6.18-194.26.1.el5)-disk2 root (hd1,0) kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=/dev/md2 initrd /initrd-2.6.18-194.26.1.el5.img
設定が終わったら再起動してみて、2本目のディスクから起動することを確認します。
今日はこんな所で。