minilinux

    Lyric part

    Which of us in childhood did not make out toys to see what was inside there. I was no exception. It took only a few years, and Linux became one of the toys. From an abstract desire to “break and see”, it was formalized into several very specific tasks, one of which was to find a starting point - the minimum something that would load and give a shell. A couple of times I started collecting lfs, but I never got to the end. I read several articles about the development of embedded, but everything was too serious and adult-like: after the proposals to build an environment for cross-compilation for various architectures and remote debugging, I turned off the Internet in a panic. I reviewed a few mini-livecd, but all of them are either megadecimal (kernel 2.4 and lower) or necessarily with graphics and DE,
    And not so long ago, I accidentally found out that what I'm looking for is called initramfs and lies under my nose.

    HOWTO part

    Let us set ourselves the task of getting a small, cozy and, preferably, something useful distribution, without any special effort. By and large, we need a loader, a kernel and an initramfs image. The easiest way to get them is to get them out of the distribution kit. In order to make it at least somehow useful, insert a busybox there and configure several network services. I'll show you how to do this with CentOS, but in principle, anyone will do. So, let's start:

    Unpack somewhere initrd: Install and copy busybox to our mini-Linux (busybox does not link to anything, so copy it safely)
    mkdir /root/myimage
    cd /root/myimage
    gzip -d < /boot/initrd-2.6.18-128.el5 | cpio --extract --verbose --make-directories --no-absolute-filenames



    yum install busybox
    cp -a /sbin/busybox /root/myimage/bin


    We leave in init only the most necessary minimum: create procfs and sysfs, the main device files, load the necessary drivers (for my network, I needed to copy them from the / lib of the main distribution) and run a couple of services. Here:

    / init / etc / passwd /etc/inetd.conf We collect initramfs and return to the place: Voila. Our mini-Linux is ready. You can demolish everything except the / boot directory and reboot. But for greater reliability, we transfer it to a USB flash drive: Let's say a flash drive is defined by the kernel as / dev / sdb. There is only one fat section on it. Using fdisk, make it bootable. Check if the asterisk is in the boot column. If not, press a, and then w. We mount the flash drive somewhere and copy / boot to it

    #!/bin/nash

    mount -t proc /proc /proc
    mount -t sysfs /sys /sys
    mount -o mode=0755 -t tmpfs /dev /dev
    mkdir /dev/pts
    mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
    mkdir /dev/shm
    mknod /dev/null c 1 3
    mknod /dev/zero c 1 5
    mknod /dev/systty c 4 0
    mknod /dev/tty c 5 0
    mknod /dev/console c 5 1
    mknod /dev/ptmx c 5 2
    mknod /dev/rtc c 10 135
    mknod /dev/tty0 c 4 0
    mkblkdevs
    insmod /lib/libphy.ko
    insmod /lib/tg3.ko
    mkblkdevs
    echo WELCOME!!!
    /bin/busybox ln -s /bin/busybox /bin/ash
    /bin/busybox ln -s /bin/busybox /bin/telnetd
    /bin/busybox ifconfig eth0 192.168.1.1 netmask 255.255.255.0
    /bin/busybox httpd
    /bin/busybox inetd /etc/inetd.conf
    /bin/ash



    root:x:0:0:root:/:/bin/ash


    23 stream tcp nowait root /bin/telnetd telnetd -l /bin/ash


    find . | cpio -H newc --create --verbose | gzip -9 > /boot/initrd-2.6.18-128.el5



    fdisk /dev/sdb



    mount /dev/sdb1 /mnt
    cp -a /boot /mnt
    umount /dev/sdb1


    Using grub, we rewrite the boot sector of the flash drive here I made the assumption that grub “saw” the flash drive as disk 2. If it is not, find will throw an error (it will not find / boot). Look at the result of find (hd2,0) ... find (hd3,0) ... etc. until you find a flash drive.
    grub
    >find (hd1,0)/boot/grub/stage2
    >root (hd1,0)
    >setup (hd0)
    >quit




    Total

    That's it. We reboot, turn on the boot from removable media in the BIOS, and we get the command prompt of our mini-Linux. We also try to connect to the 192.168.1.1 telnet client and open 192.168.1.1/init in the browser. If someone is inspired by the topic of creating his own small distributor, here are some directions for further research:
    - Look at busybox utilities. There are many useful network services: http, dhcp, tftp, smtp, tod, inetd. From tar + gzip + ftpput we get a great “unattended backup”. There is also a lot of utilities for working with FS, which will allow you to create your rescue cd.
    - Identify more devices. As you probably noticed, I threw out all disk device drivers and fs from the init script. ABOUT!!! And by the way, hotplug and USB drivers are also disabled, so if you have a usb keyboard, first and foremost return them to their place.
    I hope this article is helpful to someone.

    Also popular now: