九. 系统配置

  1. 安装 LFS-Bootscripts-20150222

    软件包包含一套在 LFS 系统启动和关闭时的启动和停止脚本。

  1. cd /sources
  2. tar -jxf lfs-bootscripts-20150222.tar.bz2
  3. cd lfs-bootscripts-20150222
  4. make install
  5. cd /sources
  6. rm -rf lfs-bootscripts-20150222

  2. 管理网络设备

  1. # 运行以下命令,创建网络设备 Udev 规则
  2. bash /lib/udev/init-net-rules.sh
  3. # 查看生成的规则
    cat /etc/udev/rules.d/70-persistent-net.rules

  3. 配置系统主机名称

  1. echo "lfs" > /etc/hostname

  4. 创建 /etc/hosts  文件

  1. cat > /etc/hosts << "EOF"
  2. # Begin /etc/hosts (network card version)
  3.  
  4. 127.0.0.1 localhost
  5.  
  6. # End /etc/hosts (network card version)
  7. EOF

  5. 配置 Sysvinit

    内核初始化期间,第一个运行的程序默认是SysVinit,这个程序读取/etc/inittab文件

  1. cat > /etc/inittab << "EOF"
  2. # Begin /etc/inittab
  3.  
  4. id:3:initdefault:
  5.  
  6. si::sysinit:/etc/rc.d/init.d/rc S
  7.  
  8. l0:0:wait:/etc/rc.d/init.d/rc 0
  9. l1:S1:wait:/etc/rc.d/init.d/rc 1
  10. l2:2:wait:/etc/rc.d/init.d/rc 2
  11. l3:3:wait:/etc/rc.d/init.d/rc 3
  12. l4:4:wait:/etc/rc.d/init.d/rc 4
  13. l5:5:wait:/etc/rc.d/init.d/rc 5
  14. l6:6:wait:/etc/rc.d/init.d/rc 6
  15.  
  16. ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
  17.  
  18. su:S016:once:/sbin/sulogin
  19.  
  20. 1:2345:respawn:/sbin/agetty --noclear tty1 9600
  21. 2:2345:respawn:/sbin/agetty tty2 9600
  22. 3:2345:respawn:/sbin/agetty tty3 9600
  23. 4:2345:respawn:/sbin/agetty tty4 9600
  24. 5:2345:respawn:/sbin/agetty tty5 9600
  25. 6:2345:respawn:/sbin/agetty tty6 9600
  26.  
  27. # End /etc/inittab
  28. EOF

  6. 配置系统时钟

  1. cat > /etc/sysconfig/clock << "EOF"
  2. # Begin /etc/sysconfig/clock
  3.  
  4. UTC=1
  5.  
  6. # Set this to any options you might need to give to hwclock,
  7. # such as machine hardware clock type for Alphas.
  8. CLOCKPARAMS=
  9.  
  10. # End /etc/sysconfig/clock
  11. EOF

  7. Bash 启动文件

  1. cat > /etc/profile << "EOF"
  2. # Begin /etc/profile
  3.  
  4. export LANG=en_US.UTF-8
  5.  
  6. # End /etc/profile
  7. EOF

  8. 创建 /etc/inputrc 文件

    inputrc  文件的作用是告知系统应该以怎样的键盘布局处理键盘

  1. cat > /etc/inputrc << "EOF"
  2. # Begin /etc/inputrc
  3. # Modified by Chris Lynn <roryo@roryo.dynup.net>
  4.  
  5. # Allow the command prompt to wrap to the next line
  6. set horizontal-scroll-mode Off
  7.  
  8. # Enable 8bit input
  9. set meta-flag On
  10. set input-meta On
  11.  
  12. # Turns off 8th bit stripping
  13. set convert-meta Off
  14.  
  15. # Keep the 8th bit for display
  16. set output-meta On
  17.  
  18. # none, visible or audible
  19. set bell-style none
  20.  
  21. # All of the following map the escape sequence of the value
  22. # contained in the 1st argument to the readline specific functions
  23. "\eOd": backward-word
  24. "\eOc": forward-word
  25.  
  26. # for linux console
  27. "\e[1~": beginning-of-line
  28. "\e[4~": end-of-line
  29. "\e[5~": beginning-of-history
  30. "\e[6~": end-of-history
  31. "\e[3~": delete-char
  32. "\e[2~": quoted-insert
  33.  
  34. # for xterm
  35. "\eOH": beginning-of-line
  36. "\eOF": end-of-line
  37.  
  38. # for Konsole
  39. "\e[H": beginning-of-line
  40. "\e[F": end-of-line
  41.  
  42. # End /etc/inputrc
  43. EOF

  9. 创建 /etc/shells 文件

    shells 文件是当前系统所有可用 shell  的列表文件

  1. cat > /etc/shells << "EOF"
  2. # Begin /etc/shells
  3.  
  4. /bin/sh
  5. /bin/bash
  6.  
  7. # End /etc/shells
  8. EOF

  10. LFS官方文档中还包含了其它可选配置,可按需添加

