• 2011/12/12 - 17:28

    News

    The section "Nas/Router" has been added

Current page: Home > Tech

Modifications for LVM

Placing the root filesystem on a logical volume

The first step is to create a logival volume for your root filesystem (assuming you already have a LVM with a volume group called vDisk). Afterwards you need to copy your existing root filesystem to the new volume (this may take some time).

lvcreate -n root -L 20G vDisk
mkfs.ext4 /dev/vDisk/root
mkdir -p /tmp/NEW_ROOT
mount /dev/vDisk/root /tmp/NEW_ROOT
cp -ax / /tmp/NEW_ROOT
umount /tmp/NEW_ROOT

The new root is now prepared for the first boot. In order to be able to boot from this logical volume the initial RAM disk has to be extended slightly. It should no longer load the original root partition, instead the volume group has to be loaded and the new logical volume has to serve as root filesystem. The new init-script has to look something like this:

cat /usr/src/initramfs/init
#!/bin/busybox sh

shell() {
    /bin/busybox --install -s
    exec /bin/sh
}

# mounting proc and sys
/bin/mount -t proc none /proc || shell
/bin/mount -t sysfs none /sys || shell

### activating volume group ###
/sbin/lvchange -a y vDisk

### mounting logical root volume ###
/bin/mount -o ro /dev/vDisk/root /mnt/root || shell

# unmounting proc and sys
/bin/umount /proc || shell
/bin/umount /sys || shell

# continuing with boot
exec switch_root /mnt/root /sbin/init || shell

Some new executables and devices are needed which can be inserted into the initial RAM disk just like the others:

cd /usr/src/initramfs
cp -a /dev/random /dev/urandom dev
cp -L `which lvchange` sbin
ldd sbin/lvchange
        linux-vdso.so.1 =>  (0x00007fff9f189000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fceba646000)
        libdevmapper-event.so.1.02 => /lib64/libdevmapper-event.so.1.02 (0x00007fceba440000)
        libdevmapper.so.1.02 => /lib64/libdevmapper.so.1.02 (0x00007fceba21a000)
        libreadline.so.6 => /lib64/libreadline.so.6 (0x00007fceb9fd4000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fceb9d53000)
        libudev.so.0 => /lib64/libudev.so.0 (0x00007fceb9b45000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fceb97df000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fceba84a000)
        libncurses.so.5 => /lib64/libncurses.so.5 (0x00007fceb958e000)
cp -L /lib64/libdl.so.2 lib
cp -L /lib64/libdevmapper-event.so.1.02 lib
cp -L /lib64/libdevmapper.so.1.02 lib
cp -L /lib64/libreadline.so.6 lib
cp -L /lib64/libm.so.6 lib
cp -L /lib64/libudev.so.0 lib
cp -L /lib64/libc.so.6  lib
cp -L /lib64/libncurses.so.5 lib

The last thing is to compile and install the kernel. Upon the next reboot the new logical root volume will be used as root.

cd /usr/src/linux
make
make install
reboot

last updated: May 4, 2020 17:36:28