User:Gavlee/LVM install alternative

From Gentoo Wiki
Jump to:navigation Jump to:search

This is a log of installing Gentoo on LVM from an existing Ubuntu installation. The method of booting is BIOS and MSDOS style partition table. It's possible to adapt this for different method but due to hardware this was not tried. The installation is possible to be completed over one evening.


  • Install Gentoo to split LVM partitions, fixing Ubuntu and its GRUB detection problems.


  • Existing Linux installation.
  • LVM tools installed.
  • Free space for LVM partitions.


The installation is meant to achieve the same result as the handbook while being in a full Linux system. Some parts deviate from the handbook in the case of ordering and by being on an alternative operating system media than Gentoo.

It's possible to resume installation or emerge more software inside the chroot at any time by mounting the file systems again at the correct points and following on from where the installation was left off.

Many of the partitioning, LVM and grub commands are risky and will overwrite data and critical files required for the boot process. Be careful and if unsure, double-check what any commands are about to do before continuing.


Get root to do administrative tasks.

user $sudo su -

LVM Partitioning

Use cfdisk or another disk partitioner if needed create some partitions for LVM if they do not exist already. Here these were already prepared which were empty, ready for any operating system.

root #cfdisk /dev/sdb

Now allocate the partitions to volumes for LVM

root #pvcreate /dev/sdb7
root #pvcreate /dev/sdb8
root #pvcreate /dev/sdb9
root #pvcreate /dev/sdb10

Create volume group gvg0 on /dev/sdb7 and extend the group with the partition volumes on /dev/sdb8, /dev/sdb9 and /dev/sdb10

root #vgcreate gvg0 /dev/sdb7
root #vgextend gvg0 /dev/sdb8
root #vgextend gvg0 /dev/sdb9
root #vgextend gvg0 /dev/sdb10

Create the logical volumes on the volume group gvg0

root #lvcreate -L 256M gvg0 -n gentoo_boot
root #lvcreate -L 2G gvg0 -n gentoo_root
root #lvcreate -L100G gvg0 -n gentoo_home
root #lvcreate -L10G gvg0 -n gentoo_opt
root #lvcreate -L100G gvg0 -n gentoo_usr
root #lvcreate -L100G gvg0 -n gentoo_var
root #lvcreate -L50G gvg0 -n gentoo_tmp
root #lvcreate -L10G gvg0 -n gentoo_swap

Creating the filesystems

Create the filesystems and swap

root #mkfs.ext2 /dev/gvg0/gentoo_boot
root #mkfs.ext4 /dev/gvg0/gentoo_root
root #mkfs.ext4 /dev/gvg0/gentoo_home
root #mkfs.ext4 /dev/gvg0/gentoo_opt
root #mkfs.ext4 /dev/gvg0/gentoo_usr
root #mkfs.ext4 /dev/gvg0/gentoo_var
root #mkfs.ext4 /dev/gvg0/gentoo_tmp
root #mkswap /dev/gvg0/gentoo_swap

Preparing mount points

Create the root directory for gentoo and mount the root filesystem there.

root #mkdir -p /mnt/gentoo
root #mount /dev/gvg0/gentoo_root /mnt/gentoo
root #mkdir -p /mnt/gentoo/{boot,home,opt,usr,var,tmp}

Mount the LVM logical volumes inside the root filesystem.

root #mount /dev/gvg0/gentoo_boot /mnt/gentoo/boot
root #mount /dev/gvg0/gentoo_home /mnt/gentoo/home
root #mount /dev/gvg0/gentoo_opt /mnt/gentoo/opt
root #mount /dev/gvg0/gentoo_usr /mnt/gentoo/usr
root #mount /dev/gvg0/gentoo_var /mnt/gentoo/var
root #mount /dev/gvg0/gentoo_tmp /mnt/gentoo/tmp

Fix up the tmp dir permissions.

root #chmod 1777 /mnt/gentoo/tmp

