Raspberry Pi (Raspberry Pi) builds a Linux system (PiLFS) from scratch (I), raspberrypilfs

Source: Internet
Author: User
Tags gparted

Raspberry Pi (Raspberry Pi) builds a Linux system (PiLFS) from scratch (I), raspberrypilfs

I. Preparations

1. Raspberry Pi motherboard with Linux host system installed, refer to Raspberry Pi (Raspberry Pi) to install Raspbian (no router, no Monitor)

2. Reference URL: Linux From Scratch on the Raspberry Pi

3. Reference URL: Linux From Scratch Version Development

 

Ii. Target architecture of PiLFS

PiLFS mainly supports the target architecture of ARM (64-bit.

If it is built by default in this article, you will get a "pure" 64-bit system-this means that you can only execute 64-bit programs.

 

Iii. host system requirements

1. If the host system is Raspbian, set the root password,And log on as the root user.

sudo passwd root
su - root

2. Run the following command to check whether the software packages of the host machine and the compiling environment are ready:

cat > version-check.sh << "EOF"#!/bin/bash# Simple script to list version numbers of critical development toolsexport LC_ALL=Cbash --version | head -n1 | cut -d" " -f2-4MYSH=$(readlink -f /bin/sh)echo "/bin/sh -> $MYSH"echo $MYSH | grep -q bash || echo "ERROR: /bin/sh does not point to bash"unset MYSHecho -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-bison --version | head -n1if [ -h /usr/bin/yacc ]; then  echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";elif [ -x /usr/bin/yacc ]; then  echo yacc is `/usr/bin/yacc --version | head -n1`else  echo "yacc not found" fibzip2 --version 2>&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  echo awk 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 -n1make --version | head -n1patch --version | head -n1echo Perl `perl -V:version`sed --version | head -n1tar --version | head -n1makeinfo --version | head -n1xz --version | head -n1echo 'int main(){}' > dummy.c && g++ -o dummy dummy.cif [ -x dummy ]  then echo "g++ compilation OK";  else echo "g++ compilation failed"; firm -f dummy.c dummyEOFbash version-check.sh
View Code

A. if the host system is Raspbian, you will find that four packages are missing. Use the command line to add:

apt-get updateapt-get install bison gawk m4 texinfo

B. At the same time,/bin/sh points to dash and uses the command line to modify the point to bash:

ln -sf bash /bin/sh

3. At the same time, check the consistency of database files. These files should be either present or missing, rather than one or two files.

cat > library-check.sh << "EOF"#!/bin/bashfor lib in lib{gmp,mpfr,mpc}.la; do  echo $lib: $(if find /usr/lib* -name $lib|               grep -q $lib;then :;else echo not;fi) founddoneunset libEOFbash library-check.sh
View Code

If the host system is Raspbian, these library files are missing and you don't need to worry about it.

 

4. Create a New Partition

1. Install the partition tool gparted in the host system. command:

apt-get install gparted

2. Use gparted to re-divide the TF card and draw an LFS system partition. My TF card is divided:

/Dev/mmcblk0p1 64 M FAT32 boot Partition

/Dev/mmcblk0p2 16.9G EXT4 host system partition

/Dev/mmcblk0p3 2G Swap Partition

/Dev/mmcblk0p4 10G EXT4 LFS system partition

 

5. Mount new partitions

Export LFS =/mnt/lfsmkdir-pv $ LFS mount-v-t ext4/dev/mmcblk0p4 $ LFS # If you are using swap partitions, run the swapon command to ensure that/sbin/swapon-v/dev/mmcblk0p3 is enabled.


Vi. software packages and patches

1.rootThe user executes the following command to create$ LFS/sources directory

mkdir -v $LFS/sources

2. Set the directory write permission and sticky Mode

chmod -v a+wt $LFS/sources

"Sticky mode" means that even if multiple users have write permission on a directory, only the owner of the file can delete the files in a sticky directory.

3. download the software packages and Patches required to build PiLFS

wget http://www.intestinate.com/pilfs/scripts/wget-listwget -i wget-list -P $LFS/sources


VII. Final preparations

1. Create a $ LFS/tools Folder

# Run the following command as a root user: # The compiled temporary tool will be installed in the $ LFS/tools Folder and will not become part of the final LFS system. Mkdir-v $ LFS/tools

2. Create/toolsTo point to $ LFS/tools.

# Run the following command as a root user: # The created Symbolic Link always points to the/tools Folder. Ln-sv $ LFS/tools/

3. Add an lfs user

# Run the following command as the root user to add new groups and new users: # When a root user logs on, a small error may damage or destroy the entire system. Groupadd lfs # Add new group useradd-s/bin/bash-g lfs-m-k/dev/null lfs # Add new user passwd lfs # Set the password chown-v lfs for the user $ LFS/tools # grant all permissions to access the $ LFS/tools Folder chown-vR lfs $ LFS/sources # grant all permissions to access the $ LFS/sources folder and sub-files su- lfs # Switch users

4. Set the environment

# Log On As an lfs user and run the following two commands to create two startup files for bash shell. # When logging on as an lfs user, the initial shell is usually a logged-on shell # It first reads the/etc/profile file of the host (probably including some settings and environment variables), and then. bash_profile file #. the bash_profile file replaces the running shellcat with a completely empty shell> ~ /. Bash_profile <"EOF" exec env-I HOME = $ HOME TERM = $ TERM PS1 = '\ u: \ w \ $ '/bin/bashEOF # The new shell instance is a non-Logon shell and does not read/etc/profile or. the bash_profile file is read. bashrc file cat> ~ /. Bashrc <"EOF" set + humask 022LFS =/mnt/lfsLC_ALL = POSIXLFS_TGT = $ (uname-m)-lfs-linux-gnueabihfPATH =/tools/bin: /usr/binexport LFS LC_ALL LFS_TGT PATHEOF # enable the configuration file source ~ /. Bash_profile
View Code

 

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.