码迷,mamicode.com
首页 > 系统相关 > 详细

从LFS官方文档构建完整Linux系统

时间:2015-11-13 17:03:12      阅读:548      评论:0      收藏:0      [点我收藏+]

标签:

该文章不是新手教程!!!

  • Parallels Desktop (为防止找不到网卡 NIC Type设成Intel(R) PRO/1000 MT)。
  • kali-linux-2.0-amd64(i386).iso (该liveCD编译工具算完整,liveCD启动另外安装bison、gawk,直接apt-get install 安装即可)。
  • 其它虚拟机硬件按个人需求设置。
  • 宿主系统所需工具检测

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前)可以不按照文档的方法配置相关文件。安装下面方法配置基本系统所需的文件,可满足系统的基本运行,和连接网络。
  1 时间设置(Configuring the setclock Script)
  2 cat > /etc/sysconfig/clock << "EOF"
  3 # Begin /etc/sysconfig/clock
  4 UTC=1
  5 # End /etc/sysconfig/clock
  6 EOF
  7 
  8 bash /lib/udev/init-net-rules.sh
  9 
 10 cat > /etc/udev/rules.d/83-duplicate_devs.rules << "EOF"
 11 # Persistent symlinks for webcam and tuner
 12 KERNEL=="video*", ATTRS{idProduct}=="1910", ATTRS{idVendor}=="0d81",  13     SYMLINK+="webcam"
 14 KERNEL=="video*", ATTRS{device}=="0x036f", ATTRS{vendor}=="0x109e",  15     SYMLINK+="tvtuner"
 16 EOF
 17 
 18 cat > /etc/inittab << "EOF"
 19 # Begin /etc/inittab
 20 id:3:initdefault:
 21 si::sysinit:/etc/rc.d/init.d/rc S
 22 l0:0:wait:/etc/rc.d/init.d/rc 0
 23 l1:S1:wait:/etc/rc.d/init.d/rc 1
 24 l2:2:wait:/etc/rc.d/init.d/rc 2
 25 l3:3:wait:/etc/rc.d/init.d/rc 3
 26 l4:4:wait:/etc/rc.d/init.d/rc 4
 27 l5:5:wait:/etc/rc.d/init.d/rc 5
 28 l6:6:wait:/etc/rc.d/init.d/rc 6
 29 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
 30 su:S016:once:/sbin/sulogin
 31 1:2345:respawn:/sbin/agetty --noclear tty1 9600
 32 2:2345:respawn:/sbin/agetty tty2 9600
 33 3:2345:respawn:/sbin/agetty tty3 9600
 34 4:2345:respawn:/sbin/agetty tty4 9600
 35 5:2345:respawn:/sbin/agetty tty5 9600
 36 6:2345:respawn:/sbin/agetty tty6 9600
 37 # End /etc/inittab
 38 EOF
 39 
 40 cat > /etc/sysconfig/console << "EOF"
 41 # Begin /etc/sysconfig/console 
 42 FONT="lat2a-16 -m 8859-2"
 43 # End /etc/sysconfig/console
 44 EOF
 45 
 46 cat > /etc/shells << "EOF"
 47 # Begin /etc/shells
 48 /bin/sh
 49 /bin/bash
 50 # End /etc/shells
 51 EOF
 52 
 53 设置bash下的键盘功能键设置
 54 cat > /etc/inputrc << "EOF"
 55 set horizontal-scroll-mode Off
 56 set meta-flag On
 57 set input-meta On
 58 set convert-meta Off
 59 set output-meta On
 60 set bell-style none
 61 "\eOd": backward-word
 62 "\eOc": forward-word
 63 "\e[1~": beginning-of-line
 64 "\e[4~": end-of-line
 65 "\e[5~": beginning-of-history
 66 "\e[6~": end-of-history
 67 "\e[3~": delete-char
 68 "\e[2~": quoted-insert
 69 "\eOH": beginning-of-line
 70 "\eOF": end-of-line
 71 "\e[H": beginning-of-line
 72 "\e[F": end-of-line
 73 EOF
 74 
 75 设置Bash Shell启动文件(The Bash Shell Startup Files)
 76 cat > /etc/profile << "EOF"
 77 # Begin /etc/profile
 78 export LANG=en_US.UTF-8
 79 export LANGUAGE=en_US:en
 80 export LC_NUMERIC=en_US.UTF-8
 81 export LC_TIME=en_US.UTF-8
 82 export LC_MONETARY=en_US.UTF-8
 83 export LC_PAPER=en_US.UTF-8
 84 export LC_IDENTIFICATION=en_US.UTF-8
 85 export LC_NAME=en_US.UTF-8
 86 export LC_ADDRESS=en_US.UTF-8
 87 export LC_TELEPHONE=en_US.UTF-8
 88 export LC_MEASUREMENT=en_US.UTF-8
 89 export INPUTRC=/etc/inputrc
 90 alias ls="ls --color"
 91 export PS1=‘\u:\w\$ ‘
 92 # End /etc/profile
 93 EOF
 94 
 95 设置本地网络名
 96 echo "HOSTNAME=SCoreLFS" > /etc/sysconfig/network
 97 
 98 设置hosts文件
 99 cat > /etc/hosts << "EOF"
100 # Begin /etc/hosts (no network card version)
101 127.0.0.1 SCoreLFS localhost
102 # End /etc/hosts (no network card version)
103 EOF
104 
105 设置网络的静态地址
106 cd /etc/sysconfig/?cat > ifconfig.eth0 << "EOF"
107 ONBOOT=yes?
108 IFACE=eth0
109 SERVICE=ipv4-static 
110 IP=10.211.55.49
111 GATEWAY=10.211.55.1 
112 BROADCAST=10.211.55.255?EOF 
113 
114 设置DNS
115 cat > /etc/resolv.conf << "EOF"
116 # Begin /etc/resolv.conf
117 nameserver 10.211.55.1 
118 nameserver 8.8.8.8 
119 # End /etc/resolv.conf
120 EOF
121 
122 建立fstab文件
123 cat > /etc/fstab << "EOF"
124 # Begin /etc/fstab
125 # file system  mount-point  type   options         dump  fsck
126 #                                                        order
127 /dev/sda1       /            ext4  defaults        1     1
128 /dev/sda2       swap         swap   pri=1           0     0
129 proc              /proc        proc   defaults        0     0
130 sysfs             /sys         sysfs  defaults        0     0
131 devpts          /dev/pts     devpts gid=4,mode=620  0     0
132 #shm              /dev/shm     tmpfs  defaults        0     0
133 # End /etc/fstab
134 EOF
135 
136 install -v -m755 -d /etc/modprobe.d
137  
138 cat > /etc/modprobe.d/usb.conf << "EOF" # Begin /etc/modprobe.d/usb.conf
139 install ohci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i ohci_hcd ; true
140 install uhci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i uhci_hcd ; true
141 # End /etc/modprobe.d/usb.conf
142 EOF
  • logout到宿主系统前记得passwd设置一下root密码。

为了后续安装软件和使用方便,建议根据blfs文档安装openssh、openssl和wget。至于ssh的配置可以安装下面方法,可以解决root登录和权限问题

1 vim /etc/ssh/sshd_config 添加下面代码
2 
3 PasswordAuthentication yes
4 PermitRootLogin yes

从LFS官方文档构建完整Linux系统

标签:

原文地址:http://www.cnblogs.com/sonofdark/p/4962609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!