Skip to content

Commit

Permalink
Imported rest of the build from Musl-LFS... including updating the ke…
Browse files Browse the repository at this point in the history
…rnel build with LLVM.
  • Loading branch information
dslm4515 committed Apr 22, 2021
1 parent 5d0bdae commit c5346ac
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 3-chroot/095-clean-up
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Clean up of final system

# While in chroot...
rm -rvf /tmp/*
exit

# Re-enter chroot:
export CMLFS=/mnt/cmlfs

chroot "$CMLFS" /usr/bin/env -i \
HOME=/root TERM="$TERM" \
PS1='(cmlfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
/bin/bash --login

# Now remove unecessary files:
rm -fv /usr/lib/lib{bfd,opcodes}.a
rm -fv /usr/lib/libbz2.a
rm -fv /usr/lib/lib{com_err,e2p,ext2fs,ss}.a
rm -fv /usr/lib/libltdl.a
rm -fv /usr/lib/libfl.a
rm -fv /usr/lib/libz.a
find /usr/lib /usr/libexec -name \*.la -delete

# It is also safe to remove /llvmtools and /cross-tools directories as they're not required anymore
59 changes: 59 additions & 0 deletions 3-chroot/097-network-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
### General Network Configuration
### This section is done in Chroot environment
### May skip if no networking is needed


# Create Network Interface Configuration File(s)

# For a wifi card:
# Requires wpa_supplicant and dhcpcd
cat > /etc/sysconfig/ifconfig.wlan0 << "EOF"
ONBOOT="yes"
IFACE="wlan0"
SERVICE="wpa"

WPA_ARGS=""

WPA_SERVICE="dhcpcd"
DHCP_START="-b -q"
DHCP_STOP="-k"
EOF

# For a ethernet card with static ip address:
cat > /etc/sysconfig/ifconfig.eth0 << "EOF"
ONBOOT=yes
IFACE=eth0
SERVICE=ipv4-static
IP=192.168.1.2
GATEWAY=192.168.1.1
PREFIX=24
BROADCAST=192.168.1.255
EOF

# Creating the /etc/resolv.conf File
cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf

#domain <Your Domain Name>
#nameserver <IP address of your primary nameserver>
#nameserver <IP address of your secondary nameserver>

# End /etc/resolv.conf
EOF

# Set the hostname
# in this eample, 'mlfs':
ln -v /etc/s6/env/HOSTNAME /etc/hostname
echo "cmlfs" > /etc/hostname

# Create the /etc/hosts file
cat > /etc/hosts << "EOF"
# Begin /etc/hosts

127.0.0.1 localhost localhost.localdomain cmlfs.localdomain cmlfs
::1 localhost localhost.localdomain cmlfs.localdomain cmlfs
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

# End /etc/hosts
EOF
29 changes: 29 additions & 0 deletions 3-chroot/099-fstab
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Final System: Fstab
# This section is done in Chroot environment

# The /etc/fstab file is used by some programs to determine where file systems
# are to be mounted by default, in which order, and which must be checked (for
# integrity errors) prior to mounting. Create a new file systems table like thisi and modify accordingly:

cat > /etc/fstab << "EOF"
# Begin /etc/fstab

# file system mount-point type options dump fsck
# order

/dev/<xxx> / <fff> defaults 1 1
/dev/<yyy> swap swap pri=1 0 0
none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0
# S6 boot mounts these at startup
#proc /proc proc nosuid,noexec,nodev 0 0
#sysfs /sys sysfs nosuid,noexec,nodev 0 0
#devpts /dev/pts devpts gid=5,mode=620 0 0
#tmpfs /run tmpfs defaults 0 0
#devtmpfs /dev devtmpfs mode=0755,nosuid 0 0

# On a EFI system, may need to mount the EFI parition
#/dev/sda1 /mnt/uefi vfat defaults 0 0
#/mnt/uefi/EFI /boot/efi none defaults,bind 0 0

# End /etc/fstab
EOF
31 changes: 31 additions & 0 deletions 3-chroot/100-kernel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Final System: Linux Kernel
# Source: https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.2.11.tar.xz
# This section is done in Chroot environment

# Prepare for compilation by running the following command:
make mrproper

# Configure kernel:
LLVM=1 LLVM_IAS=1 make menuconfig

# Compile the kernel image and modules:
LLVM=1 LLVM_IAS=1 make

# Install the modules, if the kernel configuration uses them:
LLVM=1 LLVM_IAS=1 make modules_install

# Install the kernel:
cp -iv arch/x86/boot/bzImage /boot/vmlinuz

# Install the symbol file for the kernel:
cp -iv System.map /boot/System.map

# Install the kernel configuration file .config produced by the make menuconfig:
cp -iv .config /boot/config

# Then create the initramfs image required by bootscripts
# Use the name of the kernel, which can be found in /lib/modules:
# i.e. /lib/modules/5.2.11
mkinitramfs <kernel name>
# i.e. mkinitramfs 5.2.11
cp -va initrd.img-<kernel name> /boot/initrd.img
61 changes: 61 additions & 0 deletions 3-chroot/101-boot-loader
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Final System: Bootloader Setup
# This section is done in Chroot environment


########################### If using GRUB as boot loader: ######################################

# **** The following command will overwrite the current *****
# **** boot loader. Do not run the command if this is not ***
# **** desired, for example, if using a third party boot ****
# **** manager to manage the Master Boot Record (MBR). ******
# Example assumes CMLFS is on /dev/sda2
grub-install /dev/sda

# OR install bootloader on a bootable partition
grub-install /dev/sda1

# Create the GRUB Configuration File:
# Example assumes MLFS is on /dev/sda2

cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5

insmod ext2
set root=(hd0,2)

menuentry "GNU/Linux, Clang-Musl Linux" {
linux /boot/vmlinuz root=/dev/sda2 ro
initrd initrd.img
}
EOF

########################## If using rEFInd for UEFI systems: ##################################

# You may need to unpack package under host and repackage it as a .xz, .tar, or .bz2
#
# Check http://www.rodsbooks.com/refind/ for more specific info on your target hardware
#
# Prebuilt binaries will be installed here. Building from source requires:
# * The TianoCore EDK2/UDK package (https://github.com/tianocore/edk2)
# or
# * The GNU-EFI package (http://sourceforge.net/projects/gnu-efi/)

# Mount the efi partition
# For example, if efi partition is /dev/sda1:
mkdir -pv /mnt/efi
mount -v /dev/sda1 /mnt/efi

# Create required directories:
mkdir -pv /mnt/efi/EFI/BOOT

# Install rEFInd:
cp -v refind/refind_x64.efi /mnt/efi/EFI/BOOT/
cp -vr refind/icons /mnt/efi/EFI/BOOT/
cp -vr refind/drivers_x64 /mnt/efi/EFI/BOOT/
cp -vr refind/tools_x64 /mnt/efi/EFI/BOOT/
cp -vr refind/refind.conf-sample /mnt/efi/EFI/BOOT/refind.conf

########################## For ARM ##########################
Depending on target, boot loader may be u-boot.
32 changes: 32 additions & 0 deletions 3-chroot/102-The-End
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# The End

# It may be a good idea to create an /etc/lfs-release file. By having this
# file, it is very easy for you (and for us if you need to ask for help at
# some point) to find out which LFS version is installed on the system.
# Create this file by running:
echo 1.0 > /etc/cmlfs-release

# It is also a good idea to create a file to show the status of your new
# system with respect to the Linux Standards Base (LSB). To create this file, run:
cat > /etc/lsb-release << "EOF"
DISTRIB_ID="Clang Musl Linux From Scratch"
DISTRIB_RELEASE="1.0"
DISTRIB_CODENAME="<your name here>"
DISTRIB_DESCRIPTION="Clang Musl Linux From Scratch"
EOF

## Rebooting the System

# Exit chroot and unmount CMLFS
logout
umount -v $CMLFS/dev/pts
umount -v $CMLFS/dev
umount -v $CMLFS/run
umount -v $CMLFS/proc
umount -v $CMLFS/sys

# Unmount if CMLFS is on a seperate partition or HDD/SDD/device
umount -v $CMLFS

# You may reboot your machine [if host and target are the same]

0 comments on commit c5346ac

Please sign in to comment.