Change current working directory to the mounted gentoo root directory.

root #cd /mnt/gentoo


Fetch the Gentoo stage3

Check the download isn't corrupted. checking the authenticity is a good idea too, from the handbook.

root #sha512sum stage3-amd64-20200624T214505Z.tar.xz

Unpack the stage3

root #tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

Edit compiler flags and add split-usr to USE (FIXME: is this needed?)

root #$EDITOR /mnt/gentoo/etc/portage/make.conf
FILE /etc/portage/make.conf
USE="logrotate split-usr"


Set up repos.conf for portage and any overlays.

root #mkdir --parents /mnt/gentoo/etc/portage/repos.conf
root #cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf

DNS / resolv.conf

Set up the DNS resolver.

On Ubuntu, the /etc/resolv.conf is a non-usable file with dns pointing to, copy the real one so the gentoo chrooted system can use it properly after reboot.

root #cp /run/systemd/resolve/resolv.conf /mnt/gentoo/etc/


Mount the pseudo-filesystems, this is important for the chroot to function correctly.

root #mount --types proc /proc /mnt/gentoo/proc
root #mount --rbind /sys /mnt/gentoo/sys
root #mount --make-rslave /mnt/gentoo/sys
root #mount --rbind /dev /mnt/gentoo/dev
root #mount --make-rslave /mnt/gentoo/dev

Some /dev/shm trickery follows, from the alternative OS install method. This may be necessary.

root #test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
root #mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
root #chmod 1777 /dev/shm


Time to chroot.

The environment needs to sanitised here when running on another OS, so the chroot command is different to the handbook
root #env -i HOME=$HOME TERM=$TERM /usr/sbin/chroot /mnt/gentoo /bin/bash
root #/usr/sbin/env-update
root #source /etc/profile


Get the portage tree so emerge can install software.

root #emerge-webrsync

Selecting a portage profile

List and select profile according to use case and requirements.

root #eselect profile list
root #eselect profile set 16

Select Gentoo mirrors

Use mirrorselect to get fast mirrors, this will pull in quite a few dependencies. The mirrors can be set manually instead if they are known, to save installing them.

root #emerge --ask mirrorselect
root #mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf

Setting architecture specific compiler flags

Set architecture specific cflags early in the process.

root #emerge --ask app-portage/cpuid2cpuflags
root #echo "*/* $(cpuid2cpuflags)" > /etc/portage/package.use/00cpu-flags

Update the system

Do a quick update and rebuild any use flags that changed.

root #emerge --ask --verbose --update --deep --newuse @world

Configuring time zone

Configure the time zone to appropriate locality.

root #echo "Europe/London" > /etc/timezone
root #emerge --ask --config sys-libs/timezone-data

Configuring Locales

Configure the locales.

root #$EDITOR /etc/locale.gen
FILE /etc/locale.gen
en_GB ISO-8859-1
en_GB.UTF-8 UTF-8

Generate the locales and set them with eselect

root #locale-gen
root #eselect locale list
root #eselect locale set 6
Setting LANG to en_GB.utf8

Updating the environment

Update the environment to propagate changes

root #env-update && source /etc/profile && export PS1="(chroot) ${PS1}"

Selecting a kernel

Emerge the kernel sources and genkernel to build them, acceptance of the license for firmware is required.

root #mkdir -p /etc/portage/package.license
root #echo "sys-kernel/linux-firmware linux-fw-redistributable no-source-code" \
   > /etc/portage/package.license/linux-firmware
root #emerge --ask sys-kernel/gentoo-sources genkernel

Installing LVM

Install lvm2 so the tools are available and activated on boot.

root #emerge --ask sys-fs/lvm2
root #/etc/init.d/lvm start
root #rc-update add lvm boot

Checking loaded kernel drivers

To configure the kernel, it's sometimes useful to see what kernel modules are loaded on a running Linux system. List modules currently loaded on the system with lspci(8) and the -k option.

user $lspci -k

