Sooner or later, every Linux user will think about creating their own distribution. Some argue that “everything can be customized.” Others complain that among the distributions already presented in Vetka there is no ideal. And they, supposedly, have superconceptual ideas for their own system. Why did I start all this psychology? In order to immediately turn off the oxygen playing to Linux for beginners who have nothing to do. If you really think about the creation of the OS, think to the end. So,
I want to create a Linux based OS.
Immediately I warn you: there would be the XVIII century, all those who choose another developed distribution kit for the basis of their future system (and, God forbid, a popular one ...) would be waited for by the gallows. The post about the creation of the system from scratch, which means that we will not touch any Slax and Linux Mint.
Step 1. Media selection
There are few options: either your OS starts from the LiveCD, or from a hard disk, or from a flash device. Immediately make a reservation: I will not say a word about the hard disk in the post, because it is much more convenient to create a flexible distribution kit from the “all my burden with myself” series, or a locked distribution kit on an optical disc. If you learn how to create a LiveCD or LiveUSB system, there will be no problem installing it on the hard disk.
Just in case, prepare a clean flash drive, CD-ROM, and finally install Virtualbox.
')
Step 2. Compile the kernel
Regarding the release of the third Linux kernel, this step inspires further development ... So, we need kernel sources. Every user knows that they can be obtained on kernel.org. In no case, do you hear ?, never screw an extraneous core, not compiled by you, on your system!
Since my laziness is too high, I created the / linuxkernel folder and unpacked the archive with the source code there. Logged in as root, I did the following:
cd /linuxkernel
make menuconfig
In principle, the kernel can be configured in three ways: make config (dialog configuration), make menuconfig (pseudo-graphical configuration via ncurses), and make xconfig (graphical configuration). The bottom line is that make config will ruin your mood for a long time, because He will ask all possible questions on all aspects of all topics. The problem with make xconfig is not found at all, but here I have met and is found. If itch to do through X, sort it out yourself. The best option is make menuconfig. This piece will open you a pseudo-graphic interface through which you can configure the kernel in your own way. Stuck requires the ncurses library, which is easy to install.
Basically, if your brain understands Linux at all, you will understand configuration. The process is interesting, there are really a lot of options, and the help, although in English, is still pleasing for its accessibility and simplicity.
However, you still have to send. Go to File Systems ---> and put the necessary asterisks. The letter M means that support of a driver is carried out by connecting to the kernel of an external module (I hate them!). We will also need isofs support for reading discs. File Systems ---> CD-ROM / DVD Filesystems ---> ISO 9660 CDROM file system support. You can still support the ancient yos systems.
The real Mandriva developers forgot to allow File systems ---> DOS / FAT / NT Filesystems ---> NTFS write support, and on one of their distributions I was tormented with access to the Old Windward section.
Look at the Processor type and features ---> Processor family, I was recommended to choose the Pentium-MMX.
Still rummage in Device Drivers, it is useful. You can make jokes for the sake of everything there and compile a kernel weighing> 50 MB.
Further. After loading the kernel itself, the system should load itself. Either of the files compiled in themselves (used in embedded systems), or from the CPIO archive compressed with something, or from the Initrd. Here you are not DOS, here it will not be possible to immediately refer to any init file in the root directory of a disk or flash drive.
Actually succeed, do not listen to Uncle Annix! This is wrong, even though on the Internet there is already a sickly controversy on this issue. In our system we will use the initrd, because this is convenient and will not cause obscene expressions from third-party developers, unlike the CPIO archive.
Oh yes, compile the kernel with the command
make bzImage
If you have x86, find it at / linuxkernel / arch / x86 / boot / bzImage.
For severe Chelyabinsk programmers, you can use Cross-compiling ...
Creating a ramdisk.
Now we need an initrd with the simplest shell installed there. We will use busybox, because this nyasha can do anything. The way we steal from Roberto de Leo, the creator of Movix (I would even begin to respect him, if not for the transcendental love of Perl):
dd if=/dev/zero of=/dev/ram0 bs=1k count=5000 - Ramdisk .
mke2fs -m0 /dev/ram0 5000 - Ramdisk Ext2
mkdir /distro -
mount /dev/ram0 /distro - /distro
Everything, now we have a Ramdisk, with a capacity of 5 MB. It is possible and more, just not necessary. Unlike Thomas Metajisek, I am not going to stuff initrd modules in Squashfs compressed with LZMA. All that is needed will be compiled with the kernel. Yes, this is not very logical and correct, but the hassle is a hundred times less. And especially for those who condemn this approach, you can enable the modularity option in the kernel: Enable loadable module support.
In our Ramdisk, mounted in / distro, there is such a folder, lost + found. This is because we formatted it in ext2. In no case can not remove it, although it is unlikely to help here, the image is fixed. We would have to put the busybox first ...
Install Busybox
That is why such cool projects have such slop sites? Although ... this is not the point anymore if the sources are downloaded and successfully unpacked into the / busybox folder.
You can configure busybox in the same way:
cd /busybox
make menuconfig
If you still do not understand what it is, I will explain. Busybox replaces tons of UNIX applications stored in folders / bin, / sbin, / usr / bin, / usr / sbin. Instead, only one application is created: / bin / busybox, and a bunch of links are created to it in the above folders. Install busybox with the following command:
make CONFIG_PREFIX=/distro install
Also, Busybox will create files / sbin / init and for some reason / linuxrc so that your system starts up correctly. But not all the necessary folders were created. So we finish everything with our hands and create:
/distro/etc
/distro/lib
/distro/dev
/distro/mnt
distro/proc
/distro/root
/distro/tmp
/distro/root
If you forgot something, remember, because These directories are hard to forget.
Everything is good, but only busybox requires a library to work, which need to be copied to our distribution. It is very easy to find out which:
ldd /distro/bin/busybox
The program will show us the libraries required for our shell. Immediately I say: linux gate is created by the kernel and cannot be copied.
When copying libraries, debugging information can be cut off (as Roberto advises):
objcopy --strip-debug
Making Linux from Linux
You need to create several system text files:
We need / etc / inittab. I will surprise you: at the beginning of life, the system does not even know what Root is. We even have a nameless user, but here the file of system-wide low-level features (ONF) must be present. The pilot file content is as follows:
::sysinit:/etc/rc.d/rc.S
# .
::respawn:-/bin/sh
# Ctrl+Alt+Del.
::ctrlaltdel:/sbin/reboot
# , .
::shutdown:/sbin/swapoff -a >/dev/null 2>&1
::shutdown:/bin/umount -a -r >/dev/null 2>&1
The next file is / etc / fstab. This is a table that describes what and where to mount at boot.
A useless thing! We need to mount the proc, otherwise it will not work at all, so we write in the file:
none /proc proc defaults 0 0
For mount, you also need the / etc / mtab file. Create it and leave it empty.
But mount will do everything necessary only when we explicitly ask him about it. And we will ask in the very first /etc/rc.d/rc.S file (rc.d - folder). Politely ask:
#!/bin/ash
/bin/mount -av -t nonfs
We also need a profile file (b) (a) sh, there is generally freedom for fantasy. Create the file / etc / profile and fill in the following:
PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:"
LESS=-MM
TERM=linux
HOME=/root
PS1='> '
PS2='> '
ignoreeof=10
export PATH DISPLAY LESS TERM PS1 PS2 HOME ignoreeof
You will also need the / etc / shell file, which indicates that there is a shell:
/bin/sh
/bin/ash
/bin/bash
That's all. You can write our Ramdisk to a file.
mkdir /os - "".
umount /dev/ram0 - .
dd if=/dev/ram0 of=/os/initrd bs=1k count=5000 - .
gzip /os/initrd - initrd
Creating a bootable flash drive
"Finishing line" of our little development. We take a USB flash drive, insert it, format it into vfat (you can also use ext, but do not forget that not all Windows users are killed yet).
On the flash drive we create the folder boot, in it the folders initrd and kernel.
From the / os folder, copy the compressed Ramdisk to the boot / initrd folder on the flash drive, call it “main.gz”. From the folder with the kernel sources, copy bzImage to the boot / kernel folder on a flash drive, call it “main.lk”. We take out the files of the Syslinux loader (on the Internet, or from another distribution kit: it doesn’t matter here), namely syslinux.bin, syslinux.boot, syslinux.cfg. Copy them to the root directory of our flash drive. In the syslinux.cfg file we write something like this:
default mm
prompt 1
timeout 100
label mm
kernel /boot/kernel/main.lk
append initrd=/boot/initrd/main.gz load_ramdisk=1 ramdisk_size=5000 rw root=/dev/ram0
label mc
kernel /boot/kernel/main.lk
append initrd=/boot/initrd/custom.gz load_ramdisk=1 ramdisk_size=5000 rw root=/dev/ram0
label cm
kernel /boot/kernel/custom.lk
append initrd=/boot/initrd/main.gz load_ramdisk=1 ramdisk_size=5000 rw root=/dev/ram0
label cc
kernel /boot/kernel/custom.lk
append initrd=/boot/initrd/custom.gz load_ramdisk=1 ramdisk_size=5000 rw root=/dev/ram0
label hd
localboot 0x80
Thus, we have supported custom initrd and kernel, which, for the sake of experiment, can be connected to our distribution.
Find out what kind of device in the system is our flash drive (you can run mount without parameters and see). This is either / dev / sdb1, or / dev / sdc1, or / dev / sdd1. It is necessary to unmount the flash drive before starting the installation.
Install syslinux (if there is no package in the system, apt-get install syslinux):
syslinux -d __
The file ldlinux.sys should appear in the root directory of the flash drive. If it is, then syslinux.bin, syslinux.boot is no longer needed.
How to configure the BIOS to boot from a flash drive, I will not tell you - it is easy. I can only say that it is very convenient to create the / boot / initrd / init folder, into which you can mount / boot / initrd / main, for subsequent work with it. Just do not forget to unclench and compress it with gzip.
Well that's all.
Somehow I just told you how to create a Linux system from scratch. Easy, isn't it? Then you can edit the script / sbin / init, because you still have a lot of work! You will need to write a script to mount the flash drive that chroot into the root directory. Otherwise, you will be forced to work with the ReadOnly partition, the size of 5 MB. But that's another story.
Unnx Davis T ,
B.
For the unenlightened:
Thomas Matejisek is the creator of Slax and Linux Live Scripts.
Roberto de Leo - the creator of Movix.