LFS 6.3 Lab Notes

Source: Internet
Author: User
Tags bz2 manual gettext mkdir posix translit ssh
After experiencing a variety of hardships, finally thick, thin hair, with a very short time, compiled to complete the LFS, some of the content needs further understanding, the use of the environment is Emacs ansi-term do remote landing client, as a study note
************************************************************
LFS has a LiveCD, the CD has the necessary material.
Reference Documentation:
1. Official website, http://www.linuxfromscratch.org/lfs/
2. Manual:/usr/share/lfs-book-6.3-html/index.html
3. Teach you how to build your own Linux System second Edition
The purpose of this post, taking into account the integrity, further highlight the focus.
PostScript impression:
The most detailed is the reference manual (which can be taken from the CD), followed by a hands-on document, which describes only a few key issues.
Can be used as an outline reference.
************************************************************
Job Overview:
Download Startup Disk LiveCD, where Lfslivecd-x86-6.3-r2145.iso is used
Create a virtual machine, create a hard disk to preserve the compilation results,
Create new User (LFS), compile temporary working environment as normal user, store to hard disk/tools directory)
Use the root user to compile the formal work environment in chroot mode
Set boot from hard disk
############################################################
1.1. Create a virtual machine
It's a lot easier than getting a bare metal.
############################################################
To install a completely new Linux system, start with a hard drive. Working on a virtual machine, you create a hard disk without spending money.
Create a virtual machine that is configured to:
An IDE hard disk, 8G in size, so shown as/dev/hda, with the goal of installing a custom Linux operating system on it
I use vmware11.0, the system defaults to SCSI, after creation, you can add a new IDE hard disk, remove the SCSI hard disk, so as to ensure consistent with the textbook, save the hassle of modification.

Memory: 256M
A network card: using NAT mode,
The virtual machine uses the virtual network card VMNET8 in the host as the gateway, can realize the host and the virtual machine communication, the virtual machine also can access the Internet, but the Internet cannot access the virtual machine.
VMNET8 also has the DHCP server feature, which assigns IP addresses to the network, and the virtual machine is set to DHCP mode to automatically obtain the IP address.
Use NAT: Ensure that the DHCP service is started in the Eidt-virtual Network editor
With the network, you can start SECURECRT login. Solve the console problem. You can also start a TFTP service or NFS service to lend resources to a virtual machine.

A floppy disk can exchange information with the host (using a floppy image)
A CDROM load Livecd:lfslivecd-x86-6.3-r2145.iso

Set up a virtual machine to boot from a CD
The virtual machine starts too fast to see the prompt to enter the BIOS,
To modify a virtual machine configuration file (. vmx):
Example: Other Linux 2.6.x KERNEL.VMX (each virtual machine has a corresponding configuration file)
Added at the end:
Bios.bootdelay = "3000"
Start time delay 3 seconds, this start to see, and then calmly press "F2" into the BIOS settings.

1.2. Partition and format the hard drive. (Fdisk and Mkswap, MKFS)
After the disc is booted, this hard drive is/dev/hda,
LFS recommends dividing the/DEV/HDA into 2 partitions,
First Partition, 512M,
Second partition, remaining,
Action: Fdisk/dev/hda
N (new)-P (primary) .... Create two original partitions (p,1 ... p,2 ... w)
After partitioning, two more block devices/dev/hda1,/dev/hda2

Then format two partitions, one for swap and one for ext2
Swap, (MKSWAP/DEV/HDA1),
Ext2, (Mkfs-t ext2/dev/hda2)


############################################################
2. What do we do after the CD-ROM is started?
Start the sshd service first, then we log in, convenient for us to operate.
Then attach the hard drive to the system.
Create a new user, which is the key to this section.
############################################################
After the CD-ROM is started, we see an original Linux system, with common tools and code in it.
In the root directory, there are 2 txt files that can be browsed and have an understanding of the disc tool.
You can also wait to start the sshd remote login and then browse, there will be a better browsing console.
----------------------------------------
2.1: Start sshd
----------------------------------------
/etc/rc.d/init.d/sshd start
----------------------------------------
2.2: Log in from outside with SSH.
----------------------------------------
You need to set a password for the root user before logging in: passwd root

SSH root@192.168.150.157 (change the login IP according to the actual situation)
Enter the password to log in.

For convenience, we export an environment variable. So we can have less typing.
Export Lfs=/mnt/lfs
MKDIR-PV $LFS # Create mount point, note that restart is lost

