LFS using Ubuntu 14.04

Host System Requirements:
Note :Ubuntu is not compliant out of the box, copy-paste the script and run it:
you might need to install some packages which are not present in ubuntu 14.04
bhargav@Inspiron:~$sudo apt-get install texinfo gawk make sed php gcc g++

Use scripts from documentation to check for packages and librarieson your host system :

 sudo blkid -o list
bhargav@Inspiron:~$ sudo ./version-check.sh
Script code version-check.sh :
Refer documentation for scrip code.

Note : you might need to install few packages showed after running the script :

bhargav@Inspiron:~$ sudo ./library-check.sh

script code library-check.sh : Refer documentation for script code.

  • Install gmp mpfr mpc

Installation is done manually by going onto site for each package and then download and install it as shown in documentation of each package.

You might get problem while installing mpfr hence just run this command:

sudo apt-get install libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-dbg

Making a partition on disk for lfs using parted application :Note : If you are not sure how PARTED work then refer to belowlink before going forward:http://www.thegeekstuff.com/2011/09/parted-command-examples/

bhargav-Inspiron:/$ sudo parted
(parted) print free

Now look for space which is free to use and remember the start and end

size to make partition:

Note : Please re-check or make sure before running any command.
Any mistake might lead to losing your data onto disk or HD.
(parted) mkpart
Partition name?  []? lfs                                                 
File system type?  [ext2]? ext4                                           
Start? 238GB                                                              
End? 248GB                                                                
(parted) print
Model: ATA WDC WD5000LPVX-7 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start   End     Size    File system     Name                          Flags
 1      1049kB  525MB   524MB   fat32           EFI system partition          boot
 2      525MB   567MB   41.9MB  fat32           Basic data partition          hidden
 3      567MB   701MB   134MB                   Microsoft reserved partition  msftres
 4      701MB   1488MB  786MB   ntfs            Basic data partition          hidden, diag
 5      1488MB  70.1GB  68.6GB  ntfs            Basic data partition          msftdata
 6      70.1GB  238GB   168GB   ntfs            Basic data partition          msftdata
11      238GB   248GB   10.5GB                  lfs
 7      248GB   459GB   211GB   ntfs            Basic data partition          msftdata
 9      459GB   463GB   4200MB  linux-swap(v1)
10      463GB   491GB   27.3GB  ext4
 8      491GB   500GB   9412MB  ntfs            Microsoft recovery partition  hidden, diag
Format ext2 partition to ext4 partition :
bhargav@Inspiron:~$sudo blkid -o list             //this will show partition blkid
bhargav@Inspiron:~$ sudo mkfs.ext4 /dev/sda11
We will make a variable link: (OPTIONAL you can use /mnt/lfs in $LFS or viceversa)
bhargav@Inspiron:~$ export LFS=/mnt/lfs
Make directory at /mnt/ name lfs:
 
bhargav@Inspiron:~$ sudo mkdir -pv /mnt/lfs

Mounting the partition on the location of lfs directory:

bhargav@Inspiron:~$ sudo mount -v -t ext4 /dev/sda11 /mnt/lfs
/dev/sda11 on /mnt/lfs type ext4 (rw)

Make directory inside /mnt/lfs named “sources” :

bhargav@Inspiron:~$ sudo mkdir -v $LFS/sources
mkdir: created directory ‘/mnt/lfs/sources’

Give permission to /mnt/lfs/sources :

bhargav@Inspiron:~$ sudo chmod -v a+wt $LFS/sources
mode of ‘/mnt/lfs/sources’ changed from 0755 (rwxr-xr-x) to 1777 (rwxrwxrwt)

Download all the packages from site :

It includes total 77 files including patches

 ftp://ftp.lfs-matrix.net/pub/lfs/lfs-packages/lfs-packages-7.7-systemd.tar
bhargav@Inspiron:/$ groupadd lfs
bhargav@Inspiron:/$ sudo useradd -s /bin/bash -g lfs -m -k /dev/null lfs
bhargav@Inspiron:/$ sudo adduser lfs sudo
bhargav@Inspiron:/$ sudo passwd lfs
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
lfs@Inspiron:/mnt/lfs$ sudo mkdir -v $LFS/tools
mkdir: created directory '/mnt/lfs/tools'
lfs@bhargav-Inspiron-3443:/mnt/lfs$ sudo ln -sv $LFS/tools /
'/tools' -> '/mnt/lfs/tools'
lfs@Inspiron:/mnt/lfs$
bhargav@Inspiron:/$ sudo chown -v lfs /mnt/lfs/tools
changed ownership of ‘/mnt/lfs/tools’ from root to lfs
bhargav@Inspiron:/$ sudo chown -v lfs /mnt/lfs/sources
changed ownership of ‘/mnt/lfs/sources’ from root to lfs
bhargav@Inspiron:/$
bhargav@Inspiron:/$ su - lfs
Password:

Setting Up the Environment :

 lfs@Inspiron:~$ ~/.bash_profile << "EOF"
> exec env -i HOME=$HOME TERM=$TERM PS1='u:w$ ' /bin/bash
> EOF
-su: /home/lfs/.bash_profile: No such file or directory
lfs@Inspiron:~$ cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='u:w$ ' /bin/bash
EOF

lfs@Inspiron:~$ cat > ~/.bashrc << "EOF"
> set +h
> umask 022
> LFS=/mnt/lfs
> LC_ALL=POSIX
> LFS_TGT=$(uname -m)-lfs-linux-gnu
> PATH=/tools/bin:/bin:/usr/bin
> export LFS LC_ALL LFS_TGT PATH
> EOF
lfs@Inspiron:~$ source ~/.bash_profile

IMP change it back to dash to run in normal enviroment

To change symblic link of sh to bash

sudo ln -sf bash /bin/sh

Change it to dash when it is done

sudo ln -sf dash /bin/sh

Build Binutils package :

cd $LFS/sources
tar xf binutils-2.22.tar.bz2
cd binutils-2.22

mkdir -v ../binutils-build
cd ../binutils-build

../binutils-2.22/configure 
    --target=$LFS_TGT --prefix=/tools 
    --disable-nls --disable-werror

make

case $(uname -m) in
  x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
esac

make install

cd $LFS/sources
rm -rf binutils-build binutils-2.22

Buils GCC package:

cd $LFS/sources
tar xf gcc-4.6.2.tar.bz2
cd gcc-4.6.2

tar -jxf ../mpfr-3.1.0.tar.bz2
mv -v mpfr-3.1.0 mpfr
tar -Jxf ../gmp-5.0.4.tar.xz
mv -v gmp-5.0.4 gmp
tar -zxf ../mpc-0.9.tar.gz
mv -v mpc-0.9 mpc

For futher steps visit my old blog where I have written all the remaining steps :

http://bhargavamin7.blogspot.com/2015/07/lfs-using-ubuntu-1404.html

Blogger & Assc Cloud Architect

Site Footer