linux_dist
Markdown

Part 08 System Configuration

Part 8: System Configuration

Overview

Configure your LFS system for proper operation including network, boot scripts, and system settings.

Prerequisites

  • Completed Part 7 (full system build)
  • Still inside chroot
  • Working as root

1. Network Configuration

Create /etc/hosts

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

127.0.0.1 localhost.localdomain localhost
127.0.1.1 <HOSTNAME>.localdomain <HOSTNAME>
::1       localhost ip6-localhost ip6-loopback
ff02::1   ip6-allnodes
ff02::2   ip6-allrouters

# End /etc/hosts
EOF

Replace <HOSTNAME> with your desired hostname.

Configure Network Interface

For static IP:

cd /etc/sysconfig/
cat > 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

For DHCP:

cat > /etc/sysconfig/ifconfig.eth0 << "EOF"
ONBOOT=yes
IFACE=eth0
SERVICE=ipv4-dhcp
EOF

Create resolv.conf

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

domain <Your Domain Name>
nameserver 8.8.8.8
nameserver 8.8.4.4

# End /etc/resolv.conf
EOF

Set Hostname

echo "<lfs>" > /etc/hostname

Replace <lfs> with your desired hostname.

2. System Locale Configuration

cat > /etc/locale.conf << "EOF"
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
EOF

3. Configure /etc/inputrc

cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc
# Modified by Chris Lynn <roryo@roryo.dynup.net>

# Allow the command prompt to wrap to the next line
set horizontal-scroll-mode Off

# Enable 8-bit input
set meta-flag On
set input-meta On

# Turns off 8th bit stripping
set convert-meta Off

# Keep the 8th bit for display
set output-meta On

# none, visible or audible
set bell-style none

# All of the following map the escape sequence of the value
# contained in the 1st argument to the readline specific functions
"\eOd": backward-word
"\eOc": forward-word

# for linux console
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert

# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# for Konsole
"\e[H": beginning-of-line
"\e[F": end-of-line

# End /etc/inputrc
EOF

4. Create /etc/shells

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

/bin/sh
/bin/bash

# End /etc/shells
EOF

5. Install LFS-Bootscripts

cd /sources
tar -xf lfs-bootscripts-20250827.tar.xz
cd lfs-bootscripts-20250827

make install

cd /sources
rm -rf lfs-bootscripts-20250827

6. Configure System Clock

cat > /etc/sysconfig/clock << "EOF"
# Begin /etc/sysconfig/clock

UTC=1

# Set this to any options you might need to give to hwclock,
# such as machine hardware clock type for Alphas.
CLOCKPARAMS=

# End /etc/sysconfig/clock
EOF

Note: Set UTC=1 if hardware clock is set to UTC, or UTC=0 for local time.

7. Configure Linux Console

cat > /etc/sysconfig/console << "EOF"
# Begin /etc/sysconfig/console

UNICODE="1"
KEYMAP="us"
FONT="lat1-16 -m 8859-1"

# End /etc/sysconfig/console
EOF

Change KEYMAP for your keyboard layout (e.g., "de" for German).

8. Create /etc/profile

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

export LANG=en_US.UTF-8
export PATH=/usr/bin:/usr/sbin

