Skip to content

通过知识获得解放,通过技术获得自由

Menu
  • 专题目录
  • 液压相关
    • 液压技术
    • 液压相邻技术
    • 液压应用
  • 计算机相关
    • 计算机和软件
    • 网络和网站技术
  • 哲学
  • 关于本站
Menu

LFS系统配置[0]

Posted on 2023年11月14日 by

本部分时LFS说的非常不清楚的部分,书中的实战的指导也非常差,也没有给出模板。

而且按照实际部署的过程看,原书对于可能不需要运行的代码未给出说明。

本篇包含原书第9-11章内容

本篇是用于配置LFS的配置(包括LFS启动后用到的配置+linux内核的编译)。

主要还是在chroot环境中配置,除了grub需要host环境以root运行。

  • 重启进入chroot环境
#挂载分区
mount /dev/sda2 /mnt/lfs
export LFS=/mnt/lfs
以下代码可以是脚本readForLFS.sh

#映射
mount -v --bind /dev $LFS/dev
mount -v --bind /dev/pts $LFS/dev/pts
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run
if [ -h $LFS/dev/shm ]; then
  mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi
#进入chroot
chroot "$LFS" /usr/bin/env -i          \
    HOME=/root TERM="$TERM"            \
    PS1='(lfs chroot) \u:\w\$ '        \
    PATH=/usr/bin:/usr/sbin            \
    /bin/bash --login
  • LFS配置

1)创建网络设备并配置dhcp

ln -s /dev/null /etc/systemd/network/99-default.link

ifconfig

cat > /etc/systemd/network/10-ether0.link << "EOF"
[Match]
# Change the MAC address as appropriate for your network device
MACAddress=00:0C:29:0A:AC:C9
[Link]
Name=ether0
EOF

cat > /etc/systemd/network/10-eth-dhcp.network << "EOF"
[Match]
Name=ens33
[Network]
DHCP=ipv4
[DHCP]
UseDomains=true
EOF

2)DNS

ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf

3)hostname

echo "<lfs>" > /etc/hostname

cat > /etc/hosts << "EOF"
# Begin /etc/hosts
127.0.0.1 localhost.localdomain localhost
# End /etc/hosts
EOF

4)时间问题

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

timedatectl set-local-rtc 1

6)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 8bit 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

7)创建 /etc/shells 文件

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

/bin/sh
/bin/bash

# End /etc/shells
EOF

8)禁用引导时自动清屏

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

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

9)覆盖系统服务默认行为

mkdir -pv /etc/systemd/system/foobar.service.d
cat > /etc/systemd/system/foobar.service.d/foobar.conf << EOF
[Service]
Restart=always
RestartSec=30
EOF

10)处理dump

mkdir -pv /etc/systemd/coredump.conf.d
cat > /etc/systemd/coredump.conf.d/maxuse.conf << EOF
[Coredump]
MaxUse=5G
EOF

 

  • 安装内核(实际此处编译了两次)
tar xvf linux-5.13.12.tar.xz
cd linux-5.13.12
make mrproper
make defconfig
make menuconfig
make -j4
make modules_install
cp -iv arch/x86/boot/bzImage /boot/vmlinuz-5.13.12-lfs-11.0-systemd
cp -iv System.map /boot/System.map-5.13.12
cp -iv .config /boot/config-5.13.12
install -d /usr/share/doc/linux-5.13.12
cp -r Documentation/* /usr/share/doc/linux-5.13.12

install -v -m755 -d /etc/modprobe.d
cat > /etc/modprobe.d/usb.conf << "EOF"
# Begin /etc/modprobe.d/usb.conf
install ohci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i ohci_hcd ; true
install uhci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i uhci_hcd ; true
# End /etc/modprobe.d/usb.conf
EOF

cd ..
rm -rf linux-5.13.12

对于在vmware下测试需要额外选择编译以下部分

  • 创建引导(此处非常容易出错)

由于在vmware下通过ubuntu实现的host,准备在编译好lfs不再保留host系统(ubuntu),因此不需重新安装grub

本处运行在host下以root运行以下的代码

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, Linux 5.13.12-lfs-11.0-systemd" {
        linux   /boot/vmlinuz-5.13.12-lfs-11.0-systemd root=/dev/sda2 ro
}
EOF

nano /etc/fstab
修改如下:
/swapfile none swap sw 0 0
/dev/sda2 / ext4 defaults 1 1
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

补充在chroot环境下的目录结构

  • 收尾(chroot环境中配置)
echo 11.0-systemd > /etc/lfs-release

cat > /etc/lsb-release << "EOF"
DISTRIB_ID="Linux From Scratch"
DISTRIB_RELEASE="11.0-systemd"
DISTRIB_CODENAME="<your name here>"
DISTRIB_DESCRIPTION="Linux From Scratch"
EOF

cat > /etc/os-release << "EOF"
NAME="Linux From Scratch"
VERSION="11.0-systemd"
ID=lfs
PRETTY_NAME="Linux From Scratch 11.0-systemd"
VERSION_CODENAME="<your name here>"
EOF

解除chroot挂载

exit #退出chroot环境进入host
umount -Rv $LFS
  • 重启系统和效果检测(host环境中重启)
exit #退出chroot环境

测试通过

 

补充说明

1)典型的失败情况,vfs无法挂载

 

参考资料:

  1. https://www.jianshu.com/p/2201d0367588
  2. https://blog.51cto.com/deidara/99930
  3. https://blog.csdn.net/serika00/article/details/43032529
  4. https://www.linuxquestions.org/questions/linux-from-scratch-13/kernel-panic-device-not-found-4175677832/
  5. https://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/issue-on-boot-for-lfs-system-vfs-cannot-open-root-device-null-or-unknown-block-0-0-error-6-a-4175610572/
  6. https://www.linuxquestions.org/questions/linux-from-scratch-13/lfs-7-5-kernel-panic-error-unable-to-mount-rootfs-4175506219/
  7. https://blog.csdn.net/jiangwei0512/article/details/78172642

欢迎回来

希望本站对你有所帮助!

如有疑问请联系info@fanlog.org
2023 年 11 月
一二三四五六日
 12345
6789101112
13141516171819
20212223242526
27282930 
« 6 月    

AI辅助 (17)

© 2025 | Powered by Superbs Personal Blog theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT