pax01 Posted March 26, 2015 Share Posted March 26, 2015 (edited) This is the hidden content, please Sign In or Sign Up There are so many people out there interested in Linux and how it all comes together, but so few resources to explain just that. Sure there is Linux From Scratch but that is an entire distribution with all kinds of extra programs added in. There is also the Fedora and Debian tools to make smaller and lighter versions of those distributions. But those tools keep so much hidden and automate so much. A basic Linux system need be no more than a boot loader and a kernel. That is what we would like to explore here today. How to make your own barebones Linux Build installation ? Barebones Linux Build Barebones Linux Build barebone Barebones Linux Build Barebones Linux Build Barebones Linux BuildBarebones Linux Build Goal At the end of this article we will have a working build that can be written onto a USB stick that is capable of booting into a barebones Linux Build environment. The environment should have these things: Linux Kernel Bootloader (grub) Basic Utilities (busybox) Here are some things that are needed: Computer/virtual machine running Centos 6.5 32bit 512M+ USB Stick All of these commands will be issued as root ! These are similar examples of what we are about to build but this one will be much smaller and have much less flotsam in the build. ttylinux – This is the hidden content, please Sign In or Sign Up tomsrtbt – This is the hidden content, please Sign In or Sign Up tinycore – This is the hidden content, please Sign In or Sign Up slitaz – This is the hidden content, please Sign In or Sign Up Building the Environment You need to make sure that you have some special utilities and programs available to build the sources. Additionally you will nee to make a working directory for your work. Make sure all needed packages are installed This is the hidden content, please Sign In or Sign Up Create the initial working directory structure and environment This is the hidden content, please Sign In or Sign Up Download all of the required packages into /barebones/source This is the hidden content, please Sign In or Sign Up Then Proceed to uncompress the archives we have downloaded. Uncompress This is the hidden content, please Sign In or Sign Up Building the Sources You can spend a lot of time reading up on how to tweak a kernel config. But, luckily, you do not absolutely have to do that anymore. You can build the kernel with a ‘default’ configuration that works fine in most instances. Configure and compile the kernel This is the hidden content, please Sign In or Sign Up This process has made a kernel image for you called ‘arch/x86/boot/bzImage’ which you can copy to your build directory. This is the kernel you will be booting from when you are done building. Copy kernel to build directory This is the hidden content, please Sign In or Sign Up Now for busybox. It requires us to compile it as well. Configure and compile busybox This is the hidden content, please Sign In or Sign Up This process here compiled busybox and made a binary in the _install directory, along with symlinks that point back to the busybox binary. We need to chmod the busybox binary so it is executable, and copy all of the symlinks to our build directory. It also creates ‘linuxrc’ which isn’t needed, so it should be removed. Finally, set up a symlink to point /init to busybox. Make busybox executable, copy symlinks to build directory This is the hidden content, please Sign In or Sign Up Remove linuxrc and create an /init symlink This is the hidden content, please Sign In or Sign Up Initialization Configuration When the new kernel boots up, it mounts the initrd image, then it looks for an ‘init’ to fire off. ‘init’ then runs configuration files located in /etc/init.d/ such as this one that we are going to make here. This ‘rcS’ file is executable and will: mount everything in the fstab populate the /dev directory set the hostname from /etc/hostname bring up the loopback interface Finally, we will make sure that the file is exectuable by init. Create /etc/init.d/rcS This is the hidden content, please Sign In or Sign Up ‘mount -a’ will require an /etc/fstab file for it to work. It should contain names and types of the default mount points – proc, sysfs, devpts and tmpfs. Create /etc/fstab This is the hidden content, please Sign In or Sign Up This is the file that is polled for the machine’s hostname. Create /etc/hostname This is the hidden content, please Sign In or Sign Up You can get away without having a user, but some utilities might have a hard time running. It is best to have a root user created which requires 3 files: /etc/passwd /etc/group /etc/shadow /etc/shadow is the file that passwords are stored in, so its permissions should be modified to be less permissive. This is the hidden content, please Sign In or Sign Up Library requirements Grab the libraries that you need from your host OS. In a typical build, we would have made a toolchain and built our own libraries, but for a barebones linux Build there is no need. Copy libraries to build This is the hidden content, please Sign In or Sign Up Create your initrd The final step, and the one that causes the most problems, is building your own initrd.img file. This file will be uncompressed by Linux and used as it’s operating environment. Compress initrd.img file This is the hidden content, please Sign In or Sign Up Putting it onto a flash drive We have to partition and format a flash drive, put all of these files onto it, and finally, configure grub the bootloader. You will have to partition the drive by hand! Partition and format your flash drive This is the hidden content, please Sign In or Sign Up Mount flashdrive and copy build files to it This is the hidden content, please Sign In or Sign Up Install grub bootloader onto flash drive This is the hidden content, please Sign In or Sign Up Configure grub further This is the hidden content, please Sign In or Sign Up Unmount your flash drive This is the hidden content, please Sign In or Sign Up Source && Download This is the hidden content, please Sign In or Sign Up Edited March 26, 2015 by pax01 Link to comment Share on other sites More sharing options...
Recommended Posts