if [ -d /etc/profile.d ]; then
  for script in /etc/profile.d/*.sh; do
    if [ -r $script ]; then
      . $script
    fi
  done
  unset script
fi

# Setup some environment variables.
export HISTSIZE=1000
export HISTIGNORE="&:[bf]g:exit"

# Set some defaults for graphical systems
export XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/share/}
export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg/}
export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp/xdg-$USER}

# Setup a red prompt for root and a green one for users.
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
  PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
  PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi

unset RED GREEN NORMAL

# End /etc/profile
EOF

mkdir -pv /etc/profile.d

9. Set Root Password

passwd root

Enter a secure password when prompted.

10. Create /etc/fstab

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
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
tmpfs          /dev/shm     tmpfs    nosuid,nodev        0     0
cgroup2        /sys/fs/cgroup cgroup2 nosuid,noexec,nodev 0   0

# End /etc/fstab
EOF

Important: Replace:

  • <xxx> with your root partition (e.g., /dev/sda2)
  • <fff> with your filesystem type (e.g., ext4)
  • <yyy> with your swap partition (e.g., /dev/sda3)

Example:

/dev/sda2      /            ext4     defaults            1     1
/dev/sda3      swap         swap     pri=1               0     0

11. Configure Systemd (if using Systemd)

Set Timezone

ln -sfv /usr/share/zoneinfo/<xxx> /etc/localtime

Replace <xxx> with your timezone (e.g., America/New_York, Europe/London).

Configure systemd-networkd

cat > /etc/systemd/network/10-eth0.network << "EOF"
[Match]
Name=eth0

[Network]
DHCP=yes
EOF

Or for static IP:

cat > /etc/systemd/network/10-eth0.network << "EOF"
[Match]
Name=eth0

[Network]
Address=192.168.1.2/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=8.8.4.4
EOF

Enable Services

systemctl preset-all
systemctl disable systemd-time-wait-sync.service

12. Configure SysVinit (if using SysVinit)

Set System Runlevel

Default runlevel is already set by boot scripts.

Check with:

cat /etc/inittab | grep "^id:"

Should show id:3:initdefault: for multi-user text mode.

13. Disable Screen Clearing at Boot

mkdir -pv /etc/systemd/system/getty@tty1.service.d

cat > /etc/systemd/system/getty@tty1.service.d/noclear.conf << EOF
[Service]
TTYVTDisallocate=no
EOF

14. Create /etc/lsb-release

cat > /etc/lsb-release << "EOF"
DISTRIB_ID="Linux From Scratch"
DISTRIB_RELEASE="12.4"
DISTRIB_CODENAME="LFS-12.4"
DISTRIB_DESCRIPTION="Linux From Scratch"
EOF

15. Create /etc/os-release

cat > /etc/os-release << "EOF"
NAME="Linux From Scratch"
VERSION="12.4"
ID=lfs
PRETTY_NAME="Linux From Scratch 12.4"
VERSION_CODENAME="LFS-12.4"
HOME_URL="https://www.linuxfromscratch.org/lfs/"
EOF

16. System Information Summary

cat > /etc/issue << "EOF"
Linux From Scratch 12.4 \n \l

EOF

17. Final Configuration Check

Verify all critical files exist:

# Check essential files
ls -l /etc/fstab
ls -l /etc/hostname
ls -l /etc/hosts
ls -l /etc/passwd
ls -l /etc/group
ls -l /etc/profile

# Verify root password is set
passwd -S root
# Should show: "root P ..." (P means password set)

18. Set Timezone (Alternative Method)

# List available timezones
ls /usr/share/zoneinfo/

# Set your timezone
ln -sfv /usr/share/zoneinfo/America/New_York /etc/localtime

Common timezones:

  • America/New_York
  • America/Los_Angeles
  • Europe/London
  • Europe/Paris
  • Asia/Tokyo
  • Australia/Sydney

19. Configure Keyboard Layout (Persistent)

# For US keyboard (default)
cat > /etc/vconsole.conf << "EOF"
KEYMAP=us
EOF

# For German keyboard
cat > /etc/vconsole.conf << "EOF"
KEYMAP=de-latin1
EOF

Next Steps

System configuration complete! Proceed to:

  • Part 9: Build and install Linux kernel + bootloader
  • Part 10: Final testing and first boot

Important Notes

  • Double-check /etc/fstab entries
  • Ensure root password is set
  • Verify network configuration matches your setup
  • Backup configuration files

Verification Checklist

# Verify critical configurations
[ -f /etc/fstab ] && echo "fstab: OK" || echo "fstab: MISSING!"
[ -f /etc/hostname ] && echo "hostname: OK" || echo "hostname: MISSING!"
[ -f /etc/hosts ] && echo "hosts: OK" || echo "hosts: MISSING!"
[ -f /etc/passwd ] && echo "passwd: OK" || echo "passwd: MISSING!"
[ -f /etc/group ] && echo "group: OK" || echo "group: MISSING!"
passwd -S root | grep -q " P " && echo "root password: SET" || echo "root password: NOT SET!"