Size: 2618
Comment:
|
Size: 2753
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 83: | Line 83: |
# test with qemu with kernel in debian system qemu-system-x86_64 -kernel /boot/vmlinuz-5.10.0-22-amd64 -initrd test.cpio.gz /dev/zero |
LinuxFromScratch
Linux From Scratch (LFS) is a project that provides you with step-by-step instructions for building your own custom Linux system, entirely from source code.
https://www.linuxfromscratch.org/lfs/downloads/stable/LFS-BOOK-11.3-NOCHUNKS.html
https://www.linuxfromscratch.org/hints/downloads/files/boot-cd_easy.txt
https://www.linuxfromscratch.org/lfs/downloads/stable/wget-list
List of the required downloads for LFS 11.3
initramfs with static program
https://www.kernel.org/doc/html/latest/filesystems/ramfs-rootfs-initramfs.html#contents-of-initramfs
A good first step is to get initramfs to run a statically linked "hello world" program as init
1 sudo apt install qemu-system genisoimage
2
3 cd /tmp
4 wget https://saimei.ftp.acc.umu.se/debian-cd/current/amd64/iso-cd/debian-12.1.0-amd64-netinst.iso
5 sudo mount -o loop /vagrant/debian-12.1.0-amd64-netinst.iso /mnt/iso
6
7 # reuse isolinux from debian iso
8 mkdir /tmp/debiancd
9 mkdir /tmp/debiancd/isolinux
10 mkdir /tmp/debiancd/install.amd
11 cd /mnt/iso
12 cp isolinux/isolinux.cfg isolinux/*c32 isolinux/menu.cfg isolinux/txt.cfg /tmp/debiancd/isolinux
13 cp install.amd/initrd.gz install.amd/vmlinuz /tmp/debiancd/install.amd/
14 cp /mnt/iso/isolinux/isolinux.bin /tmp/debiancd/isolinux/
15
16 # isolinux.cfg
17 cat > debiancd/isolinux/isolinux.cfg << EOF
18 default bootcd
19 prompt 1
20 timeout 40
21
22 label bootcd
23 kernel /install.amd/vmlinuz
24 append initrd=/install.amd/test.cpio.gz vga=788
25 EOF
26
27 # hello.c
28 cat > hello.c << EOF
29 #include <stdio.h>
30 #include <unistd.h>
31
32 int main(int argc, char *argv[])
33 {
34 printf("Hello world!\n");
35 sleep(999999999);
36 }
37 EOF
38 gcc -static hello.c -o init
39
40 # build cpio initramfs
41 echo init | cpio -o -H newc | gzip > test.cpio.gz
42 cp test.cpio.gz debiancd/install.amd/test.cpio.gz
43
44 cd /tmp/
45 mkisofs -o /tmp/output.iso -R -l -L -D -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -V "LFS_$(date +%Y%m%d)" /tmp/debiancd/
46 rm /vagrant/output.iso
47 cp output.iso /vagrant
48
49 # the output.iso can be launched in VirtualBox booting the iso in a VM Other Linux, Linux 64 bit
50
51 # test with qemu
52 qemu-system-x86_64 -kernel debiancd/install.amd/vmlinuz -initrd test.cpio.gz /dev/zero
53 # test with qemu with kernel in debian system
54 qemu-system-x86_64 -kernel /boot/vmlinuz-5.10.0-22-amd64 -initrd test.cpio.gz /dev/zero