Linux From Scratch(从零开始构建Linux系统,简称LFS)- Version 7.7(三)
九. 系统配置
1. 安装 LFS-Bootscripts-20150222
软件包包含一套在 LFS 系统启动和关闭时的启动和停止脚本。
- cd /sources
- tar -jxf lfs-bootscripts-20150222.tar.bz2
- cd lfs-bootscripts-20150222
- make install
- cd /sources
- rm -rf lfs-bootscripts-20150222
2. 管理网络设备
- # 运行以下命令,创建网络设备 Udev 规则
- bash /lib/udev/init-net-rules.sh
- # 查看生成的规则
cat /etc/udev/rules.d/70-persistent-net.rules
3. 配置系统主机名称
- echo "lfs" > /etc/hostname
4. 创建 /etc/hosts
文件
- cat > /etc/hosts << "EOF"
- # Begin /etc/hosts (network card version)
- 127.0.0.1 localhost
- # End /etc/hosts (network card version)
- EOF
5. 配置 Sysvinit
内核初始化期间,第一个运行的程序默认是SysVinit,这个程序读取/etc/inittab
文件
- cat > /etc/inittab << "EOF"
- # Begin /etc/inittab
- id:3:initdefault:
- si::sysinit:/etc/rc.d/init.d/rc S
- l0:0:wait:/etc/rc.d/init.d/rc 0
- l1:S1:wait:/etc/rc.d/init.d/rc 1
- l2:2:wait:/etc/rc.d/init.d/rc 2
- l3:3:wait:/etc/rc.d/init.d/rc 3
- l4:4:wait:/etc/rc.d/init.d/rc 4
- l5:5:wait:/etc/rc.d/init.d/rc 5
- l6:6:wait:/etc/rc.d/init.d/rc 6
- ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
- su:S016:once:/sbin/sulogin
- 1:2345:respawn:/sbin/agetty --noclear tty1 9600
- 2:2345:respawn:/sbin/agetty tty2 9600
- 3:2345:respawn:/sbin/agetty tty3 9600
- 4:2345:respawn:/sbin/agetty tty4 9600
- 5:2345:respawn:/sbin/agetty tty5 9600
- 6:2345:respawn:/sbin/agetty tty6 9600
- # End /etc/inittab
- EOF
6. 配置系统时钟
- 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
7. Bash 启动文件
- cat > /etc/profile << "EOF"
- # Begin /etc/profile
- export LANG=en_US.UTF-8
- # End /etc/profile
- EOF
8. 创建 /etc/inputrc 文件
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
9. 创建 /etc/shells 文件
shells
文件是当前系统所有可用 shell 的列表文件
- cat > /etc/shells << "EOF"
- # Begin /etc/shells
- /bin/sh
- /bin/bash
- # End /etc/shells
- EOF
10. LFS官方文档中还包含了其它可选配置,可按需添加
十. 让 LFS 系统可引导
1. 创建 /etc/fstab 文件
- cat > /etc/fstab << "EOF"
- # Begin /etc/fstab
- # file system mount-point type options dump fsck
- # order
- /dev/root / auto noatime,nodiratime 1 1
- #/dev/xxxx swap swap pri=1 0 0
- # End /etc/fstab
- EOF
2. 挂载 boot 分区
- mkdir /mnt/boot
- mount /dev/sdc1 /mnt/boot
3. Linux-4.7.2
a. 宿主系统下运行下列命令,查看有线、无线网卡型号
- lspci | grep -i ethernet
- lspci | grep -i wireless
b. 根据型号选择合适的驱动,安装配置内核
- cd /sources
- tar -Jxf linux-4.7.2.tar.xz
- cd linux-4.7.2
- make mrproper
- make menuconfig
- #新增
- #[*] Networking support --->
- #-*- Wireless --->
- #<*> cfg80211 - wireless configuration API
- #[*] cfg80211 wireless extensions compatibility
- # Device Drivers --->
- #[*] Network device support --->
- #[*] Ethernet driver support --->
- #[*] Atheros devices
- #<M> Qualcomm Atheros AR816X/AR817x support
- #[*] Wireless LAN --->
- #[*] Atheros/Qualcomm devices
- #<M> Atheros 802.11n wireless cards support
- #[*] Atheros ath9k PCI/PCIe bus support
- #<*> PPP (point-to-point protocol) support
- #<*> PPP support for async serial ports
- make
- make modules_install
- # 下面的命令假设主机是 x86 架构:
- cp -v arch/x86/boot/bzImage /mnt/boot/vmlinuz-4.7.2
- cp -v System.map /mnt/boot/System.map-4.7.2
- cp -v .config /mnt/boot/config-4.7.2
- install -d /usr/share/doc/linux-4.7.2
- cp -r Documentation/* /usr/share/doc/linux-4.7.2
- # 配置 Linux 模块加载顺序
- # 如果将 USB 设备(ehci_hcd、ohci_hcd 和 uhci_hcd) 编译为模块,则需要此文件。
- # 运行以下命令建立 /etc/modprobe.d/usb.conf 文件:
- 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 /sources
- rm -rf linux-4.7.2
4. 创建 initrd.img 文件
a. 点击此下载 mkinitramfs 相关文件,并放到LFS系统对应的位置
b. mkinitramfs 命令依赖于 cpio 包,先安装
- cd /sources
- tar -jxf cpio-2.12.tar.bz2
- cd cpio-2.12
- ./configure --prefix=/usr \
- --bindir=/bin \
- --enable-mt \
- --with-rmt=/usr/libexec/rmt &&
- make &&
- makeinfo --html -o doc/html doc/cpio.texi &&
- makeinfo --html --no-split -o doc/cpio.html doc/cpio.texi &&
- makeinfo --plaintext -o doc/cpio.txt doc/cpio.texi
- make install &&
- install -v -m755 -d /usr/share/doc/cpio-2.12/html &&
- install -v -m644 doc/html/* \
- /usr/share/doc/cpio-2.12/html &&
- install -v -m644 doc/cpio.{html,txt} \
- /usr/share/doc/cpio-2.12
- cd /sources
- rm -rf cpio-2.12
c. 执行如下命令,重新生成 initrd
- cp /sbin/udevadm /bin/
- chmod 777 /usr/sbin/mkinitramfs
/usr/sbin/mkinitramfs --force
d. 移动 initrd.img-4.7.2.xz 到 boot 分区下
- mv /boot/initrd.img-4.7.2.xz /mnt/boot/
5. 用 GRUB 设置引导过程
- # 将GRUB文件安装到 /mnt/boot/grub,并修改MBR扇区
- grub-install --root-directory=/mnt /dev/sdc
- # 创建GRUB配置文件
- cat > /mnt/boot/grub/grub.cfg << "EOF"
- # Begin /boot/grub/grub.cfg
- set default=0
- set timeout=5
- menuentry "linux-4.7.2-lfs-7.10" {
- set kver=4.7.2
- set boot_uuid=<boot分区uuid>
- set root_uuid=<root分区uuid>
- search.fs_uuid ${boot_uuid} root
- linux /vmlinuz-${kver} root=uuid/${root_uuid}
- initrd /initrd.img-${kver}.xz
- }
- EOF
十一. 最后
1. 创建 /etc/lfs-release
文件
- cat > /etc/lsb-release << "EOF"
- DISTRIB_ID="Linux From Scratch"
- DISTRIB_RELEASE="7.10"
- DISTRIB_CODENAME="kevin"
- DISTRIB_DESCRIPTION="Linux From Scratch"
- EOF
2. 安装 OpenSSH
- # openssh依赖于openssl库,先安装openssl
- cd /sources
- tar -zxf openssl-1.0.2h.tar.gz
- cd openssl-1.0.2h
- ./config --prefix=/usr \
- --openssldir=/etc/ssl \
- --libdir=lib \
- shared \
- zlib-dynamic &&
- make depend &&
- make
- make MANDIR=/usr/share/man MANSUFFIX=ssl install &&
- install -dv -m755 /usr/share/doc/openssl-1.0.2h &&
- cp -vfr doc/* /usr/share/doc/openssl-1.0.2h
- cd /sources
- rm -rf openssl-1.0.2h
- # 安装openssh
- cd /sources
- tar -zxf openssh-7.3p1.tar.gz
- cd openssh-7.3p1
- install -v -m700 -d /var/lib/sshd &&
- chown -v root:sys /var/lib/sshd &&
- groupadd -g 50 sshd &&
- useradd -c 'sshd PrivSep' \
- -d /var/lib/sshd \
- -g sshd \
- -s /bin/false \
- -u 50 sshd
- ./configure --prefix=/usr \
- --sysconfdir=/etc/ssh \
- --with-md5-passwords \
- --with-privsep-path=/var/lib/sshd &&
- make
- make install &&
- install -v -m755 contrib/ssh-copy-id /usr/bin &&
- install -v -m644 contrib/ssh-copy-id.1 \
- /usr/share/man/man1 &&
- install -v -m755 -d /usr/share/doc/openssh-7.3p1 &&
- install -v -m644 INSTALL LICENCE OVERVIEW README* \
- /usr/share/doc/openssh-7.3p1
- cd /sources
- rm -rf openssh-7.3p1
- # 系统启动时开启ssh服务
- cd /sources
- tar -Jxf blfs-bootscripts-20160902.tar.xz
- cd blfs-bootscripts-20160902
- make install-sshd
- cd /sources
- rm -rf blfs-bootscripts-20160902
3. 安装 dhcpcd
- cd /sources
- tar -Jxf dhcpcd-6.11.3.tar.xz
- cd dhcpcd-6.11.3
- ./configure --libexecdir=/lib/dhcpcd \
- --dbdir=/var/lib/dhcpcd &&
- make
- make install
- cd /sources
- rm -rf dhcpcd-6.11.3
4. 安装 wpa_supplicant
- # wpa_supplicant依赖于libnl-3库,先安装libnl-3
- cd /sources
- tar -zxf libnl-3.2.28.tar.gz
- cd libnl-3.2.28
- ./configure --prefix=/usr \
- --sysconfdir=/etc \
- --disable-static &&
- make
- make install
- cd /sources
- rm -rf libnl-3.2.28
- # 安装wpa_supplicant
- cd /sources
- tar -zxf wpa_supplicant-2.5.tar.gz
- cd wpa_supplicant-2.5
- cat > wpa_supplicant/.config << "EOF"
- CONFIG_BACKEND=file
- CONFIG_CTRL_IFACE=y
- CONFIG_DEBUG_FILE=y
- CONFIG_DEBUG_SYSLOG=y
- CONFIG_DEBUG_SYSLOG_FACILITY=LOG_DAEMON
- CONFIG_DRIVER_NL80211=y
- CONFIG_DRIVER_WEXT=y
- CONFIG_DRIVER_WIRED=y
- CONFIG_EAP_GTC=y
- CONFIG_EAP_LEAP=y
- CONFIG_EAP_MD5=y
- CONFIG_EAP_MSCHAPV2=y
- CONFIG_EAP_OTP=y
- CONFIG_EAP_PEAP=y
- CONFIG_EAP_TLS=y
- CONFIG_EAP_TTLS=y
- CONFIG_IEEE8021X_EAPOL=y
- CONFIG_IPV6=y
- CONFIG_LIBNL32=y
- CONFIG_PEERKEY=y
- CONFIG_PKCS12=y
- CONFIG_READLINE=y
- CONFIG_SMARTCARD=y
- CONFIG_WPS=y
- CFLAGS += -I/usr/include/libnl3
- EOF
- cd wpa_supplicant &&
- make BINDIR=/sbin LIBDIR=/lib
- install -v -m755 wpa_{cli,passphrase,supplicant} /sbin/ &&
- install -v -m644 doc/docbook/wpa_supplicant.conf.5 /usr/share/man/man5/ &&
- install -v -m644 doc/docbook/wpa_{cli,passphrase,supplicant}.8 /usr/share/man/man8/
- cd /sources
- rm -rf wpa_supplicant-2.5
5. 网络配置:复制到命令行执行前,记得把中文注释去掉,否则会出错
- # 有线网络配置
- cat > /etc/sysconfig/ifconfig.eth0 << "EOF"
- ONBOOT="no"
- IFACE="eth0"
- # 静态IP
- SERVICE="ipv4-static"
- IP="192.168.1.2"
- # 网关
- GATEWAY="192.168.1.1"
- # 子网掩码
- PREFIX="24"
- # 广播域
- BROADCAST="192.168.1.255"
- # 动态IP
- #SERVICE="dhcpcd"
- # -b background 后台运行
- # -q quite 消息仍被记录,但是只有告警或错误的信息被打印
- #DHCP_START="-b -q"
- # -k release 退出前释放租期
- #DHCP_STOP="-k"
- EOF
- # 无线网络配置
- cat > /etc/sysconfig/ifconfig.wlan0 << "EOF"
- ONBOOT="no"
- IFACE="wlan0"
- SERVICE="wpa"
- # Additional arguments to wpa_supplicant
- WPA_ARGS=""
- # 动态IP
- WPA_SERVICE="dhcpcd"
- DHCP_START="-b -q"
- DHCP_STOP="-k"
- # 静态IP
- #WPA_SERVICE="ipv4-static"
- #IP="192.168.1.2"
- #GATEWAY="192.168.1.1"
- #PREFIX="24"
- #BROADCAST="192.168.1.255"
- EOF
- # WIFI配置
- cat > /etc/sysconfig/wpa_supplicant-wlan0.conf << "EOF"
- network={
- ssid="WiFi-name1"
- psk="WiFi-password1"
- priority=5
- }
- EOF
6. 卸载文件系统
- logout
- umount -v $LFS/dev/pts
- umount -v $LFS/dev
- umount -v $LFS/run
- umount -v $LFS/proc
- umount -v $LFS/sys
- umount -v /mnt/boot
- # 删除 boot 和 sources 文件夹
- rm -rf $LFS/boot
- rm -rf $LFS/sources
- umount -v $LFS
7. 重启电脑,引导从U盘启动电脑
8. 默认登录用户名:root 密码:
9. 连接无线网络命令
- wpa_supplicant -B -i wlan0 -c /etc/sysconfig/wpa_supplicant-wlan0.conf
- 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(三)的更多相关文章
- LFS(Linux From Scratch)构建过程全记录(二):磁盘分区
写在前面 本文将会详细记录LFS中,构建分区,构建文件系统和挂载分区的全过程 准备新硬盘 为了更加符合"从零开始构建Linux"的要求,我在虚拟机中,新建了一个磁盘 我们将会在这个 ...
- Linux From Scratch(从零开始构建Linux系统,简称LFS)- Version 7.7(一)
一. 准备工作 1. 需要一个Linux宿主系统,例如早先版本的 LFS,Ubuntu/Fedora,SuSE 或者是在你的架构上可以运行的其它发行版 如果想实现Win7与Linux双系统,可参考我的 ...
- Linux From Scratch(从零开始构建Linux系统,简称LFS)(一)
一. 准备工作 1. 需要一个Linux宿主系统,例如早先版本的 LFS,Ubuntu/Fedora,SuSE 或者是在你的架构上可以运行的其它发行版 如果想实现Win7与Linux双系统,可参考我的 ...
- Linux From Scratch(从零开始构建Linux系统,简称LFS)(三)
九. 系统配置 1. 安装 LFS-Bootscripts-20150222 软件包包含一套在 LFS 系统启动和关闭时的启动和停止脚本. cd /sources tar -jxf lfs-boots ...
- Linux From Scratch(从零开始构建Linux系统,简称LFS)- Version 7.7(二)
七. 构建临时系统 1. 通用编译指南 a. 确认是否正确设置了 LFS 环境变量 echo $LFS b. 假定你已经正确地设置了宿主系统的符号链接: 1)shell 使用的是 bash. 2)sh ...
- Linux From Scratch(从零开始构建Linux系统,简称LFS)(二)
七. 构建临时系统 1. 通用编译指南 a. 确认是否正确设置了 LFS 环境变量 echo $LFS b. 假定你已经正确地设置了宿主系统需求和符号链接 c. 对于每个软件包: (1). 确保解压软 ...
- Raspberry Pi(树莓派)上从零开始构建Linux系统(简称PiLFS)(一)
一. 准备工作 1. 装有Linux宿主系统的树莓派主板,可参考 Raspberry Pi(树莓派)上安装Raspbian(无路由器,无显示器) 2. 参考网址:Linux From Scratch ...
- 从零开始构建Linux
目的:深入了解以Linux内核为基础的系统是如何组成,运行,以构建一个最基础的,纯净的系统. LFS构建步骤宿主机准备- linux操作系统安装- 使用独立硬盘,创建分区- 配置用户和组- 下载所有需 ...
- LFS(Linux From Scratch)构建过程全记录(五):交叉工具链的构建
写在前面 本文将详细讲述如何构建工具链 前置知识 在LFS-BOOK中,我们需要学习一些关于"交叉编译"的内容,详见书本 安装Binutils-2.39 我们cd到sources文 ...
随机推荐
- 关于replace()方法中第二个参数的转义问题
如果你想通过Javascript代码在网页中呈现 \ 字符,则在JS代码中你必须输入两个反斜杠 \\,否则会报错.比如: var a = "\"; alert(a); //chro ...
- 【原创】基于日志增量,统计qps,并基于ip排序
增量统计日志行数(只统计上一秒) dns_qps.py #!/usr/bin/env python #_*_coding:utf-8_*_ import datetime import re impo ...
- 关于WEB Service&WCF&WebApi实现身份验证之WebApi篇
之前先后总结并发表了关于WEB Service.WCF身份验证相关文章,如下: 关于WEB Service&WCF&WebApi实现身份验证之WEB Service篇. 关于WEB S ...
- Final Cut Pro X效果插件开发总结
一.介绍 最近公司需要针对Final Cut Pro(FCP)开发一款效果插件,用于对公司自己开发的视频格式进行后期处理.Final Cut Pro是苹果公司推出的一款视频剪辑软件,因此需要在OSX平 ...
- STM32CubeMX安装指南
1.STM32CubeMX软件下载 地址:http://pan.baidu.com/s/1bn8sXOV 密码:6u3p 2.安装 1)安装Java SDK 2)安装SetupSTM3 ...
- C#图片加水印实例与代码
本文要提供的类可以为图片加文字水印,以及判断是否是图片文件.经过测试可运行,例子请下载:http://hovertree.com/h/bjaf/5qc5eh6y.htm 例子效果图: 以下是Hover ...
- aspx后台传递Json到前台的两种接收方法
第一种:前台接收 dataType: "json", success: function (data) { va ...
- ASP.NET5,MVC 6,Beta 7与VS 2015 RTM的兼容问题
温馨提示:本文杂而乱,最终不知所云. Visual Studio 2015 RTM已经于2015年7月20号正式发布,我也在第一时间下载安装了起来. 虽然在5月份就开始使用RC版本,但是还是很期待正式 ...
- jquery 之for 循环
jquery 的 for 循环: 1. var userList = [11,22,33,44]; $.each(userList,function(i,item){ console.log(i, i ...
- php设置手机访问浏览器版apache配置
我们开发项目的时候经常会开发到浏览器版本的网页,这样我们就经常需要用手机连接局域网以方便测试,那么怎么配置服务器文件呢. 1.首先关闭电脑的windows防火墙 右击我的网络/windows防火墙 ...