1

I am trying to build a minimal linux, for experimenting out with drivers (LLD 3 book refers kernel version 2.6.10). LFS looks out to be a hell of a task, and I am not sure of if I would be able to build 2.6.10 looking at the latest documents.

I am following this blog to build a minimal image that can run on qemu (I don't want to mess up my existing system, that why I chose virtualization).

I am stuck at the point of building grub. I was able to build the latest version of grub i,e 2.0, but I was unable to locate required files stage1, stage2, e2fs_stage1_5 (mentioned in the blog).

Taking the old version 0.97 as per the blog, surprising the build is failing, during configure configure: error: GRUB requires a working absolute objcopy; upgrade your binutils

Upgrade your binutils ? I am using quiet latest Ubuntu.

grub-0.97$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.3 LTS
Release:        12.04
Codename:       precise

grub-0.97$ ld -version
GNU ld (GNU Binutils for Ubuntu) 2.22

I also found this link mentioning something about binutil upgrade (2.9.1.0.23 or later) for building GRUB.

Am I doing anything wrong ?

  • stage 1.5 is not used in grub 2 – hildred Dec 27 '13 at 3:35
  • why would you tag grub-legacy when you're using GRUB 2? – strugee Jan 18 '14 at 6:30
2

If you do want to mess up with building everything from scratch, you can try Buildroot.

git clone git://git.buildroot.net/buildroot
cd buildroot
make qemu_x86_defconfig
make

See this blog for further information.

  • 1
    Thanks @yegorich, I was able to build and run a custom kernel in half an hour. Struggling with networking though..!! – Kamath Dec 9 '13 at 16:02
3

I am trying to build a minimal linux, for experimenting out with drivers (LLD 3 book refers kernel version 2.6.10). LFS looks out to be a hell of a task...

Yeah, it is. If you just want a minimal linux with a custom kernel, you certainly don't have to build the entire userland too! Pick a goal:

  1. Experiment with driver development.

    OR

  2. Build linux from scratch.

Not both, because if what you really want to do is #1, #2 is just an unnecessary waste of time. And not a short length of time, as you are finding out, although that blog is quite short, I suspect you are going to have a lot more problems and questions if you keep going. Think: days. Like, whole days, plural. And a very high probability that sometime during day 2 or 3, you are going to agree with me and shelve LFS rather than wasting more time.

I don't want to mess up my existing system, that why I chose virtualization.

"Messing up your system" is almost certainly not an issue with testing kernel drivers, except in the sense of messing up the running state. I.e., you won't do any harm that isn't fixed by a reboot. By "almost certainly not" I mean if it is a risk, you'll know because of the peculiar nature of whatever you are doing. But you won't by working through LDD 3.

However, it is very easy to mess up the running state enough to require a reboot, which can become a tedious hassle, and does run a small risk of corrupting the filesystem if "reboot" means flicking the switch because the kernel won't come out of panic -- which makes using a VM a good idea. I don't think QEMU is the best choice, though, unless you are trying to simulate foreign hardware. Which you almost certainly don't need/want to do in this case.

So, here's my advice: if you are on an x86 or x86_64 machine, use an x86(_64) VM like virtualbox. Use whatever image you want, and install a custom kernel. Again: you do not need to build the userspace to run a custom kernel. You just need to build and install the kernel into an existing userspace (or OS image). Just the kernel. Nothing but the kernel. That's all. You can do that in < 15 minutes, although it may take hours the first time reading all the configuration stuff.

But: you don't even need a custom kernel to experiment with module building. You just need the source for the kernel used in your image. Although LDD 3 is dated, the 3.x kernel is not so substantially different than the 2.6 kernel. A lot of drivers, etc., in 3.x are completely unchanged from 2.6.

OTOH, having some experience building kernels may provide you with insights vis. kernel programming.

  • Thanks for your answer, it certainly explains road map to my goal. However my immediate requirement was to have a controlled environment to experiment with drivers. I chose QEMU because you can attach GDB to it and debug. Building a custom kernel and file system with minimal effort, is the point where I am stuck at. Buildroot is a very good suggestion, thats why I am accepting answer from @yegorich. – Kamath Dec 9 '13 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.