Mount Partition:
SWAPON/DEV/HDA1 # Swap mount, memory greater than 256M can also not mount
Mount/dev/hda2 $LFS # $LFS (i.e./mnt/lfs) is the hard disk file system.
The operation of the $lfs is to operate the hard disk.

Two directories are created on the hard disk, and changes made on the hard disk will not be lost after a reboot.
For example, create a directory, modify properties, and so on. Operation once.
Mkdir-v $LFS/sources
Chmod-v A+WT $LFS/sources
Set the property of the directory or file to 1777 so that anyone can read and write to it, and T is the anti-delete bit, not the owner can not delete
Mkdir-v $LFS/tools

Each reboot will require a link to be re-established as soon as the disc is started and/or the directory will lose its original changes.
LN-SV $LFS/tools/# The phrase is to create a tools soft connection under the root, pointing to the $lfs/tools directory

----------------------------------------
2.3: Create a new user LFS,
----------------------------------------
Create a new user LFS,
Compile some tools with new users instead of root, for the purpose of security of operations
The original compilation tool originated from the CD.
Compiled tools are stored in/tools (hard disk)
# Create a group
2.3.1:groupadd LFS
Where do groupadd view the output? There will be changes in/etc/group.

# Create User
2.3.2:useradd-s/bin/bash-g lfs-m-k/dev/null LFS
passwd LFS
Where do useradd view the output? /etc/passwd (user),/etc/shadow (password)


# Reset HDD Tools, sources directory owner
Chown-v LFS $LFS/tools
Chown-v LFS $LFS/sources

#切换用户
2.3.3:su-lfs

# Write the default startup script for login shell, not login shell
# usually the login shell calls. Bash_profile, not the login shell. BASHRC,
# The login shell can invoke the non-login portal.
2.3.4
Cat > ~/.bash_profile << "EOF"
EXEC env-i home= $HOME term= $TERM ps1= ' \u:\w\$ '/bin/bash
Eof

Cat > ~/.BASHRC << "EOF"
Set +h
Umask 022
Lfs=/mnt/lfs
Lc_all=posix
Path=/tools/bin:/bin:/usr/bin
Export LFS Lc_all PATH
Eof

# The method that makes immediate effect (without restarting the shell) when the startup script changes.
SOURCE ~/.bash_profile

#检查变量设置.
2.3.5 Export


############################################################
3.
After logging in with a new user, do our own thing, compile a temporary work environment
Use the host's tool (LIVECD), build your own build toolchain, and put it in the/tools directory.
There are two main points of knowledge here
A: Upgrade gcc and compile a new GCC with the existing GCC.
B: Upgrade glibc, compile glibc with GCC.
When GLIBC is updated, GCC is recompiled because GCC relies on glibc.
Notice how you can use the new GCC, the new glibc!!
Compile the other tools.
############################################################
This process is the same as the creation of a cross-compilation tool chain.
Since GCC will call LD,
------------------------------------------------------------
3.1. First compile the binutil and then compile GCC, at which point they are using the old glibc
------------------------------------------------------------
Because Binutil contains the assembler and the connector, while GCC is configured, check which assembler and connector are used.

CD $LFS/sources
Tar xvf/lfs-sources/binutils-2.17.tar.bz2
CD binutils-2.17

Mkdir-v. /binutils-build
Cd.. /binutils-build
.. /binutils-2.17/configure--prefix=/tools--disable-nls--disable-werror
Make
Make install
#接下来为编译连接器, prepare for the back "tuning Toolchain"
MAKE-C ld clean
Make-c LD Lib_path=/tools/lib #声明库路径是硬盘上的lib
Cp-v Ld/ld-new/tools/bin
Cd..
RM-RF Binutils-build
RM-RF binutils-2.17
----------------------------------------
3.2 Compiling GCC
----------------------------------------
To find out which connector GCC uses, use the following command
Gcc-print-prog-name=ld
Gcc-v DUMMY.C will display detailed information on the various stages of preprocessing, assembly, and compilation, including the search paths contained in the GCC files and their order.

Tar xvf/lfs-sources/gcc-4.1.2.tar.bz2
Mkdir-v Gcc-build
CD Gcc-build
.. /gcc-4.1.2/configure \
--prefix=/tools \
--with-local-prefix=/tools \
--DISABLE-NLS \
--enable-shared--enable-languages=c

