Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Modularization of Linux File system installation

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the Linux file system installation modularization example analysis, I believe that most people do not understand, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Take mounting the minix file system under Fedora8 as an example:

In order to match the kernel of the system, you must first obtain the source code of the corresponding version of minix. First, query the kernel version of the machine through uname-r:

[cocobear@cocobear] $uname-r

2.6.24.4-64.fc8

The source code for the 2.6.24.4-64 kernel is available on the Kernel.org home page, but all we need is the code in the linux-2.6.24.4/fs/minix/ directory. Because we don't need to recompile the entire kernel, we just need to write a Makefile in the linux- .6.24.4 / fs/minix/ directory and generate the corresponding minix.ko.

Before you start writing Makefile, make sure that the system has the following packages installed:

[cocobear@cocobear ~] $rpm-qa | grep kernel

Kernel-devel-2.6.24.4-64.fc8

Kernel-headers-2.6.24.4-64.fc8

Kernel-2.6.24.4-64.fc8

It needs to be used in the process of module compilation.

There is already a Makefile in the source code:

#

# Makefile for the Linux minix filesystem routines.

#

Obj-$ (CONFIG_MINIX_FS) + = minix.o

Minix-objs: = bitmap.o itree_v1.o itree_v2.o namei.o inode.o file.o dir.o

Modify the file to:

#

Makefile for the Linux minix filesystem routines.

# make minix fs as kernel module

Obj-m + = minix.o

Minix-objs: = bitmap.o itree_v1.o itree_v2.o namei.o inode.o file.o dir.o

KERNELDIR:=/lib/modules/$ (shell uname-r) / build

PWD:=$ (shell pwd)

Default:

Make-C $(KERNELDIR) masking $(PWD) modules

Clean:

Rm-rf * .o * .mod.c * .ko * .symvers

To explain briefly here, obj-m indicates that the file will be compiled as a module; because the module consists of multiple files, the module name is suffixed with-objs (minix-objs) to define the component file of the module. KERNELDIR defines the location of the code tree, PWD defines the current folder location, while the-C option in the make command specifies the location of the code tree (given by KERNELDIR), and PWD $(build) specifies the current build work.

The * * line cleans up the files generated by the compilation process.

After completing the Makefile, we can start compiling the filesystem module. Type make directly and start compiling:

[cocobear@cocobear minix] $make

Make-C / lib/modules/2.6.24.4-64.fc8/build M=/home/cocobear/minix modules

Make [1]: Entering directory `/ usr/src/kernels/2.6.24.4-64.fc8muri686'

CC [M] / home/cocobear/minix/bitmap.o

CC [M] / home/cocobear/minix/itree_v1.o

CC [M] / home/cocobear/minix/itree_v2.o

CC [M] / home/cocobear/minix/namei.o

CC [M] / home/cocobear/minix/inode.o

CC [M] / home/cocobear/minix/file.o

CC [M] / home/cocobear/minix/dir.o

LD [M] / home/cocobear/minix/minix.o

Building modules, stage 2.

MODPOST 1 modules

CC / home/cocobear/minix/minix.mod.o

LD [M] / home/cocobear/minix/minix.ko

Make [1]: Leaving directory `/ usr/src/kernels/2.6.24.4-64.fc8muri686'

After the compilation, we will now generate the minix.ko file. This is what we need. We can install the minix filesystem module using the insmod command. Of course, root permission is required here. Let's demonstrate the loading of the minix module:

[cocobear@cocobear minix] $cat / proc/modules | grep minix

[cocobear@cocobear minix] $

You can see here that minix is not loaded, so we use the insmod minix.ko command:

[cocobear@cocobear minix] $sudo insmod minix.ko

[cocobear@cocobear minix] $cat / proc/modules | grep minix

Minix 28676 0-Live 0xd0e7d000

After insmod, we can see from the above information that the minix module has been loaded. If we do not need to use this module, we can also easily uninstall it:

[cocobear@cocobear minix] $sudo rmmod minix.ko

[cocobear@cocobear minix] $cat / proc/modules | grep minix

[cocobear@cocobear minix] $

So far, we have successfully completed the installation, uninstallation and compilation of the Linux file system.

BTW: there is a problem in the middle. After writing Makefile, type make prompt: "make: Nothing to be done for `default'.". I found the reason on the Internet. I want to use tab instead of spaces before the make command, and I happen to be blank and depressed. I seem to have encountered it before.

The above is all the contents of the article "sample Analysis of Modularization of Linux File system installation". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report