Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Patching and compiling Ext4 as a kernel module

I'm currently patching Ext4 for academic purposes (only linux/fs/ext4/*, like file.c, ioctl.c, ext4.h) . I'm working on the QEMU virtual machine, and to speed up the whole process I've selected Ext4 to compile as a kernel module. The problem occurs when it comes to test new changes, as, even though I run make modules ARCH=x86 && make modules_install ARCH=x86 and reboot the machine (/ is Ext4), they are not visible unless I recompile the whole kernel. It's a little bit weird as I have a variety of signs that the Ext4 has been compiled as a module:

  1. It is configured as that:

    $ grep EXT4 .config
    CONFIG_EXT4_FS=m
    
  2. It does compile as a module:

    $ make modules ARCH=x86
    (...)
    CC [M]  fs/ext4/ioctl.o
    LD [M]  fs/ext4/ext4.o
    Building modules, stage 2.
    MODPOST 3 modules
    LD [M]  fs/ext4/ext4.ko
    
  3. After $ make modules_install ARCH=x86 the files in /lib/modules/3.13.3/kernel/fs/ have proper time stamp.

  4. Finally:

    $ lsmod
    Module                  Size  Used by
    ext4                  340817  1
    (...)
    

For some reason I have to do $ make all ARCH=x86 in order to see my changes appear in the runtime. What have I missed? Thanks!

like image 872
Tomek Falkiewicz Avatar asked Jul 01 '14 12:07

Tomek Falkiewicz


People also ask

Is ext4 a file system for Linux kernel?

ext4 (fourth extended filesystem) is a journaling file system for Linux, developed as the successor to ext3. 0x83: MBR / EBR. EBD0A0A2-B9E5-4433-87C0-68B6B72699C7: GPT Windows BDP. 0FC63DAF-8483-4772-8E79-3D69D8477DE4: GPT Linux filesystem data.

What is kernel compiling?

Yes, compiling a kernel usually means: Downloading the source code. Possibly modifying the source code (most non-programmers don't usually do this). Configuring the kernel (what features/modules/drivers to include, etc.) Compiling it.

Should I compile my own kernel?

The advantages of compiling your own kernel include being able to tune the kernel to your specific hardware, and ending up with a smaller kernel. You may also need to compile your own kernel if the default kernel does not support some specific hardware you have.


1 Answers

Most boot processes use an "initial ramdisk" (initrd) which contains all kernel modules which the kernel needs to load to be able to do anything - after all, to read files from an Ext4 file system, the kernel needs a driver for this file system and if the driver is on said file system, well, ...

So the solution is to pack all those files into an archive (the initial ramdisk) and save the hard disk blocks as a list of numbers in the boot loader. It can then use a primitive IDE/SATA driver to load the blocks directly, extract the drivers and load them.

Check the documentation of your linux distro to find out how to update initrd. On my Ubuntu Linux, it's mkinitramfs.

Related:

  • Linux initial RAM disk (initrd) overview
like image 140
Aaron Digulla Avatar answered Sep 20 '22 20:09

Aaron Digulla