Monday, October 10, 2016
My Journey to building Linux From Scratch LFS system PART3
My Journey to building Linux From Scratch LFS system PART3
CHAPTER 3
Now that we have the bootable USB flash drive, we can continue now by creating a partition onto which we will install our LFS system.
According to the book, we create a linux native partition and a swap partition using either cfdisk or fdisk.
using fdisk, I created a 40GB primary partition and a 2GB swap partition.
Now we will create a file system on the newly created partition. According to
the book, we should create an ext3 file system using the E2fsprogs
utilities. Specifically mke2fs.
#mke2fs -jv /dev/sda1where:
sda1 is my first partition.
mke2fs - is a program that creates an ext2/ext3 filesystem
- the "-j" means the create the filesystem with an
Then we initialize our swap partition.
#mkswap /dev/sda2
where: /dev/sda2 is our swap partition
To check, type blkid at the prompt, there should be an entry about /dev/sda1
and /dev/sda2
To access the partition, we mount it at /mnt/lfs.
#export LFS=/mnt/lfs -sets a variable LFS equal to /mnt/lfs
#mkdir -pv $LFS -create a directory /mnt/lfs
-"-p" means parent, "-v" means verbose
#mount -v -t ext3 /dev/sda1 $LFS
-mount our first partition to /mnt/lfs
-meaning we can access our first partition via
/mnt/lfs
note: make sure that the partition is mounted without too many restrictions
e.g. nosuid,nodev or noatime options, by using mount command.
#mount
the /dev/sda1 line should not show (nosuid,nodev,noatime)
Enable the swap partition using the swapon command
#/sbin/swapon -v /dev/sda2
Now we can download the packages and patches needed to build the basic LFS system. But since we are using the livecd as our base system, we dont need to download the packages, we just copy the packages from the /lfs-sources/ directory of the livecd to our newly created partition.
We need to create first a directory where we will install the packages and the patches.
#mkdir -v $LFS/sources
then we make this directory writable and sticky. sticky means multiple user
have write permission but only the owner can delete a file within this
directory.
#chmod -v a+wt $LFS/sources
where: a+w - means all have write access
t - means sticky
Now we download, or in our case, copy all the contents of /lfs-sources
directory to $LFS/sources.
inside /lfs-sources directory:
root[ /lfs-sources ]# cp * $LFS/sources
where: cp - the copy command
After copying the files and patches:
CHAPTER 4 - Final preparations
According to the book, we will create a $LFS/tools directory. This directory
will contain the installed programs compiled in CHAPTER 5 to separate them from the programs compiled in CHAPTER 6. The programs compiled here are temporary tools only and will not be a part of the final LFS system.
as root:
#mkdir -v $LFS/tools
then we create a /tools symlink on the host system that will point to the
$LFS/tools directory we just created
#ln -sv $LFS/tools /
the command ln above creates a link between the two files. The target file is
$LFS/tools (/mnt/lfs/tools), with a link name that is the same as the target
file and is located at the / (root) directory. The -s means create a symbolic
(or soft) link. So from the command above a soft link with a name /tools is
created that is linked to the directory $LFS/tools (or /mnt/lfs/tools).
Then we add user/group both named lfs
#groupadd lfs
#useradd -s /bin/bash -g lfs -m -k /dev/null lfs
where: -s /bin/bash : makes bash the default shell for the user
-g lfs : adds user to the group lfs
-m : create a home directory for user lfs
-k /dev/null : the skeleton directory that contains the files and
directories to be copied to the home directory.
/dev/null contains nothing. The significance of -k
option is that if it is not specified the default
/etc/skel files and directories will be copied to the
home directory.
lfs : is the name of the user
then give lfs user a password
#passwd lfs
grant user lfs ownership of $LFS/tools and $LFS/sources directory
#chown -v lfs $LFS/tools
#chown -v lfs $LFS/sources
then we login as user lfs
#su - lfs
where: su : switch user
- : start a login shell as opposed to only switch to user
lfs : switch as user lfs
then we setup a clean working environment from which building the temporary lfs system is based.
while logged in as user create two startup files, .bash_profile and .bashrc, for the bash shell.
lfs [~]$cat > ~/.bash_profile <<"EOF"
exec env -i HOME=$HOME TERM=$TERM PS1=u:w$ bin/bash
EOF
where: exec env -i.. /bin/bash -
means replace the shell with a new one with an empty environment except the variables HOME,TERM and PS1
lfs [~]$ 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
then source the just created user profile:
lfs [~]$ source ~/.bash_profile
next: CHAPTER 5
Go to link download