十. 让 LFS 系统可引导

  1. 创建 /etc/fstab 文件

  1. cat > /etc/fstab << "EOF"
  2. # Begin /etc/fstab
  3. # file system mount-point type options dump fsck
  4. # order
  5. /dev/root / auto noatime,nodiratime 1 1
  6. #/dev/xxxx swap swap pri=1 0 0
  7.  
  8. # End /etc/fstab
  9. EOF

  2. 挂载 boot 分区

  1. mkdir /mnt/boot
  2. mount /dev/sdc1 /mnt/boot

  3. Linux-4.7.2

    a. 宿主系统下运行下列命令,查看有线、无线网卡型号

  1. lspci | grep -i ethernet
  2. lspci | grep -i wireless

    b. 根据型号选择合适的驱动,安装配置内核

  1. cd /sources
  2. tar -Jxf linux-4.7.2.tar.xz
  3. cd linux-4.7.2
  4.  
  5. make mrproper
  6. make menuconfig
  7. #新增
  8. #[*] Networking support --->
  9. #-*- Wireless --->
  10. #<*> cfg80211 - wireless configuration API
  11. #[*] cfg80211 wireless extensions compatibility
  12. # Device Drivers --->
  13. #[*] Network device support --->
  14. #[*] Ethernet driver support --->
  15. #[*] Atheros devices
  16. #<M> Qualcomm Atheros AR816X/AR817x support
  17. #[*] Wireless LAN --->
  18. #[*] Atheros/Qualcomm devices
  19. #<M> Atheros 802.11n wireless cards support
  20. #[*] Atheros ath9k PCI/PCIe bus support
  21. #<*> PPP (point-to-point protocol) support
  22. #<*> PPP support for async serial ports
  23.  
  24. make
  25. make modules_install
  26.  
  27. # 下面的命令假设主机是 x86 架构:
  28. cp -v arch/x86/boot/bzImage /mnt/boot/vmlinuz-4.7.2
  29.  
  30. cp -v System.map /mnt/boot/System.map-4.7.2
  31. cp -v .config /mnt/boot/config-4.7.2
  32. install -d /usr/share/doc/linux-4.7.2
  33. cp -r Documentation/* /usr/share/doc/linux-4.7.2
  34.  
  35. # 配置 Linux 模块加载顺序
  36. # 如果将 USB 设备(ehci_hcd、ohci_hcd 和 uhci_hcd) 编译为模块,则需要此文件。
  37. # 运行以下命令建立 /etc/modprobe.d/usb.conf 文件:
  38.  
  39. install -v -m755 -d /etc/modprobe.d
  40. cat > /etc/modprobe.d/usb.conf << "EOF"
  41. # Begin /etc/modprobe.d/usb.conf
  42.  
  43. install ohci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i ohci_hcd ; true
  44. install uhci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i uhci_hcd ; true
  45.  
  46. # End /etc/modprobe.d/usb.conf
  47. EOF
  48.  
  49. cd /sources
  50. rm -rf linux-4.7.2

  4. 创建 initrd.img 文件

    a. 点击此下载 mkinitramfs 相关文件,并放到LFS系统对应的位置

    b. mkinitramfs 命令依赖于 cpio 包,先安装

  1. cd /sources
  2. tar -jxf cpio-2.12.tar.bz2
  3. cd cpio-2.12
  4.  
  5. ./configure --prefix=/usr \
  6. --bindir=/bin \
  7. --enable-mt \
  8. --with-rmt=/usr/libexec/rmt &&
  9. make &&
  10. makeinfo --html -o doc/html doc/cpio.texi &&
  11. makeinfo --html --no-split -o doc/cpio.html doc/cpio.texi &&
  12. makeinfo --plaintext -o doc/cpio.txt doc/cpio.texi
  13.  
  14. make install &&
  15. install -v -m755 -d /usr/share/doc/cpio-2.12/html &&
  16. install -v -m644 doc/html/* \
  17. /usr/share/doc/cpio-2.12/html &&
  18. install -v -m644 doc/cpio.{html,txt} \
  19. /usr/share/doc/cpio-2.12
  20.  
  21. cd /sources
  22. rm -rf cpio-2.12

    c. 执行如下命令,重新生成 initrd

  1. cp /sbin/udevadm /bin/
  2.  
  3. chmod 777 /usr/sbin/mkinitramfs
    /usr/sbin/mkinitramfs --force

    d. 移动 initrd.img-4.7.2.xz 到 boot 分区下

  1. mv /boot/initrd.img-4.7.2.xz /mnt/boot/

  5. 用 GRUB 设置引导过程

  1. # 将GRUB文件安装到 /mnt/boot/grub,并修改MBR扇区
  2. grub-install --root-directory=/mnt /dev/sdc
  3.  
  4. # 创建GRUB配置文件
  5. cat > /mnt/boot/grub/grub.cfg << "EOF"
  6. # Begin /boot/grub/grub.cfg
  7. set default=0
  8. set timeout=5
  9.  
  10. menuentry "linux-4.7.2-lfs-7.10" {
  11. set kver=4.7.2
  12. set boot_uuid=<boot分区uuid>
  13. set root_uuid=<root分区uuid>
  14. search.fs_uuid ${boot_uuid} root
  15. linux /vmlinuz-${kver} root=uuid/${root_uuid}
  16. initrd /initrd.img-${kver}.xz
  17. }
  18. EOF

十一. 最后

  1. 创建 /etc/lfs-release 文件

  1. cat > /etc/lsb-release << "EOF"
  2. DISTRIB_ID="Linux From Scratch"
  3. DISTRIB_RELEASE="7.10"
  4. DISTRIB_CODENAME="kevin"
  5. DISTRIB_DESCRIPTION="Linux From Scratch"
  6. EOF

  2. 安装 OpenSSH

  1. # openssh依赖于openssl库,先安装openssl
  2. cd /sources
  3. tar -zxf openssl-1.0.2h.tar.gz
  4. cd openssl-1.0.2h
  5. ./config --prefix=/usr \
  6. --openssldir=/etc/ssl \
  7. --libdir=lib \
  8. shared \
  9. zlib-dynamic &&
  10. make depend &&
  11. make
  12. make MANDIR=/usr/share/man MANSUFFIX=ssl install &&
  13. install -dv -m755 /usr/share/doc/openssl-1.0.2h &&
  14. cp -vfr doc/* /usr/share/doc/openssl-1.0.2h
  15.  
  16. cd /sources
  17. rm -rf openssl-1.0.2h
  18.  
  19. # 安装openssh
  20. cd /sources
  21. tar -zxf openssh-7.3p1.tar.gz
  22. cd openssh-7.3p1
  23. install -v -m700 -d /var/lib/sshd &&
  24. chown -v root:sys /var/lib/sshd &&
  25.  
  26. groupadd -g 50 sshd &&
  27. useradd -c 'sshd PrivSep' \
  28. -d /var/lib/sshd \
  29. -g sshd \
  30. -s /bin/false \
  31. -u 50 sshd
  32. ./configure --prefix=/usr \
  33. --sysconfdir=/etc/ssh \
  34. --with-md5-passwords \
  35. --with-privsep-path=/var/lib/sshd &&
  36. make
  37. make install &&
  38. install -v -m755 contrib/ssh-copy-id /usr/bin &&
  39.  
  40. install -v -m644 contrib/ssh-copy-id.1 \
  41. /usr/share/man/man1 &&
  42. install -v -m755 -d /usr/share/doc/openssh-7.3p1 &&
  43. install -v -m644 INSTALL LICENCE OVERVIEW README* \
  44. /usr/share/doc/openssh-7.3p1
  45.  
  46. cd /sources
  47. rm -rf openssh-7.3p1
  48.  
  49. # 系统启动时开启ssh服务
  50. cd /sources
  51. tar -Jxf blfs-bootscripts-20160902.tar.xz
  52. cd blfs-bootscripts-20160902
  53. make install-sshd
  54. cd /sources
  55. rm -rf blfs-bootscripts-20160902

  3. 安装 dhcpcd

  1. cd /sources
  2. tar -Jxf dhcpcd-6.11.3.tar.xz
  3. cd dhcpcd-6.11.3
  4.  
  5. ./configure --libexecdir=/lib/dhcpcd \
  6. --dbdir=/var/lib/dhcpcd &&
  7. make
  8.  
  9. make install
  10. cd /sources
  11. rm -rf dhcpcd-6.11.3

  4. 安装 wpa_supplicant

  1. # wpa_supplicant依赖于libnl-3库,先安装libnl-3
  2. cd /sources
  3. tar -zxf libnl-3.2.28.tar.gz
  4. cd libnl-3.2.28
  5.  
  6. ./configure --prefix=/usr \
  7. --sysconfdir=/etc \
  8. --disable-static &&
  9. make
  10.  
  11. make install
  12. cd /sources
  13. rm -rf libnl-3.2.28
  14.  
  15. # 安装wpa_supplicant
  16. cd /sources
  17. tar -zxf wpa_supplicant-2.5.tar.gz
  18. cd wpa_supplicant-2.5
  19.  
  20. cat > wpa_supplicant/.config << "EOF"
  21. CONFIG_BACKEND=file
  22. CONFIG_CTRL_IFACE=y
  23. CONFIG_DEBUG_FILE=y
  24. CONFIG_DEBUG_SYSLOG=y
  25. CONFIG_DEBUG_SYSLOG_FACILITY=LOG_DAEMON
  26. CONFIG_DRIVER_NL80211=y
  27. CONFIG_DRIVER_WEXT=y
  28. CONFIG_DRIVER_WIRED=y
  29. CONFIG_EAP_GTC=y
  30. CONFIG_EAP_LEAP=y
  31. CONFIG_EAP_MD5=y
  32. CONFIG_EAP_MSCHAPV2=y
  33. CONFIG_EAP_OTP=y
  34. CONFIG_EAP_PEAP=y
  35. CONFIG_EAP_TLS=y
  36. CONFIG_EAP_TTLS=y
  37. CONFIG_IEEE8021X_EAPOL=y
  38. CONFIG_IPV6=y
  39. CONFIG_LIBNL32=y
  40. CONFIG_PEERKEY=y
  41. CONFIG_PKCS12=y
  42. CONFIG_READLINE=y
  43. CONFIG_SMARTCARD=y
  44. CONFIG_WPS=y
  45. CFLAGS += -I/usr/include/libnl3
  46. EOF
  47.  
  48. cd wpa_supplicant &&
  49. make BINDIR=/sbin LIBDIR=/lib
  50.  
  51. install -v -m755 wpa_{cli,passphrase,supplicant} /sbin/ &&
  52. install -v -m644 doc/docbook/wpa_supplicant.conf.5 /usr/share/man/man5/ &&
  53. install -v -m644 doc/docbook/wpa_{cli,passphrase,supplicant}.8 /usr/share/man/man8/
  54.  
  55. cd /sources
  56. rm -rf wpa_supplicant-2.5

  5. 网络配置:复制到命令行执行前,记得把中文注释去掉,否则会出错

  1. # 有线网络配置
  2. cat > /etc/sysconfig/ifconfig.eth0 << "EOF"
  3. ONBOOT="no"
  4. IFACE="eth0"
  5.  
  6. # 静态IP
  7. SERVICE="ipv4-static"
  8. IP="192.168.1.2"
  9. # 网关
  10. GATEWAY="192.168.1.1"
  11. # 子网掩码
  12. PREFIX="24"
  13. # 广播域
  14. BROADCAST="192.168.1.255"
  15.  
  16. # 动态IP
  17. #SERVICE="dhcpcd"
  18. # -b background 后台运行
  19. # -q quite 消息仍被记录,但是只有告警或错误的信息被打印
  20. #DHCP_START="-b -q"
  21. # -k release 退出前释放租期
  22. #DHCP_STOP="-k"
  23.  
  24. EOF
  25.  
  26. # 无线网络配置
  27. cat > /etc/sysconfig/ifconfig.wlan0 << "EOF"
  28. ONBOOT="no"
  29. IFACE="wlan0"
  30. SERVICE="wpa"
  31.  
  32. # Additional arguments to wpa_supplicant
  33. WPA_ARGS=""
  34.  
  35. # 动态IP
  36. WPA_SERVICE="dhcpcd"
  37. DHCP_START="-b -q"
  38. DHCP_STOP="-k"
  39.  
  40. # 静态IP
  41. #WPA_SERVICE="ipv4-static"
  42. #IP="192.168.1.2"
  43. #GATEWAY="192.168.1.1"
  44. #PREFIX="24"
  45. #BROADCAST="192.168.1.255"
  46.  
  47. EOF
  48.  
  49. # WIFI配置
  50. cat > /etc/sysconfig/wpa_supplicant-wlan0.conf << "EOF"
  51. network={
  52. ssid="WiFi-name1"
  53. psk="WiFi-password1"
  54. priority=5
  55. }
  56. EOF

  6. 卸载文件系统

  1. logout
  2.  
  3. umount -v $LFS/dev/pts
  4. umount -v $LFS/dev
  5. umount -v $LFS/run
  6. umount -v $LFS/proc
  7. umount -v $LFS/sys
  8. umount -v /mnt/boot
  9. # 删除 boot 和 sources 文件夹
  10. rm -rf $LFS/boot
  11. rm -rf $LFS/sources
  12.  
  13. umount -v $LFS

  7. 重启电脑,引导从U盘启动电脑

  8. 默认登录用户名:root    密码:

  9. 连接无线网络命令

  1. wpa_supplicant -B -i wlan0 -c /etc/sysconfig/wpa_supplicant-wlan0.conf
  2. dhcpcd wlan0

十二. 如何将LFS系统做成镜像

  1. 需要一台装有Linux系统的PC机

  2. 利用 gparted 格式化并重新划分U盘:

    /dev/sdc1       100M        EXT4          boot分区

    /dev/sdc2       900M        EXT4          LFS系统分区

  3. 执行 sudo  fdisk -u -l /dev/sdc 命令,查看硬件的分区情况,start和end中数字的单位是512字节

  4. 利用dd命令将U盘做成镜像:

      dd if=/dev/sdc of=lfs-7.10-linux-4.7.2.img bs=512 count=[fdisk命令中最大的end数+1]

Linux From Scratch(从零开始构建Linux系统,简称LFS)- Version 7.7(三)的更多相关文章

  1. LFS(Linux From Scratch)构建过程全记录(二):磁盘分区

    写在前面 本文将会详细记录LFS中,构建分区,构建文件系统和挂载分区的全过程 准备新硬盘 为了更加符合"从零开始构建Linux"的要求,我在虚拟机中,新建了一个磁盘 我们将会在这个 ...

  2. Linux From Scratch(从零开始构建Linux系统,简称LFS)- Version 7.7(一)

    一. 准备工作 1. 需要一个Linux宿主系统,例如早先版本的 LFS,Ubuntu/Fedora,SuSE 或者是在你的架构上可以运行的其它发行版 如果想实现Win7与Linux双系统,可参考我的 ...

  3. Linux From Scratch(从零开始构建Linux系统,简称LFS)(一)

    一. 准备工作 1. 需要一个Linux宿主系统,例如早先版本的 LFS,Ubuntu/Fedora,SuSE 或者是在你的架构上可以运行的其它发行版 如果想实现Win7与Linux双系统,可参考我的 ...

  4. Linux From Scratch(从零开始构建Linux系统,简称LFS)(三)

    九. 系统配置 1. 安装 LFS-Bootscripts-20150222 软件包包含一套在 LFS 系统启动和关闭时的启动和停止脚本. cd /sources tar -jxf lfs-boots ...

  5. Linux From Scratch(从零开始构建Linux系统,简称LFS)- Version 7.7(二)

    七. 构建临时系统 1. 通用编译指南 a. 确认是否正确设置了 LFS 环境变量 echo $LFS b. 假定你已经正确地设置了宿主系统的符号链接: 1)shell 使用的是 bash. 2)sh ...

  6. Linux From Scratch(从零开始构建Linux系统,简称LFS)(二)

    七. 构建临时系统 1. 通用编译指南 a. 确认是否正确设置了 LFS 环境变量 echo $LFS b. 假定你已经正确地设置了宿主系统需求和符号链接 c. 对于每个软件包: (1). 确保解压软 ...

  7. Raspberry Pi(树莓派)上从零开始构建Linux系统(简称PiLFS)(一)

    一. 准备工作 1. 装有Linux宿主系统的树莓派主板,可参考 Raspberry Pi(树莓派)上安装Raspbian(无路由器,无显示器) 2. 参考网址:Linux From Scratch ...

  8. 从零开始构建Linux

    目的:深入了解以Linux内核为基础的系统是如何组成,运行,以构建一个最基础的,纯净的系统. LFS构建步骤宿主机准备- linux操作系统安装- 使用独立硬盘,创建分区- 配置用户和组- 下载所有需 ...

  9. LFS(Linux From Scratch)构建过程全记录(五):交叉工具链的构建

    写在前面 本文将详细讲述如何构建工具链 前置知识 在LFS-BOOK中,我们需要学习一些关于"交叉编译"的内容,详见书本 安装Binutils-2.39 我们cd到sources文 ...

随机推荐

  1. 关于replace()方法中第二个参数的转义问题

    如果你想通过Javascript代码在网页中呈现 \ 字符,则在JS代码中你必须输入两个反斜杠 \\,否则会报错.比如: var a = "\"; alert(a); //chro ...

  2. 【原创】基于日志增量,统计qps,并基于ip排序

    增量统计日志行数(只统计上一秒) dns_qps.py #!/usr/bin/env python #_*_coding:utf-8_*_ import datetime import re impo ...

  3. 关于WEB Service&WCF&WebApi实现身份验证之WebApi篇

    之前先后总结并发表了关于WEB Service.WCF身份验证相关文章,如下: 关于WEB Service&WCF&WebApi实现身份验证之WEB Service篇. 关于WEB S ...

  4. Final Cut Pro X效果插件开发总结

    一.介绍 最近公司需要针对Final Cut Pro(FCP)开发一款效果插件,用于对公司自己开发的视频格式进行后期处理.Final Cut Pro是苹果公司推出的一款视频剪辑软件,因此需要在OSX平 ...

  5. STM32CubeMX安装指南

    1.STM32CubeMX软件下载 地址:http://pan.baidu.com/s/1bn8sXOV 密码:6u3p 2.安装     1)安装Java SDK     2)安装SetupSTM3 ...

  6. C#图片加水印实例与代码

    本文要提供的类可以为图片加文字水印,以及判断是否是图片文件.经过测试可运行,例子请下载:http://hovertree.com/h/bjaf/5qc5eh6y.htm 例子效果图: 以下是Hover ...

  7. aspx后台传递Json到前台的两种接收方法

    第一种:前台接收 dataType: "json",                success: function (data) {                    va ...

  8. ASP.NET5,MVC 6,Beta 7与VS 2015 RTM的兼容问题

    温馨提示:本文杂而乱,最终不知所云. Visual Studio 2015 RTM已经于2015年7月20号正式发布,我也在第一时间下载安装了起来. 虽然在5月份就开始使用RC版本,但是还是很期待正式 ...

  9. jquery 之for 循环

    jquery 的 for 循环: 1. var userList = [11,22,33,44]; $.each(userList,function(i,item){ console.log(i, i ...

  10. php设置手机访问浏览器版apache配置

    我们开发项目的时候经常会开发到浏览器版本的网页,这样我们就经常需要用手机连接局域网以方便测试,那么怎么配置服务器文件呢. 1.首先关闭电脑的windows防火墙   右击我的网络/windows防火墙 ...