3 # Utility script to debootstrap a minbase filesystem, with additions
4 # of kernel, busybox and an init script. Then make an initrd.gz from
5 # that and prepare a boot image file with syslinux from that.
7 if [ $(id -u) -ne 0 ] ; then
8 exec sudo env http_proxy=$http_proxy $0 $*
9 echo "** Abort: must be root" >&2
14 ARCH="${1-$(dpkg-architecture -q DEB_HOST_ARCH)}"
16 IMG=${3-boot-$DIST-$ARCH.img}
22 if [ -d "$FS" ] ; then
23 select x in "keep existing $FS and skip debootstrap" \
24 "remove existing $FS and debootstrap anew" \
26 [ "$x" = abort ] && exit 1
29 echo "selection: $REPLY"
30 [ "$REPLY" = 1 ] && DEBSTRAP=false
35 for d in bin sbin lib ; do mkdir $1/usr/$d ; ln -s usr/$d $1/$d ; done
39 ## Optionally add the stupid-links
40 read -n 1 -p "prime $FS with stupid-links? [Yn]" x
41 [ "$x" = "n" ] && USRMERGE=false
43 rm -rf "$FS" # remove if existin
45 $USRMERGE && stupid_links "$FS"
47 ## bootstrap a filesystem, with exclusions
48 echo "http_proxy=$http_proxy debootstrap ..."
49 debootstrap --exclude=logrotate,cron,cron-daemon-common \
50 --arch=$ARCH $DIST "$FS" http://deb.devuan.org/merged || \
51 chroot "$FS" apt-get -f install -y
52 chroot "$FS" apt-get install -y logrotate cron
54 ## Select and add a kernel
55 KERNELS=( $(chroot "$FS" apt-cache search linux-image-\* | \
56 sed 's/\s.*//' | sort -h ) )
57 echo "** Please select kernel **"
58 select KERNEL in "${KERNELS[@]}" ; do [ -n "$KERNEL" ] && break ; done
59 VERSION=${KERNEL#linux-image-}
60 VERSION=${VERSION%-unsigned}
61 chroot "$FS" apt-get install -y $KERNEL
62 chroot "$FS" depmod -a $VERSION
64 chroot "$FS" apt-get install -y busybox-static debootstrap
65 touch "$FS"/usr/bin{linuxrc,init} # block these
66 chroot "$FS" /usr/bin/busybox --install -s /usr/bin
68 fi # End of $DEBSTRAP actions
70 ## Pick boot kernel, if there are many
71 LINUXES=( $(cd "$FS"/boot ; ls vmlinuz* 2>/dev/null) )
72 if [ ${#LINUXES[@]} -gt 1 ] ; then
73 echo "** Please select boot kernel"
74 select LINUX in $LINUXES ; do [ -n "$LINUX" ] && break ; done
75 elif [ -n "$LINUXES" ] ; then
76 LINUX="$FS"/boot/${LINUXES[0]}
78 echo "** Oh No! There is no $FS/boot/vmlinux-* ... bailing out!" >&2
82 . ./minbase-strap-initrd.sh
84 #============================================================
85 # Common syslinux menu
86 CON="console=ttyS0,115200"
87 cat <<EOF > $TMP/menu.cfg
91 append initrd=/initrd.img init=/init $CON rescue
94 append initrd=/initrd.img init=/init rescue
97 append initrd=/initrd.img root=/dev/sda2 rootfstype=squashfs $CON
100 append initrd=/initrd.img root=/dev/sdb1 $CON
103 . ./minbase-strap-bios.sh
104 . ./minbase-strap-uefi.sh
105 . ./minbase-strap-mkimg.sh
107 for E in $ENDING ; do $E ; done
109 #. ./minbase-strap-mkiso.sh $IMG