IV ‐ System Configuration - Nimpoo/ft_linux GitHub Wiki

Introduction

Link to of where I am in the process - IV. Building the LFS System - 9. System Configuration

Here, we setup some configuration files like networking, hostname, etc... and systemd services. If you don't, do a backup of your system for more security : Backup Guide.

This chapter is not really long but important, so take your time to read it and understand what you are doing.

And you're supposed to be in the chroot environment again.

1 - General Network Configuration

If you want internet access, it's the right place to configure it. If you don't, you can skip this section.

1.1 - - Static IP Configuration

If you want to configure a static IP address, you can do it by creating the file /etc/systemd/network/10-eth-static.network (or enp0s3, ens33, ens3, etc... depending on your network interface name) with the following content:

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

[Network]
Address=192.168.0.2/24
Gateway=192.168.0.1
DNS=192.168.0.1
Domains=whateveryouwant.com
EOF

Why ens3 ? You can find your network interface name with the command ip link. It can be enp0s3, ens33, ens3, etc... depending on your system. Replace ens3 with your network interface name.

1.2 - DHCP Configuration

If you want to configure a DHCP client, you can create the file /etc/systemd/network/10-eth-dhcp.network (or enp0s3, ens33, ens3, etc... depending on your network interface name) with the following content:

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

[Network]
DHCP=ipv4

[DHCPv4]
UseDomains=true
EOF

1.3 - Static resolv.conf Configuration

This file is used to resolve domain names to IP addresses. You can create it with the following content:

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

domain whateveryouwant.com
nameserver 8.8.8.8
nameserver 8.8.4.4

# End /etc/resolv.conf
EOF

Why I need to enter 2 IP addresses of a nameserver ? This is to ensure that if one of the nameservers is down, the other one can still resolve domain names. You can use any public DNS server, like Google's 8.8.8.8 (primary) and 8.8.4.4 (secondary) (2001:4860:4860::8888 and 2001:4860:4860::8844 for IPv6).

1.4 - Configuring the system hostname

During the boot process, the file /etc/hostname is used for establishing the system's hostname.

echo "<lfs>" > /etc/hostname

1.5 - Customizing the /etc/hosts File

The /etc/hosts file is used to resolve hostnames to IP addresses. You can customize it with the following content:

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

127.0.0.1  localhost lfs
::1        localhost

::1       ip6-localhost ip6-loopback
ff02::1   ip6-allnodes
ff02::2   ip6-allrouters

# End /etc/hosts
EOF

Interlude

If you want to know how udev works and how it manages device nodes and events in the Linux system, you can refer to the LFS book: Linux From Scratch - Version r12.3-95-systemd Chapter 9. System Configuration

The next section is about video and webcam devices, and I don't treat it here, again you have the LFS book for that.

2 - Other Configuration Files

Almost done with the configuration files, only few left to do like clock, linux console, local, etc...

2.1 - Configuring the System Clock

(This part can be skipped if you don't care about the system clock, but it's recommended to do it)

Create the file /etc/adjtime with the following content:

cat > /etc/adjtime << "EOF"
0.0 0 0.0
0
LOCAL
EOF

You can also use the timedatectl utility to tell systemd-timedated if your hardware clock is set to UTC or local time:

timedatectl set-local-rtc 1

To change your current system time:

timedatectl set-time YYYY-MM-DD HH:MM:SS

The hardware clock will also be updated accordingly.

To change your timezone:

timedatectl set-timezone TIMEZONE

You can list them with:

timedatectl list-timezones

2.2 - Configuring the Linux Console and Keymap

To set a font as the default console font, you can create the file /etc/vconsole.conf with the following content:

echo FONT=Lat2-Terminus16 > /etc/vconsole.conf

Lat2-Terminus is an example.

For change your KEYMAP:

localectl set-keymap MAP

It will open a list of available keymaps, choose yours.

2.3 - Configuring the System Locale

All commands using localectl require to be run directly in the LFS system, not in the chroot environment, it won't work otherwise.

The list of all locales supported by Glibc can be obtained by running the following command:

locale -a

Replace the 2 first letters with your language and the 2 last letters with your country code, for example en_US.UTF-8 for English (United States) or fr_FR.UTF-8 for French (France). After choosing your locale, you can create the file /etc/locale.conf with the following content:

LC_ALL=en_US.UTF-8 locale charmap

It is important that the locale found using the heuristic above is tested prior to it being added to the Bash startup files:

LC_ALL=<locale name> locale language
LC_ALL=<locale name> locale charmap
LC_ALL=<locale name> locale int_curr_symbol
LC_ALL=<locale name> locale int_prefix

Create the /etc/locale.conf file with the following content:

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

Create the /etc/profile to read the locale settings from /etc/locale.conf and export them, but set the C.UTF-8 locale instead if running in the Linux console (to prevent programs from outputting characters that the Linux console is unable to render):

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

for i in $(locale); do
  unset ${i%=*}
done

if [[ "$TERM" = linux ]]; then
  export LANG=C.UTF-8
else
  source /etc/locale.conf

  for i in $(locale); do
    key=${i%=*}
    if [[ -v $key ]]; then
      export $key
    fi
  done
fi

# End /etc/profile
EOF

Note that you can modify /etc/locale.conf with the systemd localectl utility. To use localectl for the example above, run:

localectl set-locale LANG=en_US.UTF-8

2.4 - Creating the /etc/inputrc File

The /etc/inputrc file is used to configure the behavior of the GNU Readline library, which is used by many command-line applications, for more information about it, you can refer to the LFS book : Linux From Scratch - Version r12.3-95-systemd Chapter 9. System Configuration.

To create the /etc/inputrc file, you can use the following command:

cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc
# Modified by Chris Lynn <[email protected]>

# 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

2.5 - Creating the /etc/shells File

Again, refer to the LFS book : Linux From Scratch - Version r12.3-95-systemd Chapter 9. System Configuration.

To create the /etc/shells file, you can use the following command:

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

/bin/sh
/bin/bash

# End /etc/shells
EOF

2.6 - Systemd Usage and Configuration

The normal behavior for systemd is to clear the screen at the end of the boot sequence. If desired, this behavior may be changed by running the following command:

mkdir -pv /etc/systemd/system/[email protected]

cat > /etc/systemd/system/[email protected]/noclear.conf << EOF
[Service]
TTYVTDisallocate=no
EOF

By default, some things are set. If you want to change these parameters, refer to the LFS book : Linux From Scratch - Version r12.3-95-systemd Chapter 9. System Configuration.


Now, it's time to make the system bootable, by built and configuring grub2 and the Linux kernel.

⚠️ **GitHub.com Fallback** ⚠️