-
-
Save criskell/b245a2c2abae18710a7973d41bfc8e17 to your computer and use it in GitHub Desktop.
initramfs
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
#!/bin/sh | |
mount -t proc proc /proc | |
mount -t sysfs sysfs /sys | |
mount -t devtmpfs devtmpfs /dev | |
# we need to do the redirection only when we are the leader of the process group session. | |
# activating the tty starting at tty_open (https://github.com/torvalds/linux/blob/86731a2a651e58953fc949573895f2fa6d456841/drivers/tty/tty_io.c#L2169) | |
# because of the dup2 syscall will cause the tty_open_proc_set_tty function with | |
# the current process being the leader and passing [this check](https://github.com/torvalds/linux/blob/86731a2a651e58953fc949573895f2fa6d456841/drivers/tty/tty_jobctrl.c#L136). | |
setsid sh -c 'exec sh <dev/ttyS0 >/dev/ttyS0 2>&1' | |
## alternative | |
# launch first sh process directly as session leader | |
# https://github.com/torvalds/linux/blob/86731a2a651e58953fc949573895f2fa6d456841/drivers/tty/tty_jobctrl.c#L136 | |
#!/usr/bin/setsid /bin/sh | |
mount -t proc proc /proc | |
mount -t sysfs sysfs /sys | |
mount -t devtmpfs devtmpfs /dev | |
exec sh </dev/ttyS0 >/dev/ttyS0 2>&1 |
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
#!/usr/bin/env bash | |
# at linux root source directory | |
rm -rf ./initramfs.cpio.gz | |
cd initramfs | |
find . | cpio -o -H newc | gzip > ../initramfs.cpio.gz | |
cd .. | |
qemu-system-x86_64 \ | |
-kernel arch/x86/boot/bzImage \ | |
-initrd initramfs.cpio.gz \ | |
-nographic \ | |
-append "console=ttyS0 init=/init" | |
# exit with ctrl + a + x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Patch 2