additional bash programming to support a json configuration file.
still working on kernel options for proper networking.
This commit is contained in:
8
scripts/boot_image.sh
Executable file
8
scripts/boot_image.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
cd "$(dirname "$0")"
|
||||
cd ..
|
||||
disk="./outputs/boot_image.img"
|
||||
|
||||
|
||||
qemu-system-x86_64 -bios /usr/share/ovmf/OVMF.fd -drive if=none,format=raw,file=$disk,id=hd -device virtio-blk-pci,drive=hd -m 16G -smp 8 -vga none --display default,gl=off -usb -device virtio-tablet-pci -device virtio-keyboard-pci --device virtio-gpu-pci -usb -enable-kvm -machine type=pc-q35-3.1,accel=kvm,kernel_irqchip=on -netdev user,id=net0 -device virtio-net-pci,netdev=net0,mac=52:54:00:12:34:56
|
||||
#--display gtk,gl=off --device virtio-gpu
|
||||
19
scripts/bootstrap_filesystem.sh
Executable file
19
scripts/bootstrap_filesystem.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "switching from $(id -un) to root"
|
||||
exec sudo "$0" "$@"
|
||||
fi
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
DIR="$(dirname "$0")"
|
||||
cd ..
|
||||
echo $PWD
|
||||
|
||||
rm -rf './outputs/root'
|
||||
if [ ! -d ./outputs/root/bin ]; then
|
||||
rm -rf './outputs/root'
|
||||
mkdir -p ./outputs/root/
|
||||
debootstrap questing ./outputs/root https://us.archive.ubuntu.com/ubuntu
|
||||
fi
|
||||
|
||||
13
scripts/build_everything.sh
Executable file
13
scripts/build_everything.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
dir=$(dirname "$0")
|
||||
echo $dir
|
||||
cd $dir
|
||||
./install_dependencies.sh
|
||||
./build_kernel.sh
|
||||
./build_initramfs.sh
|
||||
./build_filesystem.sh
|
||||
./build_image.sh
|
||||
|
||||
|
||||
|
||||
44
scripts/build_filesystem.sh
Executable file
44
scripts/build_filesystem.sh
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "switching from $(id -un) to root"
|
||||
exec sudo "$0" "$@"
|
||||
fi
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
DIR="$(dirname "$0")"
|
||||
cd ..
|
||||
echo $PWD
|
||||
if mountpoint -q "./outputs/chroot/proc/"; then
|
||||
umount -lf "./outputs/chroot/proc/"
|
||||
fi
|
||||
rm -rf './outputs/chroot'
|
||||
mkdir -p ./outputs/chroot/
|
||||
if mountpoint -q "./outputs/root/proc/"; then
|
||||
umount -lf "./outputs/root/proc/"
|
||||
fi
|
||||
rsync -a ./outputs/root/ ./outputs/chroot/
|
||||
mkdir -p ./outputs/chroot/proc
|
||||
mount --bind /proc ./outputs/chroot/proc
|
||||
cp ./config/filesystem_chroot_install.sh ./outputs/chroot/filesystem_chroot_install.sh
|
||||
cp ./config/apply_initial_host_configuration.sh ./outputs/chroot/apply_initial_host_configuration.sh
|
||||
cp ./config/config.json ./outputs/chroot/config.json
|
||||
|
||||
#setup user skeleton
|
||||
cp ./config/settings/skel/bash_profile ./outputs/chroot/etc/skel/.bash_profile
|
||||
cp ./config/settings/skel/bashrc ./outputs/chroot/etc/skel/.bashrc
|
||||
cp ./config/settings/skel/profile ./outputs/chroot/etc/skel/.profile
|
||||
|
||||
chmod +x ./outputs/chroot/filesystem_chroot_install.sh
|
||||
chmod +x ./outputs/chroot/apply_initial_host_configuration.sh
|
||||
chroot ./outputs/chroot /bin/bash -c "/filesystem_chroot_install.sh"
|
||||
chroot ./outputs/chroot /bin/bash -c "/apply_initial_host_configuration.sh"
|
||||
|
||||
|
||||
|
||||
cd $DIR
|
||||
cd ..
|
||||
if mountpoint -q "./outputs/chroot/proc/"; then
|
||||
umount -lf "./outputs/chroot/proc/"
|
||||
fi
|
||||
echo 'root filesystem created.'
|
||||
86
scripts/build_image.sh
Executable file
86
scripts/build_image.sh
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "switching from $(id -un) to root"
|
||||
exec sudo "$0" "$@"
|
||||
fi
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
cd ..
|
||||
echo "$PWD"
|
||||
sync
|
||||
if mountpoint -q "./outputs/efi"; then
|
||||
umount "./outputs/efi"
|
||||
fi
|
||||
if mountpoint -q "./outputs/sys"; then
|
||||
umount "./outputs/sys"
|
||||
fi
|
||||
echo 'creating image..'
|
||||
disk="./outputs/boot_image.img"
|
||||
efi_part="1"
|
||||
root_part="2"
|
||||
dd if=/dev/zero of="$disk" count=12000 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 ext4 100MiB 100%
|
||||
parted -s "$disk" set "$root_part" boot on
|
||||
parted -s "$disk" print
|
||||
kpartx -d "$disk"
|
||||
kpartx -avs "$disk"
|
||||
echo 'mounting image as loopback device..'
|
||||
loop="$(kpartx -l $disk | grep -ow 'loop[0-9]*' | head -n 1)"
|
||||
disk_efi="${loop}p1"
|
||||
disk_sys="${loop}p2"
|
||||
echo 'formatting image partitions..'
|
||||
mkfs.fat -F32 -n EFI /dev/mapper/${disk_efi}
|
||||
mkfs.ext4 -L ROOT /dev/mapper/${disk_sys}
|
||||
echo 'creating mount points..'
|
||||
rm -rf ./outputs/{efi,sys,grub}
|
||||
mkdir -p ./outputs/
|
||||
mkdir -p ./outputs/{efi,sys,grub}
|
||||
echo 'mounting loopback devices..'
|
||||
mount -t vfat /dev/mapper/${disk_efi} ./outputs/efi
|
||||
mount -t ext4 /dev/mapper/${disk_sys} ./outputs/sys
|
||||
echo 'installing grub..'
|
||||
echo "loop dev: ${loop}"
|
||||
echo "efi loop: ${disk_efi}"
|
||||
echo "sys loop: ${disk_sys}"
|
||||
grub-install -s --compress=gz --target=x86_64-efi --recheck --no-floppy --efi-directory=./outputs/efi --boot-directory=./outputs/efi --root-directory=./outputs/sys --bootloader-id=patronage /dev/$loop
|
||||
echo 'copying filesystem to mounted image..'
|
||||
if mountpoint -q "./outputs/chroot/proc/"; then
|
||||
umount -lf "./outputs/chroot/proc/"
|
||||
fi
|
||||
cp ./config/interfaces.network ./outputs/chroot/etc/systemd/network/10-all.network
|
||||
cp ./config/resolved.conf ./outputs/chroot/etc/systemd/resolved.conf
|
||||
rsync -a './outputs/chroot/' './outputs/sys/'
|
||||
|
||||
|
||||
#tar -xf ./patronagefs.tar --directory ./mnt/sys/
|
||||
echo 'copied..'
|
||||
echo 'copying boot files..'
|
||||
mkdir -p ./outputs/efi/boot/
|
||||
cp ./outputs/initramfs.cpio.gz ./outputs/efi/
|
||||
mkdir -p ./outputs/efi/EFI/patronage/
|
||||
cp ./outputs/bzImage ./outputs/efi/EFI/patronage/bzImage
|
||||
cp ./outputs/initramfs.cpio.gz ./outputs/efi/EFI/patronage/
|
||||
|
||||
cp ./config/grub.cfg ./outputs/efi/EFI/patronage/
|
||||
#cp $dir/grub.cfg $dir/mnt/sys/boot/grub/
|
||||
cp ./config/grub.cfg ./outputs/efi/EFI/BOOT/
|
||||
echo 'unmounting..'
|
||||
|
||||
if mountpoint -q "./outputs/efi"; then
|
||||
sync
|
||||
#fuser -kmv "$dir/mnt/efi"
|
||||
umount -lf "./outputs/efi"
|
||||
fi
|
||||
|
||||
if mountpoint -q "./outputs/sys"; then
|
||||
sync
|
||||
#fuser -kmv "$dir/mnt/sys"
|
||||
umount -lf "./outputs/sys"
|
||||
fi
|
||||
|
||||
kpartx -d "$disk"
|
||||
chmod 777 "$disk"
|
||||
echo 'image built..'
|
||||
30
scripts/build_initramfs.sh
Executable file
30
scripts/build_initramfs.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
cd ..
|
||||
echo $PWD
|
||||
echo "cleaning filesystem and creating initram directories"
|
||||
rm -rf ./dependencies/initram/
|
||||
mkdir -p ./outputs/
|
||||
mkdir -p ./dependencies/
|
||||
mkdir -p ./dependencies/initram/
|
||||
mkdir -p ./dependencies/initram/{bin,dev,etc,lib,proc,sbin,sys,tmp,usr}
|
||||
mkdir -p ./dependencies/initram/usr/{bin,sbin}
|
||||
mkdir -p ./dependencies/initram/etc/{bin,sbin}
|
||||
mkdir -p ./dependencies/initram/lib/modules/
|
||||
echo "installing busybox"
|
||||
cp ./busybox ./dependencies/initram/bin/
|
||||
chmod +x ./dependencies/initram/bin/busybox
|
||||
chmod 4755 ./dependencies/initram/bin/busybox
|
||||
./dependencies/initram/bin/busybox --install -s "./dependencies/initram/bin/"
|
||||
|
||||
cp ./config/init.sh ./dependencies/initram/init
|
||||
chmod +x ./dependencies/initram/init
|
||||
#chmod 4755 ./dependencies/initram/bin/init
|
||||
echo "copying kernel"
|
||||
cp ./dependencies/linux/arch/x86_64/boot/bzImage ./outputs/bzImage
|
||||
cd ./dependencies/initram/
|
||||
find ./bin -type f -name "*" -exec chmod +x {} +
|
||||
|
||||
find . -print0 | cpio --null -o --format=newc --owner root:root | zstd -19 > ../../outputs/initramfs.cpio.gz
|
||||
echo "created initramfs."
|
||||
17
scripts/build_kernel.sh
Executable file
17
scripts/build_kernel.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
cd ..
|
||||
mkdir -p ./dependencies
|
||||
rootdir=$(dirname "$0")
|
||||
dir=./$(dirname "$0")
|
||||
cd dependencies
|
||||
[[ -d ./linux ]] || git clone --depth 1 https://github.com/torvalds/linux.git ./linux
|
||||
cd "$(dirname "$0")"
|
||||
cd ..
|
||||
echo $PWD
|
||||
cp ./config/kernel_options.json ./dependencies/linux/kernel_options.json
|
||||
cat ./config/build_containerfile | /usr/bin/podman build --volume /lib/modules:/lib/modules:z -f - -t patronagekernel:latest .
|
||||
nice -n 20 /usr/bin/podman run -it --volume /lib/modules:/lib/modules:z --volume ./dependencies/linux:/linux patronagekernel:latest
|
||||
mkdir -p ./outputs/
|
||||
cp ./dependencies/linux/arch/x86_64/boot/bzImage ./outputs/bzImage
|
||||
13
scripts/install_dependencies.sh
Executable file
13
scripts/install_dependencies.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#install dependencies
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "switching from $(id -un) to root"
|
||||
exec sudo "$0" "$@"
|
||||
fi
|
||||
set -e
|
||||
list="kpartx podman debootstrap "
|
||||
apt update
|
||||
for item in $list; do
|
||||
apt install -y $item
|
||||
done
|
||||
cd "$(dirname "$0")"
|
||||
find . -type f -name "*" -exec chmod +x {} +
|
||||
Reference in New Issue
Block a user