Installing and detaching a file system in a module in Linux
Source: Internet
Author: User
Install and uninstall a file system in a module in Linux-general Linux technology-Linux programming and kernel information. For more information, see the following. Take the installation of minix file system under Fedora8 as an example:
To ensure matching with the system kernel, first obtain the minix source code of the corresponding version. First, query the kernel version of the local machine through uname-r:
On the Kernel.org homepage, we can get the source code of 2.6.24.4-64 kernel. In fact, we only need 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-2.6.24.4/fs/minix/directory to generate the corresponding minix. ko.
Before writing Makefile, make sure that the system has installed the following packages:
#
# 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:
#
# 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) M = $ (PWD) modules
Clean:
Rm-rf *. o *. mod. c *. ko *. symvers
In this example, obj-m indicates that the file will be compiled as a module, because this module is composed of multiple files and the module name is added as a module name? The objs (minix-objs) suffix is used to define the module composition file. KERNELDIR defines the location of the code tree, PWD defines the location of the current folder, and the-C option in the make command specifies the location of the code tree (given by KERNELDIR), M = $ (PWD) specifies the current build work.
The last line clears the files generated during the compilation process.
After Makefile is complete, we can start to compile the file system module, and directly input make to 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. fc8-i686 ′
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. o
Building modules, stage 2.
MODPOST 1 modules
CC/home/cocobear/minix. mod. o
LD [M]/home/cocobear/minix. ko
Make [1]: Leaving directory '/usr/src/kernels/2.6.24.4-64. fc8-i686 ′
After compilation, the minix. ko file is generated at present. This is what we need. You can install the minix file system module by using the insmod command. Of course, the root permission is required here. Let's demonstrate how to load the minix module:
After insmod, we can see from the above information that the minix module has been loaded. If you do not need to use this module, we can easily uninstall it:
By now, we have successfully compiled, installed, and uninstalled the file system.
BTW: a problem occurs in the middle. After the Makefile is written, enter the make prompt: "make: Nothing to be done for 'default '. ", I found the reason on the Internet. I had to use a tab before the make command, instead of a space. However, my space is just right. It seems that I have encountered it before.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service