Creating a kernel configuration

Change to the kernel source directory and create a kernel configuration.

root #cd /usr/src/linux
root #make defconfig menuconfig
KERNEL Common kernel options for amd64
General setup  --->
    Preemption Model (Preemptible Kernel (Low-Latency Desktop))
Processor type and features  --->
    [*] Symmetric multi-processing support
    [*] EFI runtime service support 
    [*]   EFI stub support
    [*]     EFI mixed-mode support
        Processor family (AMD-Opteron/Athlon64)  --->
            ( ) Opteron/Athlon64/Hammer/K8
            ( ) Intel P4 / older Netburst based Xeon
            (*) Core 2/newer Xeon
            ( ) Intel Atom
            ( ) Generic-x86-64
    [*] Machine Check / overheating reporting 
    [*]   Intel MCE Features
    [ ]   AMD MCE Features
Binary Emulations  --->
    [*] IA32 Emulation
Firmware Drivers  --->
    EFI (Extensible Firmware Interface) Support  --->
        <*> EFI Variable Support via sysfs
-*- Enable the block layer --->
    Partition Types --->
        [*] Advanced partition selection
        [*]   PC BIOS (MSDOS partition tables) support
        [*]   EFI GUID Partition support
Device Drivers --->
  HID support  --->
    -*- HID bus support
    <*>   Generic HID driver
    [*]   Battery level reporting for HID devices
        USB HID support  --->
          <*> USB HID transport layer
  [*] USB support  --->
    <*>     xHCI HCD (USB 3.0) support
    <*>     EHCI HCD (USB 2.0) support
    <*>     OHCI HCD (USB 1.1) support
Device Drivers --->
    Generic Driver Options --->
        [*] Maintain a devtmpfs filesystem to mount at /dev
        [*]   Automount devtmpfs at /dev, after the kernel mounted the rootfs
    SCSI device support  --->
        <*> SCSI disk support
    <*> Sound card support  --->
        <*>  Advanced Linux Sound Architecture  --->
             [*]  USB sound devices  --->
                  <M>   USB Audio/MIDI driver
File systems --->
    <*> Second extended fs support
    <*> The Extended 3 (ext3) filesystem
    <*> The Extended 4 (ext4) filesystem
    Pseudo Filesystems --->
        [*] /proc file system support
        [*] Tmpfs virtual memory file system support (former shm fs)

Compiling the kernel

Backup the kernel configuration and start compiling the kernel.

root #cp .config ../config-linux-5.4.48-gentoo-1
root #ionice -c2 -n7 nice -n15 make -j4
root #make modules_install install

Setting up fstab

While compiling, edit fstab and set up the mounts for the system.

root #$EDITOR /mnt/gentoo/etc/fstab
FILE /etc/fstab
# (customise mount options according to need, nosuid, noexec, noatime, discard etc)
/dev/gvg0/gentoo_boot /boot   ext2    noauto,noatime  1 2
/dev/gvg0/gentoo_root /       ext4    relatime        0 1
/dev/gvg0/gentoo_usr  /usr    ext4    relatime        0 2
/dev/gvg0/gentoo_var  /var    ext4    relatime        0 2
/dev/gvg0/gentoo_opt  /opt    ext4    relatime        0 2
/dev/gvg0/gentoo_tmp  /tmp    ext4    relatime        0 2
/dev/gvg0/gentoo_home /home   ext4    relatime        0 2
# stripe the swaps on different drives
/dev/gvg0/gentoo_swap none swap sw,pri=32
UUID=a333768d-8816-4f48-87c5-dd60902da5f4 none            swap    sw,pri=32 0 0
UUID=5192943d-b478-4602-8b60-90c30e32064f none            swap    sw,pri=32 0 0
/dev/cdrom  /mnt/cdrom   auto    noauto,user          0 0

Building the initramfs

Build the initramfs with lvm using genkernel (easy peasy method)

