initial lvm support

This commit is contained in:
illiliti 2020-01-19 00:01:21 +03:00
parent ba74f3a646
commit 5bc7f6e047
3 changed files with 76 additions and 25 deletions

16
config
View File

@ -6,28 +6,28 @@
#use_fstab=0
# root fs
root="/dev/sda1"
root="UUID=28305682-0dfe-40a9-bf39-5df42123b749"
# root fs type
rootfstype="ext4"
#rootfstype=""
# root fs mount options
rootflags=""
#rootflags=""
# drivers
drivers="ext4 virtio-scsi virtio-pci sd-mod"
#drivers=""
# binaries
binaries="./busybox findfs mount modprobe umount"
#binaries=""
# LVM support
#use_lvm=0
use_lvm=1
# LVM include config
#use_lvmconf=0
use_lvmconf=0
# LVM issue_discards
#lvm_discard=0
lvm_discard=0
# LUKS support
#use_luks=0

View File

@ -28,28 +28,73 @@ fi
tmpdir="$(mktemp -d /tmp/initramfs.XXXXXXXX)"
kernel="$(uname -r)"
moddir="/lib/modules"
binaries="./busybox udevd udevadm mount modprobe umount $binaries"
# structure
for d in dev etc usr/lib usr/bin mnt/root proc root sys; do
for d in dev var run etc usr/lib usr/bin mnt/root proc root sys; do
mkdir -p "$tmpdir/$d"
done
# TODO usr/lib64 usr/sbin
# symlinks
for s in lib lib64 bin sbin; do
case "$s" in
lib*)
( cd "$tmpdir" && ln -s "usr/lib" "$s" )
;;
*bin)
( cd "$tmpdir" && ln -s "usr/bin" "$s" )
;;
esac
done
( cd "$tmpdir" && {
ln -s "usr/lib" "lib"
ln -s "usr/lib" "lib64"
ln -s "usr/bin" "bin"
ln -s "usr/bin" "sbin"
cd "$tmpdir/usr"
ln -s "bin" "sbin"
ln -s "lib" "lib64"
} )
# TODO parse fstab | crypttab
#while [ "$use_fstab" -eq 1 ] && read fs dir type opts; do thing; done < /etc/fstab
# install mdev
#mkdir "$tmpdir/usr/lib/mdev"
#cp ./mdev/mdev.conf ./mdev/passwd ./mdev/group "$tmpdir/etc"
#cp ./mdev/usbdev ./mdev/usbdisk_link ./mdev/ide_links "$tmpdir/usr/lib/mdev"
#chmod +x $tmpdir/usr/lib/mdev/*
# install udev
find "/usr/lib/udev" -type f | grep -v "rc_keymaps\|hwdb.d" | cpio -pd "$tmpdir"
#cat <<EOF > "$tmpdir/etc/group"
#root:x:0:
#tty:x:5:
#dialout:x:11:
#kmem:x:3:
#input:x:25:
#video:x:13:
#audio:x:12:
#lp:x:10:
#disk:x:9:
#cdrom:x:16:
#tape:x:6:
#kvm:x:24:
#floppy:x:8:
#EOF
#cat <<EOF > "$tmpdir/etc/passwd"
#root:x:0:0::/root:/bin/sh
#nobody:x:99:99::/dev/null:/bin/false
#EOF
# TODO implement use_lvmconf
# handle lvm
if [ "$use_lvm" = 1 ] && [ -x "$(command -v lvm)" ]; then
binaries="lvm dmsetup $binaries"
mkdir "$tmpdir/etc/lvm"
echo "use_lvmetad = 0" >> "$tmpdir/etc/lvm/lvm.conf"
if [ "$lvm_discard" = 1 ]; then
echo "issue_discards = 1" >> "$tmpdir/etc/lvm/lvm.conf"
fi
fi
# TODO handle luks
#if [ "$use_luks" = 1 ] && [ -x "$(command -v cryptsetup)" ]; then
# binaries="cryptsetup $binaries"
#fi
# TODO rewrite drivers installing | handle $drivers config var
# install drivers
find \

16
init
View File

@ -20,17 +20,21 @@ mount -t sysfs none /sys
mount -t devtmpfs none /dev
# setup mdev
#echo "/bin/mdev" >/proc/sys/kernel/hotplug
#echo "/sbin/mdev" >/proc/sys/kernel/hotplug
#mdev -s
# setup udev
udevd --daemon
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
# TODO parse /proc/cmdline
# load drivers
modprobe -a $drivers
#modprobe -a $drivers
# find rootfs
# TODO busybox findfs doesn't support PART{UUID,LABEL}.
root="$(findfs $root)" || panic
# merge mount flags
[ -n "$rootflags" ] && mountargs="$rootflags"
[ -n "$rootfstype" ] && mountargs="$mountargs -t $rootfstype"
@ -38,6 +42,8 @@ root="$(findfs $root)" || panic
mount $mountargs "$root" "/mnt/root" || panic
# clean up
udevadm control --exit
umount "/dev"
umount "/sys"
umount "/proc"