LFS v8.0 – Part II (there is no Part I)

Intro

So I decided I need to be more methodical with my experiments. I would like to use this blog to post the many interests I pick up and put down. Perhaps this would allow me to pick up right where I left off.linux-from-scratch-logo-150x150

Todays obsession is with Linux, I have attempted Linux From Scratch (LFS) in the past but lost interest since I didn’t understand package compilation or dependency resolution in the past. I feel I have a better understanding these days and can not only tackle this project but organize it for my use and perhaps others.

As of now I would like to develop an automated build of the steps in LFS to comply with Configuration Management techniques. I am sure these ideas will evolve as I hit challenges I did not expect, but this sounds like fun to me.

RedHat Enterprise Linux (RHEL) is near and dear to my heart for no other reason than my time spent with it at work. So the LFS Systemd tutorial will be the reference point in these posts. The work will be done on AWS using the Amazon Linux AMI (amzn-ami-hvm-2017.03.0.20170417-x86_64-gp2) and the output will be a “pure” 64-bit system. FYI, Amazon Linux is a RHEL clone much like Centos, Oracle and Scientific Linux.

Host System Requirements

Use the bash scripts provided to test availability and versions. Since we are using a RHEL clone we have access to RPM and Yum to install all the missing packages.

sudo yum search bison
============================================================================================ N/S matched: bison ============================================================================================
bison-devel.x86_64 : -ly library for development using Bison-generated parsers
bison-runtime.x86_64 : Runtime support files used by Bison-generated parsers
bison.x86_64 : A GNU general-purpose parser generator

Choose the version and platform to install.

sudo yum install bison.x86_64 -y
sudo rpm -qa bison
bison-2.7-4.11.amzn1.x86_64

 

The next section will detail any missing packages or upgrades required to match the v8.0 LFS documentation.


Awk

or Gawk, was less then the version given listed on the Host System Requirements page. At this point we could attempt to upgrade the RPM in a few different ways, but since we are building Linux from Scratch lets dive into some Make builds.

wget -qO- https://ftp.gnu.org/gnu/gawk/gawk-4.0.1.tar.gz | /bin/tar -xvz
cd gawk-4.0.1
./configure

Configure fails since gcc is missing. Lets cheat with Yum since the package is missing and can be done easily with Yum.

sudo yum install gcc-c++ -y

Success! Back to Gawk.

sudo ./configure
sudo make
sudo make install
awk --version
GNU Awk 4.0.1

Grep

wget -qO- https://ftp.gnu.org/gnu/grep/grep-2.5.1a.tar.gz | /bin/tar -xvz
cd grep-2.5.1a/
sudo ./configure
sudo make
sudo make install
grep --version
grep (GNU grep) 2.5.1

Patch

sudo yum search patch
sudo yum install patch.x86_64 -y

Texinfo

sudo yum search texinfo
sudo yum install texinfo.x86_64 -y

Next we will look at creating the files system.

File System

Partition Disk

First step is to open fdisk.

sudo gdisk -l
sudo gdisk /dev/xvdf 
Command (? for help):

Set disk to “gpt”

Command (? for help): o

 

Disk /dev/xvdf: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0ED9BDD1-FE59-423A-8F05-CF500846D88E
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 2048-sector boundaries
Total free space is 209715133 sectors (100.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

use the “n” command to create a new partition, then take the default Number and First sector options. The Last sector is where we define the block size. In the case of the “root” partition”(not to be confused with the /root directory)”, the recommended 10GB is used.

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-209715166, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-209715166, default = 209715166) or {+-}size{KMGTP}: +10G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Follow these steps to create the partitions listed below. Be sure to take note of the Size column for size of the Last sector and the Code column for FS Types.

Note: For the last partition accept the default for Last sector to use remainder of the disk.

Command (? for help): p
Disk /dev/xvdf: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0ED9BDD1-FE59-423A-8F05-CF500846D88E
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        20973567   10.0 GiB    8300  Linux filesystem
   2        20973568        31459327   5.0 GiB     8200  Linux swap
   3        31459328        31461375   1024.0 KiB  EF02  BIOS boot partition
   4        31461376        31666175   100.0 MiB   8300  boot
   5        31666176        52637695   10.0 GiB    8300  opt
   6        52637696        63123455   5.0 GiB     8300  usr
   7        63123456        67317759   2.0 GiB     8300  tmp
   8        67317760       172175359   50.0 GiB    8300  src
   9       172175360       209715166   17.9 GiB    8300  home

To change the partition type after the fact, use “t” command and choose the partition number and code associated. In this case the code 8200 represented Linux Swap and EF02 represents the BIOS boot partition.

To change the partition Name use the “c” command.

Format File System

Now that we have partitions we can format each one to hold data.

For disks 1, 4 – 9 use the following.

 sudo mkfs -v -t ext4 /dev/xvdf#

For partition 2 use mkswap.

sudo mkswap /dev/xvdf2

Note: partition 3 BIOS boot partition does not receive a file system

LFS Variable

Add the LFS mount to bash_profile so it is available during each users session.

echo "export LFS=/mnt/lfs" >> ~/.bash_profile

Note: To limit scope this will be performed for each user and not added to “/etc/profiles”.

Mounting the New Partition

Create and mount a directory for each partition created above.

Note: The root partition must be mounted before any additional directories are created.

/

sudo mkdir -pv $LFS
sudo mount -v -t ext4 /dev/xvdf1 $LFS

boot

sudo mkdir -pv $LFS/boot
sudo mount -v -t ext4 /dev/xvdf4 $LFS/boot

opt

sudo mkdir -pv $LFS/opt
sudo mount -v -t ext4 /dev/xvdf5 $LFS/opt

usr

sudo mkdir -pv $LFS/usr
sudo mount -v -t ext4 /dev/xvdf6 $LFS/usr

usr/src

sudo mkdir -pv $LFS/usr/src
sudo mount -v -t ext4 /dev/xvdf8 $LFS/usr/src

tmp

sudo mkdir -pv $LFS/tmp
sudo mount -v -t ext4 /dev/xvdf7 $LFS/tmp

home

sudo mkdir -pv $LFS/home
sudo mount -v -t ext4 /dev/xvdf9 $LFS/home

If you are using a swap partition, ensure that it is enabled using the swapon command:

sudo /sbin/swapon -v /dev/xvdf2

Packages & Patches

Next we will store all files to build the tmp system. Lets create a folder to house the files.

sudo mkdir -v $LFS/sources

Make this directory writable and sticky

sudo chmod -v a+wt $LFS/sources

Download all of the packages and patches is by using wget-list as an input to wget.

sudo wget wget-list http://www.linuxfromscratch.org/lfs/view/stable-systemd/wget-list
sudo wget --input-file=wget-list --continue --directory-prefix=$LFS/sources

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s