diff --git a/.gitignore b/.gitignore index ccdb427..8f41f2a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ .nfs* *.iso + +out/ \ No newline at end of file diff --git a/README.md b/README.md index 4195e53..947ebca 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,17 @@ # reHDD-Bootable -Scripts and tools to create a bootable image with reHDD based on debian. +Scripts and tools to create a bootable image with reHDD based on openSuse. ## Requirements -The scripts are used to run within a Debian-based machine as host. -Use a host os that is installed/started in UEFI mode. +The scripts are used to run within a openSuse-based machine as host. -``` -apt-get install \ - debootstrap \ - squashfs-tools \ - xorriso \ - isolinux \ - syslinux-efi \ - grub-pc-bin \ - grub-efi-amd64-bin \ - grub-efi-ia32-bin \ - mtools \ - dosfstools \ - screenfetch \ - htop \ - git \ - curl - -``` +## Build Image +`sudo bash ./create_bootable.sh` ## Test - -`qemu-system-x86_64 -boot d -cdrom reHDD_Bootable.iso -m 1024 -smp 2` \ No newline at end of file +### BIOS +`qemu-system-x86_64 -boot d -cdrom reHDD_Bootable.iso -m 2048 -smp 2` +### UEFI +`qemu-system-x86_64 -bios /usr/share/qemu/ovmf-x86_64.bin -boot d -cdrom reHDD_Bootable.iso -m 2048 -smp 2` diff --git a/appliance.kiwi b/appliance.kiwi new file mode 100644 index 0000000..3a8670c --- /dev/null +++ b/appliance.kiwi @@ -0,0 +1,76 @@ + + + + + Hendrik Schutter + localhorst@mosad.xyz + reHDD + + + 1.42.1 + zypper + en_US + us + UTC + true + true + breeze + openSUSE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..54d0662 --- /dev/null +++ b/config.sh @@ -0,0 +1,44 @@ +#!/bin/bash +#================ +# FILE : config.sh +#---------------- +# PROJECT : OpenSuSE KIWI Image System +# COPYRIGHT : (c) 2006 SUSE LINUX Products GmbH. All rights reserved +# : +# AUTHOR : Marcus Schaefer +# : +# BELONGS TO : Operating System images +# : +# DESCRIPTION : configuration script for SUSE based +# : operating systems +# : +# : +# STATUS : BETA +#---------------- +#====================================== +# Functions... +#-------------------------------------- +test -f /.kconfig && . /.kconfig +test -f /.profile && . /.profile + +#====================================== +# Greeting... +#-------------------------------------- +echo "Configure image: [$kiwi_iname]..." + +#====================================== +# Setup baseproduct link +#-------------------------------------- +suseSetupProduct + +#====================================== +# Activate services +#-------------------------------------- +suseInsertService sshd +suseInsertService grub_config +suseInsertService dracut_hostonly + +#====================================== +# Setup default target, multi-user +#-------------------------------------- +baseSetRunlevel 3 diff --git a/create_bootable.sh b/create_bootable.sh index 02c0543..6b75ae4 100644 --- a/create_bootable.sh +++ b/create_bootable.sh @@ -1,178 +1,27 @@ +#!/bin/bash +### Config ### ROOT_PASSWORD="rehdd" - -# Create a working directory -mkdir -p "${HOME}/LIVE_BOOT" - -# Create environment live directories -mkdir -p "${HOME}/LIVE_BOOT"/{staging/{EFI/BOOT,boot/grub/x86_64-efi,isolinux,live},tmp} - -# Download Debian environment -debootstrap \ - --arch=amd64 \ - --variant=minbase \ - stable \ - "${HOME}/LIVE_BOOT/chroot" \ - http://ftp.de.debian.org/debian/ - -# Set hostname -echo "reHDD" | sudo tee "${HOME}/LIVE_BOOT/chroot/etc/hostname" - -# Install Linux Kernel -chroot "${HOME}/LIVE_BOOT/chroot" << EOF -apt-get update && \ -apt-get install -y --no-install-recommends \ - linux-image-amd64 \ - live-boot \ - systemd-sysv -EOF - -# Install packages -chroot "${HOME}/LIVE_BOOT/chroot" << EOF -apt-get install -y --no-install-recommends \ - iwd \ - curl openssh-client \ - nano -EOF - -# Set root password -chroot "${HOME}/LIVE_BOOT/chroot" passwd root - -# Compress the chroot environment into a Squash filesystem -mksquashfs \ - "${HOME}/LIVE_BOOT/chroot" \ - "${HOME}/LIVE_BOOT/staging/live/filesystem.squashfs" \ - -e boot - -# Copy the kernel from inside the chroot to the live directory. -cp "${HOME}/LIVE_BOOT/chroot/boot"/vmlinuz-* \ - "${HOME}/LIVE_BOOT/staging/live/vmlinuz" - -# Copy initramfs from inside the chroot to the live directory. -cp "${HOME}/LIVE_BOOT/chroot/boot"/initrd.img-* \ - "${HOME}/LIVE_BOOT/staging/live/initrd" - - -# Create an ISOLINUX (Syslinux) boot menu -cat <<'EOF' > "${HOME}/LIVE_BOOT/staging/isolinux/isolinux.cfg" -UI vesamenu.c32 - -MENU TITLE Boot Menu -DEFAULT linux -TIMEOUT 600 -MENU RESOLUTION 640 480 -MENU COLOR border 30;44 #40ffffff #a0000000 std -MENU COLOR title 1;36;44 #9033ccff #a0000000 std -MENU COLOR sel 7;37;40 #e0ffffff #20ffffff all -MENU COLOR unsel 37;44 #50ffffff #a0000000 std -MENU COLOR help 37;40 #c0ffffff #a0000000 std -MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std -MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std -MENU COLOR msg07 37;40 #90ffffff #a0000000 std -MENU COLOR tabmsg 31;40 #30ffffff #00000000 std - -LABEL linux - MENU LABEL reHDD [BIOS] - MENU DEFAULT - KERNEL /live/vmlinuz - APPEND initrd=/live/initrd boot=live -EOF - -# Create an EFI/UEFI boot menu -cat <<'EOF' > "${HOME}/LIVE_BOOT/staging/boot/grub/grub.cfg" -insmod part_gpt -insmod part_msdos -insmod fat -insmod iso9660 - -insmod all_video -insmod font - -set default="0" -set timeout=30 - -# If X has issues finding screens, experiment with/without nomodeset. - -menuentry "reHDD [UEFI]" { - search --no-floppy --set=root --label DEBLIVE - linux ($root)/live/vmlinuz boot=live - initrd ($root)/live/initrd -} -EOF - -# Copy the grub.cfg file to the EFI BOOT directory -cp "${HOME}/LIVE_BOOT/staging/boot/grub/grub.cfg" "${HOME}/LIVE_BOOT/staging/EFI/BOOT/" - -# Create helper GRUB boot config -cat <<'EOF' > "${HOME}/LIVE_BOOT/tmp/grub-embed.cfg" -if ! [ -d "$cmdpath" ]; then - # On some firmware, GRUB has a wrong cmdpath when booted from an optical disc. - # https://gitlab.archlinux.org/archlinux/archiso/-/issues/183 - if regexp --set=1:isodevice '^(\([^)]+\))\/?[Ee][Ff][Ii]\/[Bb][Oo][Oo][Tt]\/?$' "$cmdpath"; then - cmdpath="${isodevice}/EFI/BOOT" - fi +if [ "$EUID" -ne 0 ]; then + echo "This script must be run as root" + exit 1 fi -configfile "${cmdpath}/grub.cfg" -EOF -# Copy BIOS/legacy boot required files to live environment -cp /usr/lib/ISOLINUX/isolinux.bin "${HOME}/LIVE_BOOT/staging/isolinux/" -cp /usr/lib/syslinux/modules/bios/* "${HOME}/LIVE_BOOT/staging/isolinux/" +### Cleanup ### +printf "\nCleanup\n" +rm -rf reHDD-Bootable.iso +rm -rf out/ -# Copy EFI/modern boot required files to live environment -cp -r /usr/lib/grub/x86_64-efi/* "${HOME}/LIVE_BOOT/staging/boot/grub/x86_64-efi/" +### Build ### +printf "\nBuild\n" +START=$(date +%s.%N) +mkdir -p out +kiwi-ng system build --description ./ --set-repo obs://openSUSE:Tumbleweed/standard --target-dir ./out +mv -f ./out/*.iso reHDD_Bootable.iso 2>/dev/null; true -# Generate an EFI bootable GRUB image. -grub-mkstandalone -O i386-efi \ - --modules="part_gpt part_msdos fat iso9660" \ - --locales="" \ - --themes="" \ - --fonts="" \ - --output="${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTIA32.EFI" \ - "boot/grub/grub.cfg=${HOME}/LIVE_BOOT/tmp/grub-embed.cfg" +chmod -R 777 ./out +chmod 777 reHDD_Bootable.iso -grub-mkstandalone -O x86_64-efi \ - --modules="part_gpt part_msdos fat iso9660" \ - --locales="" \ - --themes="" \ - --fonts="" \ - --output="${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTx64.EFI" \ - "boot/grub/grub.cfg=${HOME}/LIVE_BOOT/tmp/grub-embed.cfg" - -# Create a FAT16 UEFI boot disk image containing the EFI bootloaders. -(cd "${HOME}/LIVE_BOOT/staging" && \ - dd if=/dev/zero of=efiboot.img bs=1M count=20 && \ - mkfs.vfat efiboot.img && \ - mmd -i efiboot.img ::/EFI ::/EFI/BOOT && \ - mcopy -vi efiboot.img \ - "${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTIA32.EFI" \ - "${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTx64.EFI" \ - "${HOME}/LIVE_BOOT/staging/boot/grub/grub.cfg" \ - ::/EFI/BOOT/ -) - -# Generate ISO from live environment -xorriso \ - -as mkisofs \ - -iso-level 3 \ - -o "${HOME}/LIVE_BOOT/debian-custom.iso" \ - -full-iso9660-filenames \ - -volid "reHDD" \ - --mbr-force-bootable -partition_offset 16 \ - -joliet -joliet-long -rational-rock \ - -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \ - -eltorito-boot \ - isolinux/isolinux.bin \ - -no-emul-boot \ - -boot-load-size 4 \ - -boot-info-table \ - --eltorito-catalog isolinux/isolinux.cat \ - -eltorito-alt-boot \ - -e --interval:appended_partition_2:all:: \ - -no-emul-boot \ - -isohybrid-gpt-basdat \ - -append_partition 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B ${HOME}/LIVE_BOOT/staging/efiboot.img \ - "${HOME}/LIVE_BOOT/staging" - -cp "${HOME}/LIVE_BOOT/debian-custom.iso" reHDD_Bootable.iso \ No newline at end of file +DURATION=$(echo "$(date +%s.%N) - $START" | bc) +echo "Time taken: $DURATION seconds" \ No newline at end of file diff --git a/disk.sh b/disk.sh new file mode 100644 index 0000000..6861973 --- /dev/null +++ b/disk.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +env | grep kiwi diff --git a/root/.kiwi_dracut_hostonly.trigger b/root/.kiwi_dracut_hostonly.trigger new file mode 100644 index 0000000..e69de29 diff --git a/root/.kiwi_grub_config.trigger b/root/.kiwi_grub_config.trigger new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/sysconfig/network/ifcfg-lan0 b/root/etc/sysconfig/network/ifcfg-lan0 new file mode 100644 index 0000000..b01f9e1 --- /dev/null +++ b/root/etc/sysconfig/network/ifcfg-lan0 @@ -0,0 +1,4 @@ +BOOTPROTO='dhcp' +MTU='' +REMOTE_IPADDR='' +STARTMODE='onboot' diff --git a/root/etc/udev/rules.d/70-persistent-net.rules b/root/etc/udev/rules.d/70-persistent-net.rules new file mode 100644 index 0000000..8865e78 --- /dev/null +++ b/root/etc/udev/rules.d/70-persistent-net.rules @@ -0,0 +1 @@ +SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="?*", NAME="lan0" diff --git a/root/usr/lib/systemd/system/dracut_hostonly.service b/root/usr/lib/systemd/system/dracut_hostonly.service new file mode 100644 index 0000000..fb3cb77 --- /dev/null +++ b/root/usr/lib/systemd/system/dracut_hostonly.service @@ -0,0 +1,11 @@ +[Unit] +Description=Rebuild dracut initrd for this host +ConditionPathExists=/.kiwi_dracut_hostonly.trigger + +[Service] +Type=oneshot +ExecStart=/bin/bash -c 'dracut -f' +ExecStartPost=/bin/bash -c 'rm -f /.kiwi_dracut_hostonly.trigger' + +[Install] +WantedBy=multi-user.target diff --git a/root/usr/lib/systemd/system/grub_config.service b/root/usr/lib/systemd/system/grub_config.service new file mode 100644 index 0000000..2eca0ef --- /dev/null +++ b/root/usr/lib/systemd/system/grub_config.service @@ -0,0 +1,11 @@ +[Unit] +Description=Rebuild grub config from distro toolkit +ConditionPathExists=/.kiwi_grub_config.trigger + +[Service] +Type=oneshot +ExecStart=/bin/bash -c 'grub2-mkconfig -o /boot/grub2/grub.cfg' +ExecStartPost=/bin/bash -c 'rm -f /.kiwi_grub_config.trigger' + +[Install] +WantedBy=multi-user.target