1. Install Tools for Generating Initramfs
emerge -avt genkernel
# both genkernel and dracut are fine,
# 'darcut' is more recommended.
emerge -avt dracut
-
For genkernel
- FILE
/etc/default/grub
Adding dolvm as a kernel boot parameter - GRUB_CMDLINE_LINUX="dolvm"
- FILE
-
For dracut
- FILE
/etc/default/grub
Adding LVM support to the kernel boot parameters - GRUB_CMDLINE_LINUX="rd.lvm.lv=vg00/lv_root"
- FILE
2. Create LV and Migrate Data
# choose your own name for root fs
# in this case, VG: vg00, LV: lv_root
lvcreate -L 15G -n /dev/vg00/lv_root
mkfs.ext4 /dev/vg00/lv_root
mkdir /mnt/new_root
mount /dev/vg00/lv_root /mnt/new_root
# sync data form / to /mnt/new_root
# exclude the filesystems already mounted
rsync -av --progress --exclude=/boot --exclude=/proc --exclude=/media --exclude=/mnt --exclude=/sys $(df -h | awk '{print $NF}' | grep -E "/[a-z][a-z]*" | awk '{print "--exclude="$1}' | xargs) /* /mnt/new_root
3. Change Root Directory to New Place
mount -t proc /proc /mnt/new_root/proc
mkdir -p /mnt/new_root/{run,dev,proc,sys}
mount --rbind /dev /mnt/new_root/dev
mount --rbind /sys /mnt/new_root/sys
mount --rbind /run /mnt/new_root/run
chroot /mnt/new_root /bin/bash
[host@user]# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg00-lv_root 9.8G 9.1G 141M 99%
# mount filesystems
[host@user]# mount -a
mount: /var: mount point does not exist.
dmesg(1) may have more information after failed mount system call.
mount: /opt: mount point does not exist.
dmesg(1) may have more information after failed mount system call.
# create directories not exist
# names depends on your own environment
mkdir -p /{home,var,var,opt,usr/portage,root}
# mount all again
mount -a
# verify mount status
df -h
4. Add Kernel Support
General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
General setup --->
() Initramfs source file(s)
[*] Support initial ramdisk/ramfs compressed using gzip
[] Support initial ramdisk/ramfs compressed using bzip2
[] Support initial ramdisk/ramfs compressed using LZMA
[] Support initial ramdisk/ramfs compressed using XZ
[] Support initial ramdisk/ramfs compressed using LZO
[] Support initial ramdisk/ramfs compressed using LZ4
5. Generate New Kernel Image
cd /usr/src/linux
make && make modules_install && mount /boot && make install
6. Modify Filesystems Configuration
# file: /etc/fstab
vi /etc/fstab
# Before
/dev/sda3 / ext4 noatime 0 1
# After
/dev/vg00/lv_root / ext4 noatime 0 1
7. Add Grub Boot Paramenter
# Add line to file '/etc/default/grub'
vi /etc/default/grub
# Before
GRUB_CMDLINE_LINUX=""
# After
GRUB_CMDLINE_LINUX="rd.lvm.lv=vg00/lv_root"
8. Gerenate Initramfs with 'dracut' or 'genkernel'
# only if option 'noauto' is set for '/boot' line in the file '/etc/fstab'
mount /boot
# if initramfs file exists, add option '--force'
dracut -a lvm --kver=x.y.zz-gentoo
# or generate initramfs with 'genkernel'
genkernel --lvm initramfs
9. Configure Bootloader
# verify boot parameter 'rd.lvm.lv' is effective
# check the UUID of root filesystem is the same with
# the output of command 'blkid /dev/vg00/lv_root'
grub-mkconfig 2>/dev/null| grep lvm
blkid /dev/vg00/lv_root
# regenerate GRUB boot menu
grub-mkconfig -o /boot/grub/grub.cfg
# sync the cache to local disk and reboot the system
sync && shutdown -r now