add ability to pass options via kernel boot parameters

This commit is contained in:
Simon Bruder 2018-02-14 13:59:25 +00:00
parent 1f0f0bc064
commit 96d21ce816
2 changed files with 60 additions and 16 deletions

View file

@ -24,28 +24,67 @@ print_waiting() {
echo -en "\033[36m${1}... \033[0m"
}
print_warning() {
echo -e "\n\033[31mWARNING: ${1}\033[0m"
}
print_done() {
echo -e "\033[32mdone.\033[0m"
}
error_fatal() {
print_warning "$1; interrupting startup"
while sleep 3600;do sleep 3600;done
}
##
# HARDCODED DISK PARAMETERS
# READ CONFIGURATION PARAMETERS FROM KERNEL PARAMETERS
##
disk=/dev/sda
print_waiting "Reading configuration parameters"
set -- $(cat /proc/cmdline)
for x in "$@"; do
case "$(echo $x | cut -d= -f1)" in
disk)
disk="$(echo $x | cut -d= -f2)"
;;
root)
root="$(echo $x | cut -d= -f2)"
;;
partsize)
partsize="$(echo $x | cut -d= -f2)"
;;
qemu)
qemu="$(echo $x | cut -d= -f2)"
;;
esac
done
size_part_1=$((3072 * 1024 * 1024 / 512))
# Check if mandatory parameters are missing
if [ -z $disk ];then
error_fatal "The disk parameter is missing"
fi
if [ -z $root ];then
error_fatal "The root parameter is missing"
fi
if [ -z $partsize ];then
error_fatal "The partsize parameter is missing"
fi
print_done
##
# PARTITIONING OF DISK
##
size_part_1=$(($partsize * 1024 * 1024 / 512))
parttable="label: dos
label-id: 0xdeadbeef
device: /dev/sda
device: $disk
unit: sectors
/dev/sda1 : start= 2048, size= $size_part_1, type=83"
$root : start= 2048, size= $size_part_1, type=83"
readtable="$(sfdisk -d $disk)" # wtf? but it is needed
@ -53,7 +92,7 @@ print_waiting "Checking partition tables"
if [ "$parttable" != "$readtable" ];then
print_done
print_waiting "Partition tables do not match; partitioning disk"
sfdisk -q /dev/sda << PARTTABLE
sfdisk -q $disk << PARTTABLE
$parttable
PARTTABLE
print_done
@ -62,12 +101,12 @@ else
fi
print_waiting "Checking root filesystem"
e2fsck /dev/sda1
e2fsck $root
fsck=$?
if [ $fsck != 0 ] && [ $fsck != 1 ];then
print_done
print_waiting "Creating root filesystem"
mke2fs -q -F -t ext4 ${disk}1
mke2fs -q -F -t ext4 $root
print_done
else
print_done
@ -77,10 +116,16 @@ fi
# TEMPORARY NETWORK CONFIG (only for qemu)
##
print_waiting "Setting up temporary network config"
ip addr add 10.2.2.2/24 dev ens3
ip link set ens3 up
print_done
if ! [ -z $qemu ];then
print_waiting "Setting up temporary network config"
ip addr add 10.2.2.2/24 dev ens3
ip link set ens3 up
print_done
else
print_waiting "Setting up interfaces with DHCP"
ipconfig all
print_done
fi
##
# MOUNT TEMPORARY ROOTFS
@ -88,7 +133,7 @@ print_done
print_waiting "Mounting temporary root filesystem"
mkdir -p /tmp_root
mount -t ext4 ${disk}1 /tmp_root
mount -t ext4 $root /tmp_root
cd /tmp_root
print_done
@ -121,6 +166,7 @@ if [ -f /tmp_root/.build_uuid ];then
tar xzf /tmp_root/rootfs.tar.gz .build_uuid
if [ $(cat .build_uuid) == $(cat /tmp_root/.build_uuid) ];then
sync=false
print_done
else
sync=true
print_done

View file

@ -12,13 +12,11 @@ sudo ip addr add 10.2.2.1/24 dev brtstsync
sudo ip link set taptstsync up
sudo ip link set brtstsync up
# -append "root=/dev/sda1 quiet" \
qemu-system-x86_64 \
-kernel vmlinuz \
-initrd initrd.gz \
-drive format=raw,file=pladde.img \
-append "root=/dev/sda1" \
-append "disk=/dev/sda root=/dev/sda1 partsize=3072 qemu" \
-curses \
-enable-kvm \
-m 1G \