root #genkernel --lvm --install initramfs
  • Additional kernel parameters that *may* be required to boot properly:
  • - Add "dolvm" for LVM support


Set up hostname, DNS domain, DHCP networking for wired network.

root #$EDITOR /etc/conf.d/hostname
FILE /etc/conf.d/hostname
root #$EDITOR /etc/conf.d/net
FILE /etc/conf.d/net
root #cd /etc/init.d
root #ln -s net.lo net.eth0
root #rc-update add net.eth0 default

Install netifrc for DHCP

root #emerge --ask net-misc/netifrc

Startup configuration

Set parallel startup will make the boot process faster.

root #$EDITOR /etc/rc.conf

Setting keyboard mappings

UK keymap

root #$EDITOR /etc/conf.d/keymaps

Setting up the clock

Whether local/utc clock, if dual booting.

root #$EDITOR /etc/conf.d/hwclock

Setting a root password

It's probably a good idea to set a root password here.

root #passwd

Installing system software

Install system logger, a cron daemon, locate, dhcpcd and filesystem tools then add them to default runlevel to start on boot

root #emerge --ask app-admin/sysklogd app-admin/logrotate sys-process/cronie \ sys-apps/mlocate net-misc/dhcpcd sys-fs/e2fsprogs sys-fs/dosfstools sys-fs/ntfs3g
root #rc-update add sysklogd default
root #rc-update add cronie default

SSH server

If ssh is required, add it to the run level to start on next boot.

root #rc-update add sshd default

Serial consoles

Optional but sometimes serial console is needed..

root #$EDITOR /etc/inittab
FILE /etc/inittab
s0:12345:respawn:/sbin/agetty 9600 ttyS0 vt100
s1:12345:respawn:/sbin/agetty 9600 ttyS1 vt100

Setting up GRUB

Time to get grubby for booting. Add dm and mount support to grub for lvm. Add BIOS and EFI support to make.conf, then install grub and os-prober. Finally, install grub to boot drive and run setup to create the grub configuration.

root #echo "sys-boot/grub device-mapper mount" > /etc/portage/package.use/00grub-lvm
root #echo 'GRUB_PLATFORMS="efi-64 pc"' >> /etc/portage/make.conf
root #emerge --ask sys-boot/grub:2 sys-boot/os-prober

BIOS (This was what was used here)

root #grub-install /dev/sda


root #grub-install --target=x86_64-efi --efi-directory=/boot

Add dolvm as a kernel boot parameter, this is important to boot with lvm also, when using genkernel to build the initramfs, the root=/dev/ram0 and real_root= pointing to the root is sometimes necessary.

root #$EDITOR /etc/default/grub
FILE /etc/default/grub
GRUB_CMDLINE_LINUX="dolvm root=/dev/ram0 real_root=/dev/gvg0/gentoo_root"
root #grub-mkconfig -o /boot/grub/grub.cfg

Creating a login user

Make a regular user to login with.

root #useradd -m -G users,wheel,audio,cdrom,floppy,portage,usb,video -s /bin/bash gav
root #passwd gav

Clean up

Remove the install stage3 tarball when not needed.

root #rm /stage3-*.tar.*

Next steps

It's reasonable to reboot here but since being in the chroot, it could be useful to emerge while in a working environment. Install the required software while still working and reboot into new environment after the needed software is installed.

root #emerge --ask xorg-server openbox lxterminal

Unmounting filesystems

Finish up and unmount the file-systems to sync all the data

root #exit
root #cd
root #umount -l /mnt/gentoo/dev{/shm,/pts,}
root #umount -R /mnt/gentoo


Reboot when necessary.

See also


There used to be a document describing LVM install method. This must have disappeared somewhere so the aim was to try a Gentoo install remembering those steps. The method is a little different by using an existing Ubuntu installation rather than installing from Gentoo media. The Gentoo Handbook and installation alternatives document was used as a reference for the install, and credit to flameeyes for writing the how-to document for the LVM installation method which this document was inspired from.