Thursday, November 10, 2011

multiboot -fedora 16, archlinux and vista

intro


this guide will show how i do multiboot, with fedora 16, archlinux and vista, while keeping the linux system partitions (/, /home, /var and /tmp) on lvm2 over encrypted partitions (the guide might not be useful if you want to use encrypted partitions over lvm2).

since my previous article about multiboot, multiboot, here i come, fedora 16 was released and i've managed to ruin my fedora 15 grub config. even though i could fix grub, i've decided to take it almost from scratch (i've kept only the vista partition untouched) and document as much as possible.

setup


the current configuration i have is this:
  • /dev/sda1: fedora 16 boot (150MB, ext2, primary)
  • /dev/sda2: windows vista (70GB, ntfs, primary)
  • /dev/sda4: extended (remaining, up to 1T)
    • /dev/sda5: encrypted (150GB, luks, logical)
      • /dev/mapper/vg_007 (lvm2)
        • /dev/vg_007/lv_swap (2GB, swap)
        • /dev/vg_007/lv_f16_root (25GB, ext4)
        • /dev/vg_007/lv_f16_home (5GB, ext4)
        • /dev/vg_007/lv_f16_tmp (2GB, ext4)
        • /dev/vg_007/lv_f16_var (4GB, ext4)
        • /dev/vg_007/lv_arch_root (25GB, ext4)
        • /dev/vg_007/lv_arch_home (5GB, ext4)
        • /dev/vg_007/lv_arch_tmp (2GB, ext4)
        • /dev/vg_007/lv_arch_var (16GB, ext4)
    • (582GB, free)
    • /dev/sda6: arch boot (100MB, ext2, logical)
    • /dev/sda7: encrypted (160GB, luks, logical)
      •  /dev/mapper/007-ST-DATA-LNX (ext4)
    • /dev/sda8: vista data (40GN, vfat, logical)
i've chosen some small home partitions as i keep most of my data on 007-ST-DATA-LNX and i intend to keep only minimum (like configs) in the /home directories, with big data symlinked from 007-ST-DATA-LNX.

based on other articles i've read on arch configuration, i've also decided to start with a big lv_arch_var.

the 007 is not related in any way with the mi6, but with the hard-disk being my seventh one and also a seagate (thus 007 and ST).

vista


note: this was left untouched since my original installation of fedora 15.

in order to avoid any complications, its always good to install your m$ os as soon as possible, as they can be picky about existing partitions and will always overwrite the mbr.

but even before vista, i wanted to make sure that i have some space reserved for a boot partition.

so:
  • boot from a linux live cd
  • create /dev/sda1 at the beginning of the disk
  • reboot
and continue with vista installation:
  • boot from vista cd
  • install vista

now we could waste the next 8-16 hours to update vista or we could continue with installing your linux distros. i advise the later, as it would allow us at some point to make a backup of a clean vista with ntfsclone.

fedora 16


note: this guide should be usable more or less with any other distro

continuing from the previous step, boot now from the fedora 16 cd into the live system.

no previous encrypted and lvm2 configuration


in case you are using a clean disk, you'll have to add the logical volumes that will keep the encrypted partitions, encrypt them, create a volume group and then add the logical volumes to it.

open a terminal and:
  • gain root:
    $ su -
  • create the logical partition /dev/sda5 (use cfdisk or fdisk)
  • encrypt /dev/sda5 and unlock it:
    # cryptsetup -v -c aes-xts-plain -y -s 512 luksFormat /dev/sda5
    # cryptsetup luksOpen /dev/sda5 007-ROOT
  • create the vg_007 volume group:
    # vgcreate vg_007 /dev/mapper/007-ROOT
  • create the logical volumes (you could create the arch volumes at this point, too, but you can do it also when you'll install arch):
    # lvcreate -v -n lv_swap -L 2G vg_007
    # lvcreate -v -n lv_f16_root -L 25G vg_007
    # lvcreate -v -n lv_f16_home -L 5G vg_007
    # lvcreate -v -n lv_f16_tmp -L 2G vg_007
    # lvcreate -v -n lv_f16_var -L 4G vg_007
  • in order for the installer to go smoothly, it is best to deactivate now the lvm2 and lock the encrypted partition (the installer will ask you later for the password):
    # vgchange -a n
    # cryptsetup luksClose 007-ROOT

using existing encrypted and lvm2 configuration


you don't have to do anything in this case. if you want to unlock and inspect the lvm2 partitions, don't forget to deactivate and lock them before installing the os.

common steps


now that we have the disk partitioned for fedora, simply launch the installer. at some point, the installer will ask Which type of installation would you like? and you should select Create Custom Layout.

the installer will ask for the password used to decrypt /dev/sda5 and will present all existing partitions, including the lvm2 ones.

use this mapping:

partitionmount pointformatfile-system
/dev/sda1/bootYext2
/dev/vg_007/lv_swap-Yswap
/dev/vg_007/lv_f16_root/Yext4
/dev/vg_007/lv_f16_home/homeYext4
/dev/vg_007/lv_f16_tmp/tmpYext4
/dev/vg_007/lv_f16_var/varYext4

later on, when asked where to install grub, accept the default /dev/sda.

except the initial part when you manually configure the encrypted and lvm2 partitions, there's nothing very different compared with a regular installation.

archlinux


installing arch is not that complicated either. just insert the arch cd and boot from it. the boot process should leave you at a root prompt.

now, all you have to do is to:
  • unlock /dev/sda5:
    # cryptsetup luksOpen /dev/sda5 007-ROOT
  • activate the lvm2:
    # vgchange -a y
  • if you haven't created the lvm partitions for arch when you created those for fedora, you'll have to create them now:
    # lvcreate -v -n lv_arch_root -L 25G vg_007
    # lvcreate -v -n lv_arch_home -L 5G vg_007
    # lvcreate -v -n lv_arch_tmp -L 2G vg_007
    # lvcreate -v -n lv_arch_var -L 16G vg_007
  • start the install process:
    # /arch/setup
  • when you get to 4. Prepare hard drives:
    • select 3. Manually Configure block devices, filesystems and mountpoints
    • select dev directly by /dev/*
    • use the mapping in the table bellow
    • select Done when finished
  • when you get to 7. Configure System
    • modify /etc/rc.conf to contain:
      USELVM="yes"
    • modify /etc/mkinitcpio.conf to contain (keep the order!):
      HOOKS=...keymap encrypt lvm2 filesystems...
  • skip 8. Install Bootloader as we will use the grub from fedora and we don't want to mess with its config
  • exit the installer and reboot the machine (you will boot to fedora).

arch partition mapping:

partitionmount pointformatfile-system
/dev/sda6/bootYext2
/dev/vg_007/lv_swap-Nswap
/dev/vg_007/lv_arch_root/Yext4
/dev/vg_007/lv_arch_home/homeYext4
/dev/vg_007/lv_arch_tmp/tmpYext4
/dev/vg_007/lv_arch_var/varYext4

grub tweaking


ok. we are almost done and all we have now to do is make grub2 boot correctly arch.

by default, fedora's grub2 will try to autodetect windows and arch. while windows autodetection works, the one for arch is not, probably because we are using encryption and lvm.

the solution is simple tough:
  • modify /etc/default/grub to save selected os (nice to have) and to disable the os prober (having that would only clutter the menu):
    GRUB_DEFAULT=saved
    GRUB_SAVEDEFAULT=true
    GRUB_DISABLE_OS_PROBER=true
  • identify the uuid of the windows partition:
    # blkid /dev/sda2
    /dev/sda2: UUID="EC8074DA8074ACA8" TYPE="ntfs"
  • create /etc/grub.d/50_WindowsVista for the vista installation (and make it executable):
    #!/bin/sh
    exec tail -n +3 $0

    # partition numbering is like in /dev
    # /dev/sda1 -> (hd0,1)
    # /dev/sda2 -> (hd0,2)
    menuentry "Windows Vista Home Premium" {
            savedefault
            insmod part_msdos
            insmod ntfs
            set root='(hd0,msdos2)'
            search --no-floppy --fs-uuid --set=root EC8074DA8074ACA8
            chainloader +1
    }
  • identify the uuid of the arch boot partition:
    # blkid /dev/sda6
    /dev/sda6: LABEL="ARCH_BOOT" UUID="ee393ce1-bff0-4373-ab79-adab37a506cc" TYPE="ext2"
  • create /etc/grub.d/51_ArchLinux for the vista installation (and make it executable):
    #!/bin/sh
    exec tail -n +3 $0

    # partition numbering is like in /dev
    # /dev/sda1 -> (hd0,1)
    # /dev/sda2 -> (hd0,2)
    menuentry "ArchLinux" {
            savedefault
            set gfxpayload=keep
            insmod part_msdos
            insmod ext2
            set root='(hd0,msdos6)'
            search --no-floppy --fs-uuid --set=root ee393ce1-bff0-4373-ab79-adab37a506cc
            linux   /vmlinuz-linux root=/dev/mapper/vg_007-lv_arch_root cryptdevice=/dev/sda5:vg_007 ro vga=773
            initrd  /initramfs-linux.img
    }
  • rebuild the /boot/grub2/grub2.cfg:
    # grub2-mkconfig -o /boot/grub2/grub.cfg
  • install the changes:
    # grub2-install /dev/sda
that's it. now we should have a system that can boot fedora 16, arch linux and vista.

other distros could be added to the mix, though maintaining the grub menu might not be as easy as with arch.

if anybody finds this useful or knows a better way, please let me know.

i would also love to know how i can chainload a second grub2 from the main one, as all the info i've found so far was only how to chainload from grub to grub2, but not from grub2 to grub2.

No comments:

Post a Comment