Friday, June 26, 2015

My Journey to building Linux From Scratch (LFS) system PART2

cont. from part1


The book provides link for FAQ and some references. For FAQ, the link is
http://www.linuxfromscratch.org/faq/.

Since we will create our LFS system by-the-book, we are going to follow the
book chapter by chapter. Chapter 1 of the book just provides us with the
introduction, some information, references and prerequisites. The above
information are taken from chapter 1 of the book.


CHAPTER 2: Preparing the new partition.

In this chapter, it shows us the instruction in creating a partition for our
base system. In my case, I will be using the whole partition of my netbook onto which I will install my LFS system. BTW, in this journey I will be installing the system on an ACER Aspire One netbook. This netbook doesn't have a CD-ROM, hence the reason that I will be creating a bootable USB. The book states a primary partition and a swap partition is going to be created. It also states that a 1.3 GB partition (up to 2-3 GB) is enough as a primary partition.

To create a partition cfdisk or fdisk command is used, as per the book. This
means that we must be already inside our host system. For those that have a
CD-ROM drive just boot your computer using the liveCD. For those that don't
have, We need to create first our bootable USB.

At this time, I will be deviating first from the books' instruction to create my
bootable USB.

According to the live CD documentation, we should install first GRUB on our
flash drive. But no instruction is given on how to install GRUB on our flash
drive. Now the first stumbling block. But since we're here to learn, we will
going to find everything we need to know about GRUB. What is GRUB? GRUB means GRand Unified Bootloader. A bootloader is a software that first runs when the computer starts. According to GRUB's manual, there are two versions of grub, grub-legacy and grub2.

To install GRUB on our flash drive, we invoke the grub-install command. Now
this looks like we really need another linux system with grub already installed to install GRUB on our flash drive. In my case, I already have a working linux system and I use my present system, I use Kali Linux btw, to install GRUB in my flash drive. So to install GRUB:
   
    #grub-install --root-directory=/media/usb0 /dev/sdb

    where     /media/usb0 - is the mount point of my USB flash drive.
                   /dev/sdb - is the flash drive.
then create a grub.cfg file

    #grub-mkconfig  /media/usb0/boot/grub/grub.cfg

After installing grub, according to the liveCD documentation, we follow the
"BOOTING FROM ISO IMAGE" section of the documentation. It states that we copy the ISO image as a file into our drive and configure the boot loader to load "linux" as a kernel image and "initramfs_data.cpio.gz" as initrd.

"Store the ISO image of this CD as a file on a partition formatted with the
following filesystems: vfat, ntfs, ext2, ext3, ext4, jfs, reiserfs, reiserfs4,
xfs. Copy the /boot/isolinux/{linux,initramfs_data.cpio.gz} from your CD to the hard disk."

From the above instruction, we should format our flash drive with the above
mentioned filesystem and then copy the ISO image that we downloaded to the flash drive. Then after that we copy the
/boot/isolinux/{linux,initramfs_data.cpio.gz} files from the CD to our flash drive. The "hard disk" instruction above is applicable only if you want to boot from hard disk, since we are using our flash drive as a bootable device, we replace the hard disk with our flash drive.

Now to copy the files "linux, initramfs_data.cpio.gz" to our flash drive
we mount the ISO image. First we create a mount point and mount the ISO image to that mount point and then copy the aforementioned files.

 
#mkdir mount_here
#mount -o loop -t iso9660 lfslivecd.iso mount_here

where: mount_here is the mount point of our USB flash drive at the current working directory
then we can go the directory /boot/isolinux and copy the two aforementioned files to our flash drive.

After copying the ISO image and the two files, we configure the bootloader to load "linux" as the kernel image and "initramfs_data.cpio.gz" as initrd. 
From the same section above, we should pass the following as a kernel parameter.

rw root=iso:/dev/xxx:/path-to-livecd.iso rootfstype=fs_type rootdelay=20

where:     /dev/xxx - is the partition where we copy the lfslivecd.iso image
   
To configure our configuration file, we edit the created grub.cfg file to
something similar as below.

menuentry 'Linux From Scratch Live USB' {
    search --no-floppy --fs-uuid --set=root e0f3e26a-1d46-4478-9f1d- 635dd53ff488
    echo 'Loading Linux From Scratch...'
    linux     /linux rw root=iso:/dev/sdb1:/lfslivecd.iso rootfstype=ext2 rootdelay=20
    initrd    /initramfs_data.cpio.gz
}

where:    e0f3e26a-1d46-4478-9f1d-635dd53ff488 is the UUID of my USB flash                 drive.


Here is the screenshot when I boot my live USB LFS.






to be cont....







No comments:

Post a Comment