some polishing
[rrq/tiniest.git] / mkit.sh
diff --git a/mkit.sh b/mkit.sh
index 437a5f40e087c20e9e50ee99fce3899686ed6481..728fe335a81b96339d86bc3e374e580adbe5d16a 100755 (executable)
--- a/mkit.sh
+++ b/mkit.sh
@@ -14,6 +14,7 @@ REPO="deb.devuan.org/merged"
 SUITE="daedalus"
 SECTION="main"
 ARCH="amd64"
+MBR=dos # or dos
 
 PKGFILE=${REPO//\//_}_${SUITE}_${SECTION}_binary-${ARCH}_Packages
 if [ ! -r $PKGFILE ] ; then
@@ -26,7 +27,8 @@ echo "# Creating mapdepends.txt and mapfile.txt"
 awk '
 BEGIN { print "###" > "mapdepends.txt"; print "###" > "mapfile.txt"; }
 $1=="Package:" {P=$2; next}
-$1=="Depends:" {print P,$2 >> "mapdepends.txt";next }
+$1=="Pre-Depends:" {print P,$0 >> "mapdepends.txt";next }
+$1=="Depends:" {print P,$0 >> "mapdepends.txt";next }
 $1=="Filename:" {print P,$2 >> "mapfile.txt";next }
 ' ${PKGFILE}
 
@@ -64,9 +66,9 @@ echo $KERNEL
 echo "# Create initrd filesystem"
 rm -fr initrd
 
-echo "# Install busybox, and fluff it up"
-fakechroot fakeroot \
-dpkg --log=dpkg.log --root=initrd -i $(debfile busybox-static)
+echo "# Extract busybox, and fluff it up"
+mkdir initrd
+debextract initrd $(debfile busybox-static)
 for L in $(initrd/bin/busybox --listfull) ; do
     mkdir -p $(dirname initrd/$L)
     case "$L" in
@@ -98,8 +100,8 @@ MODULES=(
     t10-pi sd_mod sg
     nls_cp437 nls_ascii fat vfat
     crc32c_generic jbd2 mbcache crc16 ext4
+    usb-storage usbcore usb-common xhci-pci xhci-hcd
     isofs
-    overlay
     # input
     psmouse evdev
     # network
@@ -127,22 +129,7 @@ depmod -F initrd/System.map-$V -b initrd $V $MOODLES
 
 echo "# setup a scripted init. The kernel runs this via the #! interpreter"
 rm -f initrd/sbin/init # just in case
-cat <<EOF > initrd/init
-#!/bin/sh
-echo 
-echo 
-echo "Hi there, tiniest lover!"
-
-mkdir /proc
-mount -t proc proc /proc
-mount -t devtmpfs devtmpfs /dev
-mkdir /dev/pts
-mount -t devpts devpts /dev/pts
-mkdir /sys
-mount -t sysfs sysfs /sys
-$(for m in ${MODULES[@]} ; do echo modprobe $m ; done)
-exec /bin/sh
-EOF
+cp init/init initrd/init
 chmod a+x initrd/init
 
 echo "# Now pack up that initrd as initrd.gz"
@@ -152,8 +139,10 @@ echo "# Now pack up that initrd as initrd.gz"
 rm -f bootimage.raw
 dd if=/dev/zero of=bootimage.raw bs=32M count=1
 
-# Prepare a dos partition table with a first partition marked as EFI
+# Prepare a gpt/dos partition table with a first partition marked as EFI
 sfdisk bootimage.raw <<EOF
+label: $MBR
+
 2048 32767 U *
 - - L
 EOF
@@ -164,7 +153,7 @@ IMG="-i bootimage.raw@@$((2048*512))"
 
 # Add an ext2 filesystem at offset 61440*512
 # Copy initrd.gz and kernel into the fat filesystem root
-mke2fs -t ext4 -E offset=$((34816*512)) -F bootimage.raw
+mke2fs -t ext4 -E offset=$((34816*512)) -F bootimage.raw 15M
 
 mcopy $IMG initrd.gz ::
 mcopy $IMG kernel/boot/vm* ::/vmlinuz
@@ -184,6 +173,8 @@ mcopy $IMG \
       kernel/usr/lib/syslinux/modules/bios/* ::/boot/syslinux/bios
 mcopy $IMG syslinux-legacy.cfg ::/syslinux.cfg
 
+syslinux --install --offset=${IMG#*@@} bootimage.raw
+
 echo "# Set up UEFI boot"
 cat <<EOF > syslinux-uefi.cfg
 path /EFI/BOOT/efi64
@@ -192,15 +183,25 @@ EOF
 
 mmd $IMG ::/EFI
 mmd $IMG ::/EFI/BOOT
-mmd $IMG ::/EFI/BOOT/efi64
 mcopy $IMG kernel/usr/lib/SYSLINUX.EFI/efi64/syslinux.efi \
       ::/EFI/BOOT/bootx64.efi
 mcopy $IMG \
       kernel/usr/lib/syslinux/modules/efi64/* ::/EFI/BOOT
-mcopy $IMG syslinux-uefi.cfg ::/EFI/BOOT/syslx64.cfg
-
-syslinux --install --offset=${IMG#*@@} bootimage.raw
+mcopy $IMG syslinux-uefi.cfg ::/EFI/BOOT/syslinux.cfg
+
+#echo "# Set up isolinux boot"
+#mcopy $IMG kernel/usr/lib/ISOLINUX/isolinux.bin ::/
+
+case "$MBR" in
+    dos) MBRBIN=mbr.bin ;;
+    gpt)
+       MBRBIN=gptmbr.bin
+       sfdisk --relocate gpt-bak-std bootimage.raw
+       sfdisk -f --part-attrs bootimage.raw 1 LegacyBIOSBootable
+       ;;
+    *) exit 1 ;;
+esac
 dd conv=notrunc of=bootimage.raw bs=440 count=1 \
-   if=kernel/usr/lib/syslinux/mbr/mbr.bin
+   if=kernel/usr/lib/syslinux/mbr/$MBRBIN
 
 exit