Компиляция ядра Linux: автономная ОС

1344
morTie

Привет, ребята, я новичок в компиляции ядра Linux, поэтому у меня есть вопрос: компилируя ядро ​​Linux, мы создаем полностью автономную ОС, которая не зависит от каких-либо дистрибутивов Linux?

Если да ... Хорошо, когда я хочу создать файл initrd с помощью команды initramfs, почему он добавляет некоторую информацию о моем работающем разрушении Linux (я использую Ubuntu 10.4)?

Как мне скомпилировать и добавить модули в мой скомпилированный linux и где их разместить?

Это краткое изложение того, что я делал:

1. получить исходный код ядра (3.4.1) и скомпилировать его с помощью команды «make all» (я использую мой текущий linux .config)

  1. Установка grub на мою карту памяти

  2. Помещение скомпилированного bzImage в каталог / boot моей карты памяти

  3. Используя команду "initramfs", создайте файл initrd и поместите его также в / boot.

  4. Загрузка моего ПК с карты памяти и вход в терминал grub>

  5. Использование «root (hd0,0)»; "kernel / boot / bzImage"; «initrd /boot/initrd.img», а затем «boot» команды для загрузки.

  6. Попадание в терминал (initramfs) после ошибки, в которой говорится, что не удалось найти файл "/lib/modules/3.4.1/modules.dep" !!!

Что я делаю неправильно ?

2

2 ответа на вопрос

10
tgies

By compiling linux kernel are we building a totally standalone OS which doesn't depend on any linux destributions?

No. Linux by itself is not an operating system. It is just a kernel. A userland, comprising a collection of system libraries and basic software, is necessary to facilitate your interaction with the computer. In what we commonly mean when we refer to "Linux", this is provided by a separate project called the GNU Project. Technically, we ought to (and some do) call it "GNU/Linux".

Well when I want to create the initrd file using initramfs commmand why is it adding some info about my running linux destrubution ( I'm running Ubuntu 10.4) ?

Because your initrd contains the collection of programs that initially set up your system on boot, load necessary drivers and daemons, find and mount the requisite partition(s) on your hard drive(s), etc. It is actually customized not only to your distribution, but to your particular installation, configuration, and computer. It is not generally interchangeable with anyone else's initrd. That's why it has to be generated by your system.

How should I compile and add modules to my compiled linux and where should I put them?

If you are compiling your own kernel, presumably you are doing make menuconfig in the kernel source directory prior to compiling, which allows you to select which features will be compiled, and whether they will be integrated into the kernel binary or made available as modules.

This is a summery of what I've been doing:

There are a number of reasons this won't work the way you want it to.

getting the kernel source (3.4.1) and compiling it using "make all" command ( I use my current linux .config )

If you are running Ubuntu 10.04, which predates the 3.x branch of the Linux kernel by quite a bit, let alone 3.4. It will most likely not work correctly, at least not without an enormous amount of extra work. The config files changed quite a bit too, and I'm frankly surprised it's not throwing out errors left and right about things in your (presumably for Linux 2.6) config file not matching up with how things are done in 3.4. Also, you probably want to be downloading Ubuntu's kernel source package and not the plain vanilla kernel source from kernel.org, as Ubuntu patches the kernel to include needed features and make it play nice with everything else in the system. Finally, you are missing a number of steps, which I'll go into later.

Putting the compiled bzImage to the /boot directory of my memory stick

I'm not sure what your intention is with this, but if it's to have a full bootable Linux installation on your memory stick, there's a bit more to it than that -- you don't have any userland stuff at all on that memory stick, for instance. What this will actually do, if set up properly, is (try to) run the Ubuntu installation on your hard drive with the kernel on your memory stick. I believe this should work, but why do that rather than just install the kernel on your hard drive? You can install it side by side with your existing one so you can freely switch between them.

Getting into (initramfs) terminal after an error stating that could not find the "/lib/modules/3.4.1/modules.dep" file !!!

This goes back to the missed steps I mentioned earlier. You need to make modules_install your new kernel to get its modules placed in /lib/modules.

HOWEVER...

None of this really matters, because ideally you should not compile a kernel the "traditional" way at all, unless you have a very specific need to. These days, should you actually need to compile your own kernel, most distributions have a way to do it that uses their custom kernel version (if applicable), automates the build process, installs the kernel as a package so you can cleanly install and remove it as necessary, and configures your bootloader to give you a choice of the new or old kernel(s). In Ubuntu you should follow these instructions: Kernel/Compile - Ubuntu Wiki

Which is not to say you can't compile a kernel the "old-fashioned" way just for kicks/for educational purposes -- I compiled my first kernel that way, but this was before there were better ways to do it. If your system being not-broken is important to you, use the recommended method for your distro, use their source, and use their package management.

Если вы * по-настоящему * хотите создать свой собственный Linux с нуля, зайдите на http://linuxfromscratch.org. Имейте в виду, что это очень сложный и сложный процесс, и компиляция вашего ядра, пожалуй, самая легкая его часть. tgies 11 лет назад 1
1
LawrenceC

When you recompile or compile the Linux kernel, you are NOT creating a new distribution. You are making a newer or different version of the kernel only. The kernel is a single file that is loaded, then executed by the bootloader after your PC completes the POST process.

A distribution consists of many, many other files, including the standard UNIX utilities, usually a package manager, and others. None of this is touched if you (re)compile your own kernel.

It's been awhile since I've compiled my own kernel, but i think you need to run depmod -a after the make command.

`make module_install` устанавливает модули ядра и, я полагаю, запускает` depmod` для вас. tgies 11 лет назад 0
скорее, нет необходимости или смысла запускать `depmod -a` со ссылкой на новое ядро, которое вы только что скомпилировали, но не запускаете в тот момент, когда вы вызываете` depmod`. `depmod` предположительно происходит при загрузке, когда это необходимо. tgies 11 лет назад 0

Похожие вопросы