Skip to content

ArthurWuTW/linuxfromscratch

Repository files navigation

Linux From Scratch in QEMU

This project provides steps and scripts to build your own linux system in virtual machine envionment. The instruction we follow is Linux From Scratch verion 11.3 (https://www.linuxfromscratch.org/index.html)

Prerequisites

Host OS: RockyLinux 8 or other Linux distributions
Virtual Machine Environment: QEMU
Alt text

Virtual Machine Setup

  • Virtaul Disk 1: Install Virtual Machine Host OS Alt text
  • Virtual Disk 2: Install Linux From Scratch(LFS) Alt text

Install Virtual Machine Host OS

  1. Install RockyLiunx 8 OS in Virtual Disk 1(sda) by default Linux partition settings Alt text
  2. prepare LFS partition
lsblk
## sdb      8:16    0    70G   0 disk

fdisk /dev/sdb
## create three partitions sdb1(512M), sdb2(1G), sdb3(68.5G) by command (ref: https://linux.die.net/man/8/gdisk). Note that sdb2 needs to change type "Linux swap / Solaris"(hex code=82)
## sdb1: /boot partition
## sdb2: swap
## sdb3: / partition

lsblk
## sdb1      8:16    0    512M    0 part
## sdb2      8:16    0    1G      0 part
## sdb3      8:16    0    68.5G   0 part
  1. format partitions
mkfs -v -t ext4 /dev/sdb1
mkswap /dev/sdb2
mkfs -v -t ext4 /dev/sdb3

Install Linux From Scratch(LFS)

./run.sh

cd pkg_compile_cross_toolchain_script && ./install_all.sh

cd pkg_cross_compiling_temporary_tools_script && ./lfs_user_install_all.sh

cd pkg_chroot_tools && cat README ## following README

Setup QEMU Boot Order

Alt text

TO-DO List

  • Install sshd
cd /opt
./chroot_install_openssh.sh
vi /etc/ssh/sshd_config
## Set root login config
## === modify this line ===
PermitRootLogin yes
  • Install wget

  • Install netstat

  • Install Gnome

Troubleshooting

pinging google.com hangs

  1. Observe infrastructure from QEMU Environment Alt text
  2. Modify ifconfig.eth0 Alt text
  3. Infra after modification Alt text
  4. ping google.com again Alt text

Grub failed, cannot find vmlinuz-6.1.11-lfs-11.3

  1. press c
    Alt text
  2. type cd (hd and press tab, and you will see disks and partitions recognized by grub Alt text
  3. setup root path in /boot/grub/grub.cfg file, in this case, root path is (hd0, msdos1)
set root=(hd0, msdos1)

VFS: Unable to mount root fs

Alt text

  1. Disk2 partitions were SOMETIMES recognized as /dev/sdc1, /dev/sdc2, and /dev/sdc3, but we expect /dev/sdb1~3, so if we configure grub.cfg like /dev/sdbX, it will casue this error.
  2. It is highly recommanded to specify partitions by PARTUUID, command below shows partition PARTUUID information.
blkid
# /dev/sdb3: UUID="17b539e0-9a73-482c-ba8b-70e3353ba187" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="b4d939e3-03"
  1. specify root=PARTUUID=XXXX
vi /boot/grub/grub.cfg
# set default=0
# set timeout=5
#
# insmod ext2
# set root=(hd0,msdos1)
#
# menuentry "GNU/Linux, Linux 6.1.11-lfs-11.3" {
#         linux   /vmlinuz-6.1.11-lfs-11.3 root=PARTUUID=b4d939e3-03 ro
# }
  1. LFS boots successfully

Alt text

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages