Here is going to be short walk-through on how to install Gentoo on non-EDI system with Linux software RAID (mdadm with new version-1 metadata) on GPT partition table. Installation will be using LVM for partition management with no non-LVM /boot partition. And GRUB 2 will boot all this stuff.
Disk preparation and RAID creation
At first we setup partition table on one of the disks using gdisk, cgdisk or other tool of choice. I usually leave some space at the end, so if failed disk would be replaced by slightly smaller disk (even one sector could ruin your day!) there would be no problems using it. Also I align partitions to 1 MB (2048 sectors if logical sector size is 512), gdisk and cgdisk will align them for you.
On MBR partition table I would be using DA partition type (non-FS data) because it was recommended to use with version-1 metadata, but it appears that this type of partition is not supported in GPT tools, so I used GPT’s FD00 partition type (Linux RAID). And we need a BIOS boot partition for GRUB 2 to put it’s core.img. 1MB is plenty for it, and type should be EF02 (BIOS boot partition).
After setup my disk looks like this:
~# gdisk -l /dev/sda GPT fdisk (gdisk) version 0.8.1 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/sda: 1953525168 sectors, 931.5 GiB Logical sector size: 512 bytes Disk identifier (GUID): E1F41A5B-6F37-4738-AB19-67F3BB2532BB Partition table holds up to 128 entries First usable sector is 34, last usable sector is 1953525134 Partitions will be aligned on 2048-sector boundaries Total free space is 3175788 sectors (1.5 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 4095 1024.0 KiB EF02 BIOS boot partition 2 4096 1950351360 930.0 GiB FD00 Linux RAID
Lets copy this partition layout to other disk:
sgdisk -R=/dev/sdb /dev/sda
Verify drive letters before running command! 🙂
After that we need to randomize GUID on second disk:
sgdisk -G /dev/sdb
Now we have two disks with identical partition layout. Now it’s time to create RAID out of them.
mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sda2 /dev/sdb2
For more information on mdadm you can check out Linux RAID wiki and of course mdadm’s man page 🙂
LVM and filesystems
Now we have brand new RAID which will be synchronizing itself. It is safe to continue setup (and reboot/shutdown system). Next step is LVM. Let’s create physical volume:
Now we need a volume group. I will name mine “vg-sata” as I am using SATA disks.
vgcreate vg-sata /dev/md0
lvcreate -L4G -n swap vg-sata lvcreate -L200M -n boot vg-sata lvcreate -L15G -n root vg-sata
I hope names explain their purpose 🙂 Next – filesystems:
mkswap -f /dev/vg-sata/swap mkfs.ext4 /dev/vg-sata/boot mkfs.ext4 /dev/vg-sata/root
I had to use -f for mkswap due to warning of not erasing bootbits sectors without it and we do not need them there.
So now we are ready to install gentoo. Just follow handbook for installation. We already prepared disks you only need to mount them. (Or create more partitions if separate partitions are desired for /home, /var, etc).
If you followed the Handbook, you should have noticed that “EFI GUID Partition support” needs to be enabled for GPT tables to work.
Also I like to compile into kernel used features rather than using modules so I also have “Device Drivers —> Multiple devices driver support (RAID and LVM) —> RAID-1 (mirroring) mode” amongst other selected drivers. I have not tested if RAID-1 compiled as module works, but most likely it will, initramfs should preload it.
Because we are using RAID and LVM for our partitions we need to activate them after loading kernel so system could finish booting. To generate initramfs we can use genkernel. Straight out of Handbook:
genkernel --lvm --mdadm --install initramfs
For /etc/fstab configuration I use UUID’s. This way if for some reason my partition name will change I will not need to edit this configuration and my system will be bootable.
“device-mapper” USE flag needs to be added. For lazy:
echo "sys-boot/grub device-mapper">>/etc/portage/package.use emerge -av grub
After installation edit /etc/default/grub:
Let’s generate GRUB 2 config.
grub2-mkconfig -o /boot/grub/grub.cfg
Install GRUB 2 bootloader on disks:
grub2-install /dev/sda grub2-install /dev/sdb
And that’s it. Fingers crossed during reboot 🙂