# bootstrap, will compile 3 times, the first time to compile a new GCC, the second and third time with the new GCC compiled GCC code, the compilation results should be fully consistent to calculate the pass.
Make Bootstrap
Make install

# because some programs or scripts are compiled with CC instead of GCC, a link is built. Q, which GCC is this gcc? Answer, the system path is under GCC.
Ln-vs gcc/tools/bin/cc
Cd..
RM-RF Gcc-build
RM-RF gcc-4.1.2


----------------------------------------
3.3 Copy Linux header file, glibc compile will use kernel header file
----------------------------------------
Tar xvf/lfs-sources/linux-2.6.22.5.tar.bz2
CD linux-2.6.22.5
Make Mrproper # cleanup
Make Headers_check
Make Install_hdr_path=dest Headers_install
CP-RV dest/include/*/tools/include
Cd..
RM-RF linux-2.6.22.5

----------------------------------------
3.4 Compiling GLIBC
----------------------------------------
This glibc, is already a semi-new GCC in the compilation (/TOOLS/GCC, its path in front)
GLIBC C library includes allocating memory, searching directories, opening and closing files, reading and writing files, string processing, pattern matching, mathematical calculations, and so on. C Successful place of language
Tar xvf/lfs-sources/glibc-2.5.1.tar.bz2
CD glibc-2.5.1
Mkdir-v. /glibc-build
Cd.. /glibc-build
.. /glibc-2.5.1/configure \
--prefix=/tools \
--disable-profile--enable-add-ons \
--enable-kernel=2.6.0 \
--with-binutils=/tools/bin \
--WITHOUT-GD \
--with-headers=/tools/include \
--without-selinux
Make
Make install
Cd..
RM-RF Glibc-build
RM-RF glibc-2.5.1

During the installation of GLIBC, it warns of missing/tools/etc/ld.so.conf files. It doesn't really matter, but the following command can fix it:
Mkdir-v/tools/etc
Touch/tools/etc/ld.so.conf

----------------------------------------
3.5: Adjust the tool chain and GCC spec to test the new environment
----------------------------------------
Adjustment tool Chain: Save the old, then use the new translation,
Mv-v/tools/bin/{ld,ld-old}
Mv-v/tools/$ (gcc-dumpmachine)/bin/{ld,ld-old}
Mv-v/tools/bin/{ld-new,ld}
ln-sv/tools/bin/ld/tools/$ (Gcc-dumpmachine)/bin/ld

Fix the GCC spec file so that it executes the new dynamic connector. (question: Does gcc use spec files?)
#定义文件变量, export content, replace content, delete variables

Specfile= ' DirName $ (gcc-print-libgcc-file-name) '/specs &&
Gcc-dumpspecs > $SPECFILE &&
Sed ' s@^/lib/ld-linux.so.2@/tools&@g ' $SPECFILE > Tempspecfile &&
MV-VF tempspecfile $SPECFILE &&
Unset specfile


The advantage of using variables is to substitute filenames!
The goal is to replace all/lib/ld-linux.so.2 in the GCC specs with/tools/lib/ld-linuux.so.2.

#清理GCC INCLUDED file, this is the garbage (intermediate file) that GCC generates during the compilation process and can be deleted.
Gcc_includedir= ' DirName $ (gcc-print-libgcc-file-name) '/include &&
Find ${gcc_includedir}/*-maxdepth 0-xtype d-exec rm-rvf ' {} '; &&
RM-VF ' grep-l ' don't EDIT this FILE ' ${gcc_includedir}/* ' &&
Unset Gcc_includedir
#删除变量
Test tool chain and GCC adjustments
Echo ' main () {} ' > dummy.c
CC DUMMY.C
Readelf-l a.out | grep ' Tools '
If the output is roughly the following
[Requesting program interpreter:/tools/lib/ld-linux.so.2]
The adjustment succeeds because all libraries are connected to the/tools/lib.
RM-RF a.out dummy.c

The manual is also compiled TCL,EXPECT,DEJAGNU
----------------------------------------
3.6: Build gcc again with the new glibc
----------------------------------------
Now that the GLIBC has been compiled, the tool chain and GCC spec have been adjusted, and GCC needs to be compiled a second time, thus using the new glibc and GCC
Tar xvf/lfs-sources/gcc-4.1.2.tar.bz2
CD gcc-4.1.2
Cp-v Gcc/makefile.in{,.orig}
#禁止./fixinc.sh Script Run
Sed ' s@\./fixinc\.sh@-c true@ ' Gcc/makefile.in.orig > Gcc/makefile.in

#添加-fomit-frame-pointer Options
Cp-v Gcc/makefile.in{,.tmp}
Sed ' s/^xcflags =$/&-fomit-frame-pointer/' gcc/makefile.in.tmp > Gcc/makefile.in

# This patch removes/usr/include from the GCC search path
Patch-np1-i/lfs-sources/gcc-4.1.2-specs-1.patch

# Now start configuring and compiling
Mkdir-v. /gcc-build
Cd.. /gcc-build
.. /gcc-4.1.2/configure--prefix=/tools \
--with-local-prefix=/tools \
--enable-clocale=gnu--enable-shared \
--enable-threads=posix--enable-__cxa_atexit \
--enable-languages=c,c++--disable-libstdcxx-pch
Make
Make install
Cd..
RM-RF Gcc-build
RM-RF gcc-4.1.2

Re-check the Elf file connector should be/tools/lib/ld-linux.so.2

----------------------------------------
3.7: Compile the Binutil again with the new glibc and GCC
----------------------------------------
Tar xvf/lfs-sources/binutils-2.17.tar.bz2
Mkdir-v Binutils-build
CD Binutils-build
.. /binutils-2.17/configure \
--prefix=/tools--disable-nls \
--with-lib-path=/tools/lib
Makels
Make install
MAKE-C ld clean
MAKE-C LD Lib_path=/usr/lib:/lib
Cp-v Ld/ld-new/tools/bin
Cd..
RM-RF Binutils-build
RM-RF binutils-2.17

You can refer to the manual for more detailed work, and other tools are essential for subsequent builds.
Ncurses-5.6
Bash-3.2
bzip2-1.0.4
Coreutils-6.9
Diffutils-2.8.1
Findutils-4.2.31
Gawk-3.1.5
Gettext-0.16.1
Grep-2.5.1a
Gzip-1.3.12
Make-3.81
Patch-2.5.4.
Perl-5.8.8
Sed-4.1.5
Tar-1.18
Texinfo-4.9
util-linux-2.12r
************************************************************
Part II:
If all the temporary tools are compiled, build your own Linux system with the new tools
************************************************************
Concept:
Virtual kernel filesystem (Kernel file systems)
The kernel produces file systems that exist in memory but do not exist on the hard disk, and they are used to communicate with the kernel.
DEVFS,SHM,PROC,SYSFS are kernel file systems.
Before Udev is started, some manual device nodes and mount directories need to be created manually and then mounted manually.

Create three important directories
MKDIR-PV $LFS/{dev,proc,sys}

Device files required to create two target systems
Mknod-m $LFS/dev/console C 5 1
Mknod-m 666 $LFS/dev/null C 1 3

Using the main system to load several important file systems, please note that this step is extremely important for later work.
Mount-v--bind/dev $LFS/dev
MOUNT-VT devpts devpts $LFS/dev/pts
MOUNT-VT Tmpfs SHM $LFS/DEV/SHM
MOUNT-VT proc proc $LFS/proc
MOUNT-VT Sysfs Sysfs $LFS/sys

Chroot to the target system directory to make the target system unaffected by the main system
Chroot "$LFS"/tools/bin/env-i \
Home=/root term= "$TERM" ps1= ' \u:\w\$ ' \
Path=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
/tools/bin/bash--login +h


The env command belongs to the Coreutils package,
Chroot also belongs to the coreutils bag
/tools/bin/bash belongs to Bash pack

Establish the directory structure of the target system, it is said I this is FHS (file hierachy standard) files hierarchy
MKDIR-PV/{bin,boot,etc/opt,home,lib,mnt,opt}
MKDIR-PV/{media/{floppy,cdrom},sbin,srv,var}
grep ' search.*/usr/lib ' dummy.log |sed ' s|; |\n|g ' Install-dv-m 0750/root
Install-dv-m 1777/tmp/var/tmp
MKDIR-PV/USR/{,LOCAL/}{BIN,INCLUDE,LIB,SBIN,SRC}
Mkdir-pv/usr/{,local/}share/{doc,info,locale,man}
Mkdir-pv/usr/{,local/}share/{misc,terminfo,zoneinfo}
MKDIR-PV/USR/{,LOCAL/}SHARE/MAN/MAN{1..8}
For dir in/usr/usr/local; Do
LN-SV Share/{man,doc,info} $dir
Done
Mkdir-pv/var/{lock,log,mail,run,spool}
Mkdir-pv/var/{opt,cache,lib/{misc,locate},local}

