Last active
August 29, 2015 14:20
-
-
Save PkmX/6fa2778259d44c84cb33 to your computer and use it in GitHub Desktop.
OSDI Lab8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/sbin/busybox sh | |
set -e | |
/sbin/busybox --install -s | |
mount -t proc proc /proc | |
mount -t sysfs sysfs /sys | |
mknod -m 666 /dev/null c 1 3 | |
mknod -m 666 /dev/zero c 1 5 | |
mknod -m 666 /dev/ptmx c 5 2 | |
mknod -m 666 /dev/tty c 5 0 | |
mknod -m 444 /dev/random c 1 8 | |
mknod -m 444 /dev/urandom c 1 9 | |
mknod -m 620 /dev/tty1 c 4 1 | |
mknod -m 620 /dev/tty2 c 4 2 | |
mknod -m 620 /dev/tty3 c 4 3 | |
mknod -m 620 /dev/tty4 c 4 4 | |
mknod -m 620 /dev/tty5 c 4 5 | |
mknod -m 620 /dev/tty6 c 4 6 | |
mknod -m 620 /dev/tty7 c 4 7 | |
mknod -m 620 /dev/tty8 c 4 8 | |
ip link set eth0 up | |
ip link set lo up | |
exec /sbin/init |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ifneq ($(KERNELRELEASE),) | |
obj-m := lab8.o | |
else | |
KERNELDIR ?= linux-2.6.32.60 | |
PWD := $(shell pwd) | |
SPACE := | |
SPACE += | |
eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1))) | |
.SECONDEXPANSION: | |
.PHONY: all clean qemu | |
all: initramfs.cpio.gz | |
lab8.ko: | |
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules | |
qemu: all | |
qemu-system-x86_64 -kernel $(KERNELDIR)/arch/x86_64/boot/bzImage -initrd initramfs.cpio.gz $(QEMUFLAGS) | |
malloc: malloc.c | |
$(CC) $(CPPFLAGS) -static $(CFLAGS) $< -o $@ | |
busybox: | |
wget -nv http://www.busybox.net/downloads/binaries/latest/busybox-x86_64 -O $@ | |
chmod a+x $@ | |
INITRAMFS := initramfs/ | |
INITRAMFS_DIRS := $(INITRAMFS) $(addprefix $(INITRAMFS),bin/ dev/ etc/ lib/ proc/ sbin/ sys/ usr/ usr/bin/ usr/sbin/) | |
INITRAMFS_BINS := $(addprefix $(INITRAMFS),init sbin/busybox usr/bin/malloc lib/lab8.ko) | |
$(INITRAMFS_DIRS): %: | $$(if $$(call eq, $$(INITRAMFS), $$@),,$$(shell dirname $$@)/) | |
mkdir $@ | |
$(INITRAMFS_BINS): %: $$(notdir $$@) | $$(shell dirname $$@)/ | |
install -m755 $< $@ | |
initramfs.cpio: $(INITRAMFS_DIRS) $(INITRAMFS_BINS) | |
cd $(INITRAMFS) && \ | |
echo -e "$(subst $(SPACE),\n,$(^:$(INITRAMFS)%=./%))" | cpio -v -H newc -o > $(abspath $@) | |
%.gz: % | |
gzip - < $< > $@ | |
clean: | |
-$(MAKE) -C $(KERNELDIR) M=$(PWD) clean | |
-rm malloc | |
-rm -r initramfs.cpio initramfs.cpio.gz $(INITRAMFS) | |
distclean: clean | |
-rm busybox | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment