从LFS官方文档构建完整Linux系统
Posted chulia
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从LFS官方文档构建完整Linux系统相关的知识,希望对你有一定的参考价值。
http://www.cnblogs.com/sonofdark/p/4962609.html
这不是新手教程!!!
- Parallels Desktop (为防止找不到网卡 NIC Type设成Intel(R) PRO/1000 MT)。
- kali-linux-2.0-amd64(i386).iso (该liveCD编译工具算完整,liveCD启动另外安装bison、gawk,直接apt-get install 安装即可)。需要多次编译的包,先删掉,再重新解压,编译,否则会造成不可扭转的错误。
- 其它虚拟机硬件按个人需求设置。
- 宿主系统所需工具检测
library-check.sh
1
2
3
4
5
6
|
#!/bin/bash for lib in lib{gmp,mpfr,mpc}.la; do echo $lib: $( if find /usr/lib * -name $lib| grep -q $lib; then :; else echo not; fi ) found done unset lib |
编译安装 GMP、MPFR、MPC
version-check.sh
1 #!/bin/bash 2 # Simple script to list version numbers of critical development tools 3 4 export LC_ALL=C 5 bash --version | head -n1 | cut -d" " -f2-4 6 echo "/bin/sh -> `readlink -f /bin/sh`" 7 echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3- 8 bison --version | head -n1 9 if [ -e /usr/bin/yacc ]; 10 then echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`"; 11 else echo "yacc not found"; fi 12 13 bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6- 14 echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2 15 diff --version | head -n1 16 find --version | head -n1 17 gawk --version | head -n1 18 if [ -e /usr/bin/awk ]; 19 then echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`"; 20 else echo "awk not found"; fi 21 22 gcc --version | head -n1 23 ldd --version | head -n1 | cut -d" " -f2- # glibc version 24 grep --version | head -n1 25 gzip --version | head -n1 26 cat /proc/version 27 m4 --version | head -n1 28 make --version | head -n1 29 patch --version | head -n1 30 echo Perl `perl -V:version` 31 sed --version | head -n1 32 tar --version | head -n1 33 echo "Texinfo: `makeinfo --version | head -n1`" 34 xz --version | head -n1 35 36 echo \'main(){}\' > dummy.c && gcc -o dummy dummy.c 37 if [ -x dummy ] 38 then echo "gcc compilation OK"; 39 else echo "gcc compilation failed"; fi 40 rm -f dummy.c dummy 41 42 echo \'main(){}\' > dummy.c && g++ -o dummy dummy.c 43 if [ -x dummy ] 44 then echo "g++ compilation OK"; 45 else echo "g++ compilation failed"; fi 46 rm -f dummy.c dummy
- 构建方法按官方文档一步步来,只是复制粘贴而已。下面说些要注意的地方。(构建完tools,进入chroot后)
编译安装GCC时,可以不要check,但一定执行以下命令
1 install -v -dm755 /usr/lib/bfd-plugins 2 3 ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/5.2.0/liblto_plugin.so /usr/lib/bfd-plugins/
否则后续编译软件的时候出现找不到类库和头文件的问题。如果不放心,每次安装完一个软件ldconfig一下。
- 安装完软件后(编译内核和安装GRUB前)可以不按照文档的方法配置相关文件。安装下面方法配置基本系统所需的文件,可满足系统的基本运行,和连接网络。
时间设置(Configuring the setclock Script) cat > /etc/sysconfig/clock << "EOF" # Begin /etc/sysconfig/clock UTC=1 # End /etc/sysconfig/clock EOF bash /lib/udev/init-net-rules.sh cat > /etc/udev/rules.d/83-duplicate_devs.rules << "EOF" # Persistent symlinks for webcam and tuner KERNEL=="video*", ATTRS{idProduct}=="1910", ATTRS{idVendor}=="0d81", \\ SYMLINK+="webcam" KERNEL=="video*", ATTRS{device}=="0x036f", ATTRS{vendor}=="0x109e", \\ SYMLINK+="tvtuner" EOF 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 cat > /etc/sysconfig/console << "EOF" # Begin /etc/sysconfig/console FONT="lat2a-16 -m 8859-2" # End /etc/sysconfig/console EOF cat > /etc/shells << "EOF" # Begin /etc/shells /bin/sh /bin/bash # End /etc/shells EOF 设置bash下的键盘功能键设置 cat > /etc/inputrc << "EOF" set horizontal-scroll-mode Off set meta-flag On set input-meta On set convert-meta Off set output-meta On set bell-style none "\\eOd": backward-word "\\eOc": forward-word "\\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 "\\eOH": beginning-of-line "\\eOF": end-of-line "\\e[H": beginning-of-line "\\e[F": end-of-line EOF 设置Bash Shell启动文件(The Bash Shell Startup Files) cat > /etc/profile << "EOF" # Begin /etc/profile export LANG=en_US.UTF-8 export LANGUAGE=en_US:en export LC_NUMERIC=en_US.UTF-8 export LC_TIME=en_US.UTF-8 export LC_MONETARY=en_US.UTF-8 export LC_PAPER=en_US.UTF-8 export LC_IDENTIFICATION=en_US.UTF-8 export LC_NAME=en_US.UTF-8 export LC_ADDRESS=en_US.UTF-8 export LC_TELEPHONE=en_US.UTF-8 export LC_MEASUREMENT=en_US.UTF-8 export INPUTRC=/etc/inputrc alias ls="ls --color" export PS1=\'\\u:\\w\\$ \' # End /etc/profile EOF 设置本地网络名 echo "HOSTNAME=SCoreLFS" > /etc/sysconfig/network 设置hosts文件 cat > /etc/hosts << "EOF" # Begin /etc/hosts (no network card version) 127.0.0.1 SCoreLFS localhost # End /etc/hosts (no network card version) EOF 设置网络的静态地址 cd /etc/sysconfig/ cat > ifconfig.eth0 << "EOF" ONBOOT=yes
IFACE=eth0 SERVICE=ipv4-static IP=10.211.55.49 GATEWAY=10.211.55.1 BROADCAST=10.211.55.255 EOF 设置DNS cat > /etc/resolv.conf << "EOF" # Begin /etc/resolv.conf nameserver 10.211.55.1 nameserver 8.8.8.8 # End /etc/resolv.conf EOF 建立fstab文件 cat > /etc/fstab << "EOF" # Begin /etc/fstab # file system mount-point type options dump fsck # order /dev/sda1 / ext4 defaults 1 1 /dev/sda2 swap swap pri=1 0 0 proc /proc proc defaults 0 0 sysfs /sys sysfs defaults 0 0 devpts /dev/pts devpts gid=4,mode=620 0 0 #shm /dev/shm tmpfs defaults 0 0 # End /etc/fstab EOF 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
- 编译内核时选择下面基本的项
-> Device Drivers -> SCSI device support - > SCSI disk support -> Device Drivers -> SCSI device support -> SCSI low-level drivers -> BusLogic SCSI support -> Device Drivers -> Fusion MPT device support -> Fusion MPT (base + ScsiHost) drivers -> Device Drivers -> Networking support -> Ethernet (10 or 100Mbit) -> AMD PCnet32 PCI support -> Device Drivers -> USB support -> Support for Host-side USB -> EHCI HCD (USB 2.0) support -> UHCI HCD (most Intel and VIA) support -> USB Mass Storage support E100/E1000、ext4 相关项
- logout到宿主系统前记得passwd设置一下root密码。
为了后续安装软件和使用方便,建议根据blfs文档安装openssh、openssl和wget。至于ssh的配置可以按照下面方法,可以解决root登录和权限问题
1 vim /etc/ssh/sshd_config 添加下面代码 2 3 PasswordAuthentication yes 4 PermitRootLogin yes
- 问题:安装完系统虚拟机的磁盘占空间过大,达10几G。而在LFS系统内查询的结果,加swap分区也不过2G。而且无法释放。这个问题很困惑,找了很久没找到方法。如果谁知道的,在评论里面回复。谢谢!!!
http://www.linuxfromscratch.org/livecd/download.html
http://wiki.linuxfromscratch.org/lfs/browser#trunk
http://www.linuxfromscratch.org/livecd/download.html
http://ftp.osuosl.org/pub/lfs-livecd/
http://ftp.osuosl.org/pub/lfs/lfs-packages/
http://ftp.osuosl.org/pub/clfs/clfs-packages/
http://ftp.osuosl.org/pub/blfs/svn/
以上是关于从LFS官方文档构建完整Linux系统的主要内容,如果未能解决你的问题,请参考以下文章
LFS 系列从零开始 DIY Linux 系统:构建 LFS 系统 - Shadow-4.2.1
LFS 系列从零开始 DIY Linux 系统:构建 LFS 系统 - Attr-2.4.47
LFS 系列从零开始 DIY Linux 系统:构建临时系统 - Texinfo-5.2
LFS 系列从零开始 DIY Linux 系统:构建 LFS 系统 - Acl-2.2.52