Customizing a RepairDisk: The Road to LFS

Many are the times that we have had to repair a system from a LiveCD, and at some point in the process we have found ourselves lacking a tool and when we want to install it, the LiveCD OS tells us that it has run out of space and garlic and water ( to screw and hold).

This problem has really come to me because of going into LFS (LinuxFromScratch), which is a guide (NOT a distribution itself) to install a custom Linux. The point of this "distribution" is that from any LiveCD, and with the appropriate tools, you download the kernel code and other tools to build your own system (compiling everything little by little). If you want to follow the step-by-step guide, you need several tools and compilers, and there is no liveCD with everything, so you have to customize one.

Let's do it. We will use the SystemRescueCD, which offers a fairly comprehensive Gentoo-based environment.

In our example (installing a Linux from scratch following the Linux From Scratch book) we are missing the Bison and Makeinfo programs, so we are going to create a new ISO image of this disk but with the new tools.

NOTICE: Gentoo is a distribution that compiles , all packages to be installed, therefore the process of adding and updating programs is slow.

Although a package manager is used (like Debian's apt-get), instead of downloading packages, the source code is downloaded to compile it on your machine.

For the process you will need a Linux partition (ext4 for example) with at least 1.5G free, although more is recommended. If you don't want to fiddle with your partitions, make use of a virtual machine. Of course, it is advisable that the partition have several gigs since during the compilation, installation, synchronization of repositories ... temporary space is needed; I advise using an 8G + 2G swap partition (with 4G + 1G it should be enough, but so we can assure you, if RAM / swap is missing the process will be even slower).

Assuming you have created a virtual machine with a 10G disk, you start it by telling it to boot from the newly downloaded SystemRescueCd. Once inside we partition with fdisk (if you have started the graphical session you can do it with gparted, but the purpose of this post is to teach the use of basic tools). fdisk is an interactive command:

  • with the option "n" we create a new partition
  • with the option "t" we change the type of filesystem that will go in the partition
  • with the option «w» we write to the disk
  • with the option «q» we leave without writing the changes

When we use the "n" option it will give us several options, all the time we will use default, except when setting the last sector in the first partition, which we will have to write "+ 8G", thus indicating to the program that we want our partition occupy 8GB.

When creating the second partition we will use the default options since the rest of the space will be occupied. Also, to tell fdisk that the second partition will be of type swap, use the "t" option (the hexcode for swap is 82). The interface looks like this:

% fdisk / dev / sda Command (m for help):

Once everything is done, we use the "w" option to write the changes to disk and exit.
Now it's time to format the partitions. We will start with the swap in order to make use of it immediately:

% mkswap / dev / sda2% swapon / dev / sda2

We already have the swap partition formatted, and with the command swapon we have started using it. Now we format the first partition in ext4:

% mkfs.ext4 /dev/sda1

We can start to follow the steps described in http://www.sysresccd.org/Sysresccd-manual-en_How_to_personalize_SystemRescueCd, here I translate / describe them with the odd annotation.

We mount the partition in its place (the LiveCD already comes prepared with a folder / mnt / custom where the partition in which we will make the appropriate changes must be mounted). Also after mounting we will have to extract the files from the disk, this is achieved with a script that is already prepared. The script will take a while (since it dumps hundreds of megabytes of memory), if you want to check that it is actually working, go to another terminal (with Alt + F4 for example) and do a df -h.

% mount / dev / sda2 / mnt / custom% / usr / sbin / sysresccd-custom extract

If you now navigate within / mnt / custom / customcd, you will see several folders. In / mnt / custom / customcd / files the root filesystem is found. Now it's time to chroot the future new system. Here I am going to put the commands, for more information about chroot you can see this tutorial I wrote a month ago

% mount -o bind / proc / mnt / custom / customcd / files / proc% mount -o bind / dev / mnt / custom / customcd / files / dev% mount -o bind / sys / mnt / custom / customcd / files / sys% chroot / mnt / custom / customcd / files / bin / bash # gcc-config $ (gcc-config -c)

We are already in the chrooted system, which will be the LiveCD system once we boot it. We will install the missing packages (bison and texinfo) using the command emerge (who handles the parcel of porterage from gentoo).

First we synchronize the portage tree (the equivalent of apt-get update)
# emerge-webrsync NOTE: we use this command instead of "emerge –sync" because it is faster, since it downloads a tar pack from the web. This step is necessary, because if you don't emerge it will automatically emerge –sync, slowing it down.

After synchronizing the portage tree we can proceed to install the packages:

# emerge sys-devel / bison # emerge sys-devel / texinfo
bison will take a while to compile, be patient

We leave chroot:# exit

We unmount "/ proc" so that the new installed packages are stored in squashfs. We also unmount "/ dev" and "/ sys" so that we don't forget later
% umount /mnt/custom/customcd/files/proc
% umount /mnt/custom/customcd/files/dev
% umount /mnt/custom/customcd/files/sys

As we already have the new squash file system prepared, we create it with the following command
% /usr/sbin/sysresccd-custom squashfs
If we want to add a file in the ISO image but we want it to be outside squashfs, we must put it in the folder «/ mnt / custom / customcd / isoroot»

% cp -a my-files /mnt/custom/customcd/isoroot

At this point, the official guide tells you that you can set the keymap to boot with a default keyboard (for example "es" for Spanish keyboards). But doing several tests, the script they use for me has not worked and it resulted in an error when loading the kernel, so I will skip this step.

The glorious moment has arrived, we can now generate the new ISO image with our customized system!
% /usr/sbin/sysresccd-custom isogen my_srcd
"My_srcd" is the name we give to the volume, you can call it whatever you want. The image is saved in «/ mnt / custom / customcd / isofile», in addition an .md5 file is also generated 🙂

If you are working on a virtual disk, the crucial step remains: extract the ISO image of the virtual system. There are several ways to do it, I will explain a simple one (in VirtualBox) to avoid having to install "guest additions" or anything like that.
We will use the client to obtain the file through an ssh tunnel. To do this, we must first configure the guest system with a root password. The ssh server starts automatically, we still restart it just in case.
% passwd
% /etc/init.d/sshd restart

We have to configure the port forwarding of the virtual machine. In VirtualBox it is done as follows:

  1. You access the virtual machine configuration
  2. In the network section you have already configured an adapter in NAT
  3. Look for the port forwarding option
  4. You add a new rule, with the only parameters "host port" and "guest port"
  5. host = 3022 and guest = 22

With this we have achieved that port 3022 of our PC is 22 of the virtual machine. We start the Filezilla client:

  1. In the server parameter we write: sftp: // localhost
  2. In the username parameter we write: root
  3. In the password parameter we put the one we use in «passwd»
  4. In the port parameter we write: 3022
  5. Click on «Quick connection»

If everything has gone well to the left we can navigate on our PC and to the right in the virtual machine. All you have to do is access (in the virtual machine) the folder "/ mnt / custom / customcd / isofile" and drag the ISO image to the place you want on your PC.

!! Congratulations!! If everything went well, you have your ISO image ready with a customized SystemRescueCD and ready to boot from a CD, USB ...


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Leo said

    What a good guide, somewhat complicated but very useful.
    Good contribution.

  2.   Leper_Ivan said

    Then with a little more time, and without so much discomfort in the eyes, I will read it thoroughly. It seems very useful and interesting.

  3.   Carlos Sanchez said

    Hello woqer, very good post!

    I have been with LFS for some years and I have created my own iso that can serve you, it has everything you need to compile since it is an LFS. 😀 I hope it is useful to you

    http://vegnux.org.ve/files/isos/neonatox-06.2rc6.linux-i686-xfce4.iso