From 517586891e0f90b9176114f34635fd5af44d6be5 Mon Sep 17 00:00:00 2001 From: Michiel Derhaeg Date: Sat, 6 Aug 2016 10:08:36 +0200 Subject: [PATCH] did lots of work --- Makefile | 4 +++- filesystem/Makefile | 4 ++-- filesystem/build.sh | 2 +- filesystem/inittab | 5 +++-- filesystem/passwd | 7 +------ filesystem/rcS | 2 -- filesystem/systemctl | 27 +++++++++++++++++++++++++++ gen_image.sh | 21 ++++++++++++++++----- 8 files changed, 53 insertions(+), 19 deletions(-) delete mode 100644 filesystem/rcS create mode 100644 filesystem/systemctl diff --git a/Makefile b/Makefile index 159c083..b899672 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ KERNEL_URL=https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-$(KERNEL_VERSION). BUSYBOX_VERSION=1.24.2 BUSYBOX_URL=https://www.busybox.net/downloads/busybox-$(BUSYBOX_VERSION).tar.bz2 -all: bzImage +all: fs.tar linux-$(KERNEL_VERSION).tar.xz: wget $(KERNEL_URL) @@ -33,3 +33,5 @@ fs.tar: bzImage busybox mdos.img: fs.tar gen_image.sh ./gen_image.sh + +.PHONY: fs.tar diff --git a/filesystem/Makefile b/filesystem/Makefile index 8fd8ea5..d68fd59 100644 --- a/filesystem/Makefile +++ b/filesystem/Makefile @@ -1,4 +1,4 @@ -FS_FILES=build.sh crypttab filesystem.install fstab group gshadow host.conf hosts inittab issue ld.so.conf locale.sh modprobe.d.usb-load-ehci-first motd nsswitch.conf os-release passwd profile rcS resolv.conf securetty shadow shells +FS_FILES=build.sh crypttab filesystem.install fstab group gshadow host.conf hosts inittab issue ld.so.conf locale.sh modprobe.d.usb-load-ehci-first motd nsswitch.conf os-release passwd profile systemctl resolv.conf securetty shadow shells -all: build.sh $(FS_FILES) +../fs.tar: build.sh $(FS_FILES) fakeroot ./build.sh diff --git a/filesystem/build.sh b/filesystem/build.sh index db2b21f..81a9063 100755 --- a/filesystem/build.sh +++ b/filesystem/build.sh @@ -89,6 +89,6 @@ busybox --install -s usr/bin install -m644 "$srcdir/inittab" etc/inittab install -d -m755 etc/init.d -install -m755 "$srcdir/rcS" etc/init.d/rcS +install -m755 "$srcdir/systemctl" sbin/systemctl tar --xattrs -cpf ../../fs.tar * diff --git a/filesystem/inittab b/filesystem/inittab index aa77469..ad6cd9c 100644 --- a/filesystem/inittab +++ b/filesystem/inittab @@ -1,3 +1,4 @@ -::sysinit:/etc/init.d/rcS -::respawn:-/bin/sh +::sysinit:/sbin/systemctl init +::askfirst:-/bin/sh ::ctrlaltdel:/bin/umount -a -r +::shutdown:/usr/bin/umount -a -r diff --git a/filesystem/passwd b/filesystem/passwd index b3e79eb..d01c2d4 100644 --- a/filesystem/passwd +++ b/filesystem/passwd @@ -1,4 +1,4 @@ -root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/sh bin:x:1:1:bin:/bin:/usr/bin/nologin daemon:x:2:2:daemon:/:/usr/bin/nologin mail:x:8:12:mail:/var/spool/mail:/usr/bin/nologin @@ -7,8 +7,3 @@ http:x:33:33:http:/srv/http:/usr/bin/nologin uuidd:x:68:68:uuidd:/:/usr/bin/nologin dbus:x:81:81:dbus:/:/usr/bin/nologin nobody:x:99:99:nobody:/:/usr/bin/nologin -systemd-journal-gateway:x:191:191:systemd-journal-gateway:/:/usr/bin/nologin -systemd-timesync:x:192:192:systemd-timesync:/:/usr/bin/nologin -systemd-network:x:193:193:systemd-network:/:/usr/bin/nologin -systemd-bus-proxy:x:194:194:systemd-bus-proxy:/:/usr/bin/nologin -systemd-resolve:x:195:195:systemd-resolve:/:/usr/bin/nologin diff --git a/filesystem/rcS b/filesystem/rcS deleted file mode 100644 index 15151ac..0000000 --- a/filesystem/rcS +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -/usr/bin/mount -a diff --git a/filesystem/systemctl b/filesystem/systemctl new file mode 100644 index 0000000..42bbea3 --- /dev/null +++ b/filesystem/systemctl @@ -0,0 +1,27 @@ +#!/bin/sh + +init() { + # TODO options + /usr/bin/mount -t proc proc /proc + /usr/bin/mount -t sysfs sys /sys + /usr/bin/mount -t devtmpfs dev /dev + mkdir -p /dev/pts /dev/shm # TODO check if in filesystem + /usr/bin/mount -t devpts devpts /dev/pts + /usr/bin/mount -t tmpfs tmpfs /dev/shm + + if [[ -f /etc/hostname ]]; then + echo "$(cat /etc/hostname)" > /proc/sys/kernel/hostname + fi + + /sbin/mdev -s + echo /sbin/mdev > /proc/sys/kernel/hotplug + + /usr/bin/mount -a + /usr/bin/mount -o remount,rw / +} + +case $1 in + init) + init + ;; +esac diff --git a/gen_image.sh b/gen_image.sh index 2191de6..988be4d 100755 --- a/gen_image.sh +++ b/gen_image.sh @@ -5,10 +5,12 @@ if [[ $(id -u) -ne 0 ]]; then exit 1 fi -rm -f mdos.img -fallocate -l 100M mdos.img -echo -e "o\nn\n\n\n\n\nw\n" | fdisk mdos.img -loopdevice="$(losetup -P --show -f mdos.img)" +image=mdos.img + +rm -f $image +fallocate -l 100M $image +echo -e "o\nn\n\n\n\n\nw\n" | fdisk $image +loopdevice="$(losetup -P --show -f $image)" looppart=${loopdevice}p1 mkfs.ext4 $looppart @@ -16,9 +18,18 @@ mkdir -p mountdir mount $looppart mountdir cd mountdir tar --xattrs -xpf ../fs.tar -grub-install --target=i386-pc --boot-directory="$PWD/boot/grub" $loopdevice +grub-install --target=i386-pc --boot-directory="$PWD/boot" $loopdevice cd .. + +## generate grub.cfg (since linux 3.8 32-bit MBR "NT disk signatures" are allowed) +uuid=$(fdisk -l $image | grep "Disk identifier" | cut -d " " -f 3 | cut --complement -c 1,2)-01 +echo -e "linux /boot/bzImage root=PARTUUID=$uuid\nboot" > "mountdir/boot/grub/grub.cfg" + umount mountdir sync rm -rf mountdir losetup -d $loopdevice + +if [[ -n $SUDO_UID ]]; then + chown $SUDO_UID:$SUDO_GID $image +fi