build the kernel. create a bootable efi image.
This commit is contained in:
31
build_kernel.sh
Executable file
31
build_kernel.sh
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
dir=$(dirname "$0")
|
||||||
|
echo $dir
|
||||||
|
#mkdir -p /tmp/linux
|
||||||
|
[[ -d ./linux ]] || git clone --depth 1 https://github.com/torvalds/linux.git ./linux
|
||||||
|
cat ./containerfile | /usr/bin/podman build --volume /lib/modules:/lib/modules:z -f - -t kernelbuild:latest .
|
||||||
|
#rsync -av ./linux /mnt/tmpfs
|
||||||
|
nice -n 20 /usr/bin/podman run -it --volume /lib/modules:/lib/modules:z --volume ./linux:/linux kernelbuild:latest
|
||||||
|
cd $dir
|
||||||
|
rm -rf initram/
|
||||||
|
mkdir -p initram
|
||||||
|
mkdir -p initram/{bin,dev,etc,lib,proc,sbin,sys,tmp,usr}
|
||||||
|
mkdir -p initram/usr/{bin,sbin}
|
||||||
|
mkdir -p initram/etc/{bin,sbin}
|
||||||
|
mkdir -p initram/lib/modules/
|
||||||
|
cp busybox ./initram/bin/
|
||||||
|
#cp ./linux/drivers/block/nbd.ko initram/lib/modules/
|
||||||
|
#cp ./linux/modules.builtin initram/lib/modules/
|
||||||
|
#cp ./linux/modules.order initram/lib/modules/
|
||||||
|
|
||||||
|
chmod +x $dir/initram/bin/busybox
|
||||||
|
$dir/initram/bin/busybox --install -s "$dir/initram/bin/"
|
||||||
|
cp $dir/init.sh $dir/initram/init
|
||||||
|
cp $dir/linux/arch/x86_64/boot/bzImage $dir/bzImage.efi
|
||||||
|
chmod +x $dir/initram/init
|
||||||
|
cd $dir/initram/
|
||||||
|
find .
|
||||||
|
find . -print0 | cpio --null -ov --format=newc | gzip -9 > $dir/initramfs.cpio.gz
|
||||||
|
|
||||||
15
container_cmd.sh
Normal file
15
container_cmd.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
set -e
|
||||||
|
cores=$(nproc)
|
||||||
|
echo "${cores}"
|
||||||
|
/usr/bin/make clean
|
||||||
|
/usr/bin/make defconfig
|
||||||
|
#cat /boot/config-$(uname -r) > ./linux/.config
|
||||||
|
sed -i 's/CONFIG_SYSTEM_TRUSTED_KEYS="\.\*"/CONFIG_SYSTEM_TRUSTED_KEYS=""/' ./.config
|
||||||
|
sed -i 's/CONFIG_SYSTEM_REVOCATION_KEYS="\.\*"/CONFIG_SYSTEM_REVOCATION_KEYS=""/' ./.config
|
||||||
|
sed -i 's/CONFIG_EFI_STUB="\.\*"/CONFIG_EFI_STUB="n"/' ./.config
|
||||||
|
echo "CONFIG_FB_EFI=y" >> ./.config
|
||||||
|
echo "CONFIG_EFI=y" >> ./.config
|
||||||
|
echo "CONFIG_SYSFB=y" >> ./.config
|
||||||
|
echo "CONFIG_FB=y" >> ./.config
|
||||||
|
echo "CONFIG_FRAMEBUFFER_CONSOLE=y" >> ./.config
|
||||||
|
/usr/bin/make -j ${cores}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
from ubuntu
|
from ubuntu:latest
|
||||||
run apt update
|
run apt-get update
|
||||||
run apt upgrade
|
run apt-get upgrade -y
|
||||||
run apt install -y bison flex gcc make libncurses-dev git
|
run apt-get install -y bison flex gcc make libncurses-dev git bc build-essential git libncurses5-dev lzop perl libssl-dev bison flex kmod device-tree-compiler dwarves libelf-dev libdwarf-dev libdw-dev python3 gawk zstd
|
||||||
run apt install -y bc build-essential git libncurses5-dev lzop perl libssl-dev bison flex kmod device-tree-compiler
|
|
||||||
run apt install -y dwarves libelf-dev libdwarf-dev libdw-dev python3 gawk zstd
|
|
||||||
workdir /linux
|
workdir /linux
|
||||||
add ./kernelb.sh /
|
add ./container_cmd.sh /
|
||||||
run chmod +x /kernelb.sh
|
run chmod +x /container_cmd.sh
|
||||||
cmd ["/usr/bin/bash","-c","/kernelb.sh"]
|
cmd ["/usr/bin/bash","-c","/container_cmd.sh"]
|
||||||
|
|||||||
68
create_image.sh
Executable file
68
create_image.sh
Executable file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
dir=$(dirname "$0")
|
||||||
|
echo "${dir}"
|
||||||
|
if mountpoint -q "$dir/mnt/efi"; then
|
||||||
|
umount "$dir/mnt/efi"
|
||||||
|
fi
|
||||||
|
if mountpoint -q "$dir/mnt/sys"; then
|
||||||
|
umount "$dir/mnt/sys"
|
||||||
|
fi
|
||||||
|
disk="boot_image.img"
|
||||||
|
mnt="/mnt"
|
||||||
|
efi_part="1"
|
||||||
|
root_part="2"
|
||||||
|
dd if=/dev/zero of=boot_image.img count=1024 bs=1M
|
||||||
|
parted -s "$disk" mklabel gpt
|
||||||
|
parted -s --align=optimal "$disk" mkpart ESP fat32 1MiB 50Mib
|
||||||
|
parted -s "$disk" set "$efi_part" esp on
|
||||||
|
parted -s --align=optimal "$disk" mkpart ext2 100MiB 100%
|
||||||
|
parted -s "$disk" set "$root_part" boot on
|
||||||
|
parted -s "$disk" print
|
||||||
|
kpartx -d "$disk"
|
||||||
|
kpartx -avs "$disk"
|
||||||
|
loop="$(kpartx -l boot_image.img | grep -ow 'loop[0-9]*' | head -n 1)"
|
||||||
|
disk_efi="${loop}p1"
|
||||||
|
disk_sys="${loop}p2"
|
||||||
|
echo "${loop}"
|
||||||
|
echo "${disk_efi}"
|
||||||
|
echo "${disk_sys}"
|
||||||
|
mkfs.fat -F32 -n EFI /dev/mapper/${disk_efi}
|
||||||
|
mkfs.ext2 -L ROOT /dev/mapper/${disk_sys}
|
||||||
|
rm -rf $dir/mnt/
|
||||||
|
mkdir -p $dir/mnt/
|
||||||
|
mkdir -p $dir/mnt/{efi,sys,grub}
|
||||||
|
mount -t vfat /dev/mapper/${disk_efi} $dir/mnt/efi
|
||||||
|
mount -t ext4 /dev/mapper/${disk_sys} $dir/mnt/sys
|
||||||
|
|
||||||
|
#--grub-mkdevicemap=$dir/mnt/device.map
|
||||||
|
#echo "(hd0) /dev/${disk_grub}" > $dir/mnt/device.map
|
||||||
|
#--efi-directory=$dir/mnt/efi --boot-directory=$dir/mnt/grub --root-directory=$dir/mnt/sys
|
||||||
|
grub-install --target=x86_64-efi --recheck --no-floppy --efi-directory=$dir/mnt/efi --root-directory=$dir/mnt/sys --bootloader-id=patronage /dev/$loop
|
||||||
|
#umount $dir/mnt/image
|
||||||
|
#lsblk -f
|
||||||
|
mkdir -p $dir/mnt/efi/boot/
|
||||||
|
cp $dir/initramfs.cpio.gz $dir/mnt/efi/
|
||||||
|
mkdir -p $dir/mnt/efi/EFI/patronage/
|
||||||
|
cp $dir/linux/arch/x86_64/boot/bzImage $dir/mnt/efi/EFI/patronage/bzImage
|
||||||
|
cp $dir/initramfs.cpio.gz $dir/mnt/efi/EFI/patronage/
|
||||||
|
#cp $dir/linux/arch/x86/boot/compressed/vmlinux $dir/mnt/efi/
|
||||||
|
#cp $dir/linux/arch/x86/boot/vmlinux.bin $dir/mnt/efi/
|
||||||
|
#cp $dir/initramfs.cpio.gz $dir/mnt/sys/
|
||||||
|
#cp $dir/linux/arch/x86_64/boot/bzImage $dir/mnt/sys/
|
||||||
|
#cp $dir/linux/arch/x86/boot/compressed/vmlinux $dir/mnt/sys/
|
||||||
|
#cp $dir/linux/arch/x86/boot/vmlinux.bin $dir/mnt/sys/
|
||||||
|
|
||||||
|
cp $dir/grub.cfg $dir/mnt/efi/EFI/patronage/
|
||||||
|
#cp $dir/grub.cfg $dir/mnt/sys/boot/grub/
|
||||||
|
cp $dir/grub.cfg $dir/mnt/efi/EFI/BOOT/
|
||||||
|
sync
|
||||||
|
#exit
|
||||||
|
if mountpoint -q "$dir/mnt/efi"; then
|
||||||
|
umount "$dir/mnt/efi"
|
||||||
|
fi
|
||||||
|
if mountpoint -q "$dir/mnt/sys"; then
|
||||||
|
umount "$dir/mnt/sys"
|
||||||
|
fi
|
||||||
|
kpartx -d boot_image.img
|
||||||
17
grub.cfg
Normal file
17
grub.cfg
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
set timeout=1
|
||||||
|
set default=0
|
||||||
|
insmod fat
|
||||||
|
insmod part_gpt
|
||||||
|
insmod gzio
|
||||||
|
|
||||||
|
set root='(hd0,gpt1)'
|
||||||
|
menuentry "PatronageOS" {
|
||||||
|
ls (hd0,gpt1)/EFI/patronage/
|
||||||
|
linux /EFI/patronage/bzImage quiet splash debug=yes ramdisk_size=500000,1 boot=/init
|
||||||
|
echo 'loaded kernel...'
|
||||||
|
initrd /EFI/patronage/initramfs.cpio.gz
|
||||||
|
echo 'loaded initial ramdisk...'
|
||||||
|
set debug=all
|
||||||
|
boot
|
||||||
|
echo 'done.'
|
||||||
|
}
|
||||||
8
init.sh
Normal file
8
init.sh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/busybox sh
|
||||||
|
/bin/busybox mount -t devtmpfs devtmpfs /dev
|
||||||
|
/bin/busybox mount -t proc none /proc
|
||||||
|
/bin/busybox mount -t sysfs none /sys
|
||||||
|
#/bin/busybox ln -s "/lib/modules/" "/lib/modules/$(uname -r)"
|
||||||
|
#depmod -a
|
||||||
|
#/bin/busybox modprobe nbd max_part=2
|
||||||
|
exec /bin/busybox sh
|
||||||
Reference in New Issue
Block a user