Create Linux Distribution(LFS)
LFS stand for linux from scratch, means to create your own distribution, but it is not meant to be used as everyday work distro, but rather as a project to learn how linux works, and how all of its components fits togetter to shape a complete system. note this is not the extesive version of LFS, to download and compile all program and kernel from scratch, but rather just my simple version of it.
first we need a disk image, if you have real disk that's fine too:
dd if=/dev/zero of=lfs.img bs=1M count=1024
then we need to partition, format and mount it. first put dos label, and create one partition on it.
fdisk lfs.img
create loop back device
doas losetup --find --show -P lfs.img
this command will print the loop device used, we will assume it is loop0
create a file system on the partition:
doas mkfs.ext4 /dev/loop0p1
then mount it:
doas mount /dev/loop0p1 /mnt
now we need at least a kernel, and initramfs to get our shell, on boot. we will use existing kernel, and initramfs in our system. let's do that:
doas mkdir -p /mnt/boot
doas cp -v /boot/{vmlinuz-linux, initramfs-linux.img} /mnt/boot
finally let's make our system bootable, using grub.
doas grub-install --target=x86_64-pc --boot-directory=/mnt/boot /dev/loop0
now let's provide, a configuration for our grub.
cat <EOF >/mnt/boot/grub/menu.lst
timeout 1
default 1
title LFS
kernel /boot/vmlinuz-linux
initrd /boot/initramfs-linux.img
EOF
doas grub-menulst2cfg /mnt/boot/grub/menu.lst /mnt/boot/grub/grub.cfg
run sync to make sure everything is written.
sync
finally let's boot it up.
qemu /dev/loop0 # or qemu lfs.img