Create several necessary links, because during the compilation of the target system, some compilers use absolute paths to find commands or files.
Ln-sv/tools/bin/{bash,cat,echo,grep,pwd,stty}/bin
Ln-sv/tools/bin/perl/usr/bin
LN-SV/TOOLS/LIB/LIBGCC_S.SO{,.1}/usr/lib
LN-SV/TOOLS/LIB/LIBSTDC++.SO{,.6}/usr/lib
LN-SV bash/bin/sh
Touch/etc/mtab

Create Root and nobody users and necessary groups
Cat >/etc/passwd << "EOF"
Root:x:0:0:root:/root:/bin/bash
Nobody:x:99:99:unprivileged User:/dev/null:/bin/false
Eof
Cat >/etc/group << "EOF"
root:x:0:
Bin:x:1:
Sys:x:2:
Kmem:x:3:
Tty:x:4:
Tape:x:5:
Daemon:x:6:
Floppy:x:7:
Disk:x:8:
Lp:x:9:
Dialout:x:10:
Audio:x:11:
Video:x:12:
Utmp:x:13:
USB:X:14:
Cdrom:x:15:
MAIL:X:34:
NOGROUP:X:99:
Eof

Reload bash so that the root user takes effect so that the preceding prompt will not be "I have no name!"
Exec/tools/bin/bash--login +h

