Gentoo on GPT + Software RAID + LVM with GRUB 2 on non-EFI system

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:

pvcreate /dev/md0

Now we need a volume group. I will name mine “vg-sata” as I am using SATA disks.

vgcreate vg-sata /dev/md0

And partitions:

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).

Kernel config

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 🙂

Useful MySQL queries and related shell scripts reference

Here are some useful MySQL query for occasional use. All queries may be adjusted as needed (like “myisam” replaced with “innodb”, etc).

  • Show fragmented tables and their data usage with free occupied space. Removing “AND Data_free > 0” will data for show all tables.
    CONCAT(ROUND(data_length / ( 1024 * 1024 ), 2), 'MB') DATA,
    CONCAT(ROUND(data_free  / ( 1024 * 1024 ), 2), 'MB') FREE
  FROM information_schema.TABLES
  WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 0
  • Show all MyISAM tables.
  FROM information_schema.TABLES
  WHERE ENGINE like "myisam"
  • Shell command to dump all MyISAM tables of specific database to file.
echo "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='some_database' and ENGINE like 'myisam' ORDER BY TABLE_NAME;" | mysql | sed 1d > tables.txt
  • Shell command to mass change table engine to innodb from file.
cat tables.txt |awk '{print "ALTER TABLE " $1 " ENGINE = innodb;";}' | mysql some_database

And some “what was that syntax?” queries.

  • Show all users.
SELECT user, host FROM mysql.user ORDER BY user, host;
  • revoke privileges
  • set/change password
SET PASSWORD FOR 'user'@'host' = PASSWORD('password');


Synaptics touchpad does not work on gentoo linux (gnome 3.6)? – solved

For quite some time I had problem that laptop’s touchpad didn’t work for me. But because I mostly use USB mouse and keyboard I didn’t notice it for a while. Most likely it broke when I “optimized” my INPUT_DEVICES make.conf variable.

To fix it I had to add “synaptics” to INPUT_DEVICES. Now my /etc/portage/make.conf contains this line:

INPUT_DEVICES="evdev synaptics"

After that just reemerge xorg-drivers and relogin.

emerge -1av xorg-drivers

Hello World! Again..

Hello world! Again.. 🙂

This is my second attempt at starting blog site. First site didn’t go beyond “hello world” post, let’s hope this time it will be different.

Currently I am planning on posting various IT related tips, gotcha’s, etc. I guess it will be yet another blog with notes for author on how to do some stuff, command reference, code snippets and other related stuff. I hope that from time to time I will have something more interesting to share, but time will tell 🙂