First, Introduction
Lfs──linux from Scratch, is a kind of direct download from the Internet source code, from the beginning to compile Linux installation method. It's not a release, it's just a recipe that tells you where to go to buy food (download source code), how to make these raw things into a taste of their own dishes-personalized Linux, not just the personality of the desktop.
Reference: http://www.linuxfromscratch.org/
Http://www.ha97.com/book/lfs-book-6.6/index.html
Http://xxb.is-programmer.com/2008/3/26/LFS-8.1730.html
http://sinojelly.blog.51cto.com/479153/201337/
Second, the Environment preparation
The following environmental checks are required to use the Debian platform:
1. Check the required tools and kernel version numbers to see if they meet the lfs7.7 list requirements
2, check the need to use the library, a total of three, GMP, MPFR and MPC
The tool check script is as follows:
#filename: check_env.sh
#/bin/SHExport Lc_all=C # Check forBashbash--version |Head-n1 |Cut-D" "-f2-4Echo "/bin/sh, ' readlink-f/bin/sh '"Echo-N"Binutils:";LD--version |Head-n1 |Cut-D" "-f3-Bison--version |Head-n1# Check forYACCif[-H/USR/BIN/YACC]; Then Echo "/usr/bin/yacc, ' readlink-f/usr/bin/yacc '";elif[-X/USR/BIN/YACC]; Then EchoYACC is '/usr/bin/yacc--version |Head-N1 'Else Echo "Yacc not found"fi# Check for Otherbzip2--version2>&1</dev/NULL|Head-n1 |Cut-D" "-F1,6-Echo-N"coreutils:";Chown--version |Head-n1 |Cut-D")"-F2diff--version |Head-N1Find--version |Head-N1gawk--version |Head-N1if[-h/usr/bin/awk]; Then Echo "/usr/bin/awk, ' readlink-f/usr/bin/awk '";elif[-x/usr/bin/awk]; Then EchoYACC is '/usr/bin/awk--version |Head-N1 'Else Echo "awk not found"fiGCC--version |Head-n1g+ +--version |Head-n1ldd--version |Head-n1 |Cut-D" "-f2-# glibc Versiongrep--version |Head-N1gzip--version |Head-N1Cat/proc/VERSIONM4--version |Head-N1 Make--version |Head-N1Patch--version |Head-N1EchoPerl 'Perl-v:version 'sed--version |Head-N1Tar--version |Head-N1makeinfo--version |Head-N1xz--version |Head-N1Echo "main () {}"> dummy.c && g++-o dummy dummy.cif[-X dummy]; Then Echo "g++ compilation OK";Else Echo "g++ Compilation failed";fiRM-F dummy.c Dummy
If the result is as follows, the environment is ready
If "Command not Found" appears, the tool is missing and can be installed with the following command (for example, installing the Gawk tool)
sudo Install gawk
The Library check script is as follows:
#filename: check_lib.sh
#!/bin/bashfor on do echo $lib: $ ( if Findgrepthen :; Else Echo Not ; fi ) found Done unset Lib
The results show that three libraries do not currently have a
Third, storage equipment preparation
LFS compilation needs to have a separate piece of storage, the condition is not good on a separate partition, the condition is better to hang a block of hard disk, really do not create a new directory to do this thing, but this is not able to guide up, only chroot after the compilation environment.
The following is a new SATA hard drive with VMware , then access the virtual machine, partition, mount as an example to describe this process.
Click "Edit Virtual machine settings" and select Add hard drive, such as:
Select "SATA (A)" and click "Next", such as:
Select "Create a new Virtual disk" and click "Next", such as:
Set the disk size to: 20G, then select "Save Virtual disk as a single file" and click "Next", such as:
Click "Done", such as:
Click "OK", such as:
Start the virtual machine and execute the following command to view the new drive information
ls grep SD
The new hard drive is SDB, such as:
After executing the following command, select "New" to create a new partition, such as:
Cfdisk/dev/sdb
SELECT [Primary] to create a new primary partition, such as:
Tip size (in MB), select the size of the partition you want to create: 128, such as:
SELECT [Beginning] to add a partition in the starting position of the free space, such as:
Select [Bootable], enter, create a new section above this column the Flags field will appear with the boot word, such as:
The arrow key presses down and the cursor selects "Free Space" to create the swap partition. Basically repeat the steps just now, but the size is changed to 1024, do not need to set the boot logo.
Move the cursor to [type], change the file system type, enter after entering the type selection menu, the number default input is 82, that is, "Linux swap/solaris", directly enter the
At this point back to the main menu, you can see the second partition sdb2 "FS Type" is changed to "Linux Swap/solaris", such as:
Press the arrow key down, select Free Space, repeat the SDB1 creation step, type SELECT [Logical], size default maximum, no need to change, such as:
When you return to the main menu, you can see that the Name column shows SDB5, such as:
The new hard disk partition table is completed, need to write to the hard disk, move the cursor to [write], enter, such as:
Tip "is sure you want to write the partition table to disk? (yes or No): ", hit" Yes "and enter, such as:
Right-move the cursor to [quit] to enter and exit Cfdisk, such as:
Now that the partition is complete, the isolated storage devices and partitions required by LFS are ready, such as:
Iv. disk initialization and source preparation
The following steps are required to format the partition:
/DEV/SDB1 use Ext2 to perform the following commands, such as
Mkfs-v-T EXT2/DEV/SDB1
/DEV/SDB2 use swap to perform the following commands, such as
Mkswap/dev/sdb2
/DEV/SDB5 use EXT4 to perform the following commands, such as
Mkfs-v-T EXT4/DEV/SDB5
Execute the following command to create the directory:/mnt/lfs
mkdir -pv/mnt/lfs
For convenience, change the owner of the/mnt/lfs directory to the current user, otherwise add sudo to each operation and execute the following command
Chown -R Lenovo. sudo lfs/
Mount the primary storage partition/DEV/SDB5 of the LFS project to this directory
Mount -v-t ext4/dev/sdb5/mnt/lfs
Each time the host system restarts, you need to re-export and mount, for convenience, execute the following command to create the environment variable $lfs=/mnt/lfs
VI ~/.BASHRC
#在文件尾添加如下内容
Export Lfs=/mnt/lfs
Execute the following command to make the environment variable effective immediately
SOURCE ~/.BASHRC
At this point we can download and compile the LFS components we need on the $lfs.
Below, create a new directory to store the source code, and download the source code
mkdir $LFS/SRCCD $LFS/src
wget http://www.haopingrui.cn/lfs.tar.gz 124e1eb0e52f176ab84c38118b4975e3
At this point, the partition and source are ready to complete.
Five, tool chain compilation
In order to avoid the use of large account misuse caused the host loss, first, create a new LFS user
Set a password for user LFS
Add environment variables for user LFS
VI ~/.BASHRC
Add the following at the end of the file
Home=$HOMETERM=$TERM #ps1= ' ${debian_chroot:+ ($debian _chroot)}\[\033[ on; 31m\][\a]\[\033[ on; 33m\]\u\[\033[00m\]@\[\033[ on; 32m\]\h:\[\033[ on; 34m\]\W\[\033[00m\]$ ' Set+Humask022LFS=/mnt/Lfslc_all=posixlfs_tgt=$(uname-m)-lfs-linux-Gnupath=/tools/bin:/bin:/usr/binexport LFS lc_all lfs_tgt PATH
Execute the following command
SOURCE ~/.BASHRC
Finally, add the user lfs to the sudo group to get permission to execute sudo
sudo sudo lfs
After creating a directory and establishing a soft link, change the file owner, execute the following command
mkdir -v $LFS/toolssudo ln-sv $LFS/tools/toolssudochown -rv LFS $LFS/src
Unzip and move files to directory $lfs/src/
cd/mnt/lfs/srctar -zxvf lfs. Tar . GZ MV $LFS/src/lfs/* $LFS/src/
Next, the tool compiles
Compiling binutils
TarJXVF binutils-2.25.Tar. BZ2CD binutils-2.25mkdir-V. /binutils-BUILDCD ./binutils-build/.. /binutils-2.25/configure--prefix=/tools--with-sysroot= $LFS--with-lib-path=/tools/lib--target= $LFS _tgt --disable-nls--disable-werrormake case $ (uname in mkdirLn -sv lib/tools/lib64;; Esac Make Install
LFS (Linux from Scratch) learning