So far, the preparation of the target system has been basically completed, the following is the start of the target system package installed.
Assuming/sources is the source directory (cp-a/lfs-sources/* $LFS/sources/), 89 packages
Export Lfs=/sources

Here is the installation list: Most of the names we are familiar with. Compiling 50
1:linux-2.6.22.5
2:man-pages-2.63
3:glibc-2.5.1
4:binutils-2.17
5:gcc-4.1.2
6:berkeley DB-4.5.20
7:sed-4.1.5
8:e2fsprogs-1.40.2
9:coreutils-6.9
10:iana-etc-2.20
11:m4-1.4.10
12:bison-2.3
13:ncurses-5.6
14:procps-3.2.7
15:libtool-1.5.24
16:perl-5.8.8
17:readline-5.2
18:zlib-1.2.3
19:autoconf-2.61
20:automake-1.10
21:bash-3.2
22:bzip2-1.0.4
23:diffutils-2.8.1
24:file-4.21
25:findutils-4.2.31
26:flex-2.5.33
27:grub-0.97e
28:gawk-3.1.5
29:gettext-0.16.1
30:grep-2.5.1a
31:groff-1.18.1.4
32:gzip-1.3.12
33:inetutils-1.5e
34:iproute2-2.6.20-070313
35:kbd-1.12
36:less-406
37:make-3.81
38:man-db-2.4.4
39:mktemp-1.5
40:module-init-tools-3.2.2
41:patch-2.5.4
42:psmisc-22.5
43:shadow-4.0.18.1
44:sysklogd-1.4.1
45:sysvinit-2.86
46:tar-1.18
47:texinfo-4.9
48:udev-113
49:util-linux-2.12r
50:vim-7.1ma
Then install the kernel and install grub, you can start with the hard disk. and has a lot of common tools.
************************************************************
Part III:
Problems encountered and solutions:
1. Make glibc-2.5.1 Error:
No gen-translit.pl < c-translit.h.in > c-translit.h.tmp
/bin/sh:no:command not found
Workaround: Perl tool N does not work because PERL-V cannot execute, although when not chroot, or
LFS users can execute Perl, do not know chroot after Perl exactly where the problem, or serious photos
Manual 5th Chapter Redo again, problem solved.
2. When make Menuconfig
Error opening Terminal:eterm-color
Workaround: I was under Emacs to open the Ansi-term remote login operation, but make Menuconfig does not support eterm
So you can only operate directly on the virtual machine, complete the Make lang=c lc_all= menuconfig operation

3. Interface eth0 doesn ' t exist
When configuring the kernel, the driver,
Added support for AMD PCnet32 PCI supports at device drivers->networking support->ethernet (100Mbit), which can be compiled into the kernel or compiled into modules

enjoy!
************************************************************

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.