52 lines
893 B
Markdown
52 lines
893 B
Markdown
# Build Linux from Scratch
|
|
|
|
## Prerequisites
|
|
|
|
```bash
|
|
sudo apt install qemu-system-x86 grub-pc-bin e2fsprogs
|
|
```
|
|
|
|
## Run
|
|
|
|
```bash
|
|
gcc -static -o init/init init/init.c
|
|
|
|
dd if=/dev/zero of=disk.img bs=1M count=512 status=none
|
|
echo -e "n\np\n1\n2048\n\nw" | fdisk disk.img > /dev/null
|
|
|
|
dd if=disk.img of=part.img bs=512 skip=2048 status=none
|
|
|
|
mkfs.ext4 part.img
|
|
debugfs -w -R "mkdir /boot" part.img
|
|
debugfs -w -R "mkdir /boot/grub" part.img
|
|
|
|
debugfs -w -R "write init/init /init" part.img
|
|
debugfs -w -R "write linux/arch/x86/boot/bzImage /boot/bzImage" part.img
|
|
debugfs -w -R "write grub/grub.cfg /boot/grub/grub.cfg" part.img
|
|
|
|
dd if=part.img of=disk.img bs=512 seek=2048 conv=notrunc status=none
|
|
|
|
```
|
|
|
|
Or, alternatively
|
|
|
|
```bash
|
|
make
|
|
```
|
|
|
|
|
|
# `make run`
|
|
|
|
```bash
|
|
ifconfig eth0 10.0.2.15
|
|
route add default gw 10.0.2.2
|
|
|
|
medit req.txt
|
|
GET / HTTP/1.0
|
|
Host: 1.1.1.1
|
|
|
|
:w
|
|
:q
|
|
|
|
nc 1.1.1.1 80 < req.txt
|
|
``` |