QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5025|回复: 8

有关fanx内核编译的文档:unionfs在slax中的应用

[复制链接]
发表于 2006-11-3 19:46:56 | 显示全部楼层 |阅读模式
我是版主的朋友,一直想给fanx编译内核,但是关于unionfs的问题一直不能解决。所以花了两天时间专门翻译了下面的文档,可能会对尝试为fanx编译内核的朋友有所帮助。原文出处http://www.linux-live.org/unionfs/。另外这是我第一次翻译文档,其中存在大量翻译错误以及术语的错误,希望各位予以斧正。

        一个利用Unionfs使文件系统统一的实例
这个材料给出了一个使用unionfs的例子,即在slax linux live cd实现。Unionfs 是2004年在stony brook大学开始的,它是一个可叠放的统一的文件系统,它能够结合多个目录(因此可称为分支)的内容同时独立地保持它们的物理内容。它允许任何ro和rw分支的结合,同时允许在分支中修改和删除不使用的分支。Unionfs可以使用在几个方面,例如统一在不同磁盘上的不同的文件系统到一个home目录,或者把几张cd合并成一个统一的归档镜像。所以,具有复制可写功能的unionfs可以用来把ro和rw的文件系统合并起来,并且实现了允许修改只读文件系统并把这些修改保存在可写文件系统。
Slax是一个192兆大的linuxlive发行版,目的是将linux操作系统的全部特征压制到一个便携式的媒介(U盘或者mini-CD)中,并且允许在任何电脑上不需要安装而启动linux。它甚至可以在没有硬盘的电脑上运行。Unionfs是slax系统中最重要的部分,它使slax具有完全可写的根目录结构,从而无论是表面上还是运行方式上slax等同于一个真实的linux操作系统。所以首先让我们谈一下unionfs。

启动时加载unionfs
要使unionfs运行,你需要通过编译源代码建立一个linux内核模块。Unionfs可以作为扩充模块用于版本在2.4.20或2.6.9和更新的linux内核。从ftp下载最新的版本并且解开压缩包。

$tar –xzf unionfs-x-y-z.tar.gz
然后进入解压出来的文件夹,仔细阅读文件夹中的README和INSTALL两个文件。其中有很多关于如何避免问题的说明。之前如果你知道加模块可能会使编译调试不成功会对整个编译过程很有用。调试信息对报告错误很有用,但是值得注意的是内核模块大小的增加。两个参数必须设定使调试完全不起作用(即调试信息不写入模块中)。
在包含源码的目录下建立一个fistdev.mv文件,写入下面代码:
EXTRACFLAGS=-DUNIONFS_NDEBUG
UNIONFS_DEBUG_CFLAG=
编译出来的内核模块没有调试信息大约90KB,而有调试信息的是5MB(你可以下载fistdev.mv来为slax编译unionfs)。

另一件使编译工作顺利的重要的事是下载和解压你正使用的内核源码包,并且修改unionfs中Makefile中的LINUXSRC变量,添加你刚才解压的目录路径(某些时候可以自动检测到)。
接下来,使用下面的命令可以将unionfs模块建立并安装在/lib/modules/$(Kernel Version)/kernel/fs/unionfs下:
$make
$make install
$depmod -a
使用unionfs
在接下面的例子中我们把两个文件夹的内容合并到仅仅一个文件夹/mnt/union中。假定所有的文件夹都已经存在。
$modprobe unionfs
$mount –t unionfs –o dirs=/mnt/cdrom1=ro:/mnt/cdrom2=ro unionfs /mnt/union
现在,文件夹/mnt/union包含所有/mnt/cdrom1和/mnt/cdrom2中的文件,它们被合并在一起并且都是只读的。如果两个目录中有相同文件名的文件,那么cdrom1中的文件具有优先权(因为cdrom1在命令中列在左边)。
使用unionctl
Unionctl(同时还有uniondbg)是一个编译unionfs时建立并安装在/usr/local/sbin中的工具。Unionctl被用来处理存在的union(如上面的/mnt/union),列出、增加、修改或者删除存在的分支。下面是一些使用unionctl命令准确列出所有信息的简单例子。
$unionctl /mnt/uion --list
将会显示下面的信息:
          /mnt/cdrom1 (r-)
        /mnt/cdrom2 (r-)
增加另一个目录(/mnt/cdrom3)到union中使用
$unionctl /mnt/union --add --after /mnt/cdrom2 --mode ro /mnt/cdrom3
再用unionctl –list将会显示
        /mnt/cdrom1 (r-)
        /mnt/cdrom2 (r-)
        /mnt/cdrom3 (r-)
当你改变分支本身内容时,执行下面的命令强制更新union目录。
$uniondbg –g /mnt/union
写入union目录
合并只读文件夹在很多情况下是很有用的,但是在加入一个读写分支之前,union目录本身仍然是只读的。这种情况下,所有的改变都储存在最左边的分支中(使用copy-up模块,如下)并且文件删除通过使用下面两个可用模块其中之一来实现。
WHITEOUT模块,插入一个.wh文件指向一个真实的文件
DELETE_ALL 模块,设法删除所有的分支中的任意一个文件
WHITEOUT模块的默认状态是可用的。Copy-up是一个被用来操作union中的文件修改的特殊模块。只读分支中的文件不能修改,因此在修改时要先把它复制到之前(左边)的可读写分支中。然后修改就可以实现了,并且修改过得文件保存在可读写的分支上。
在上面的例子中最左边增加一个可读写的分支,输入
$unionctl /mnt/union --add --before /mnt/cdrom1 --mode rw /mnt/changes
所有的修改将保存在/mnt/changes中,而union目录就变成如下
        /mnt/changes (rw)
        /mnt/cdrom1 (r-)
        /mnt/cdrom2 (r-)
        /mnt/cdrom3 (r-)
真实运用unionfs的实例:SLAX
数据保存在一个只读的媒介如CD-ROME而不能修改。这个linux livecd发行版支持对所有文件夹可写,这需要使用特殊的技术允许虚拟的修改并把所有的改变保存在内存中。SLAX使用这些技术已经很长时间了,最早是2003年末使用ovlfs,2004年末将unionfs使用在SLAX 5中,该版本于2005年4月发布,要不是unionfs你不能感受到它所创造的奇迹。
SLAX的内部组织
启动linux需要三个基本的要求:
1)        内核映像(描述操作系统本身的文件,通常叫做vmlinuz);
2)        包括根文件系统和初始化进程(linuxrc)的分区或映像文件(例如initrd.gz);
3)        一些linux引导工具(该工具解压内核映像并将其载入内存)。
SLAX CD启动通过使用isolinux.bin,该引导文件包括了光盘文件系统的驱动程序,并且能够把内核映像(vmlinuz)和根文件系统映像(initrd.gz)从光盘载入内存。
当完成加载内核和运行后,linux内核在电脑的RAM上建立一个虚拟磁盘(称为initrd ramdisk),并且把initrd.gz解压到其中,同时将其作为根文件系统挂载。SLAX中的initial ramdisk仅仅有4.4MB大,包含进入SLAX所需的基本软件和驱动程序。最难的是下面的内容,请仔细阅读。
内核执行/linuxrc(ramdisk中)文件作为初始化进程。Linuxrc的工作是相当复杂的。它创建一个空的union目录/union,然后在/memory目录下挂载空文件系统(即tmpfs),创建目录/memory/changes(这个目录在空文件系统中,而不是在ramdisk中)。统一文件系统被挂载到/union上,而/memory/changes目录作为一个可读写分支增加到其中。
然后linuxrc通过挂载所有的光盘和磁盘并寻找livecd.sgn文件来找到SLAX CD。你可能很奇怪,因为cdrom被挂载到/union/mn/目录下!之后,所有SLAX CD中必需的映像文件(*.mo)都被挂载在/memory/images/*.mo目录上,并且所有的这些挂载点作为单独的制度分支通过使用unionctl增加到统一文件系统中,而这些都在第一分支(可读写的changes目录)之后。

/(initrd, 4MB)
     |
     |---- /memory(tmpfs, 80% of RAM)
     |        |-- images
     |        |     |-- base.mo   <--loop--+
     |        |     |      |-- bin         |
     |        |     |      |-- usr         |
     |        |     |      +-- var         |
     |        |     |                      |
     |        |     |-- xwindow.mo <-loop------+   
     |        |     |      |-- etc         |   |
     |        |     |      |-- usr         |   |
     |        |     |      +-- var         |   |
     |        |     |                      |   |
     |        |     +-- kde.mo     <-loop----------+
     |        |            |-- opt         |   |   |
     |        |            |-- usr         |   |   |
     |        |            +-- var         |   |   |
     |        |                            |   |   |
     |        +-- changes                  |   |   |
     |                                     |   |   |
     +---- /union                          |   |   |
              |---- /mnt/cdrom             |   |   |
              |          |--- base.mo -----+   |   |
              |          |--- xwindow.mo ------+   |
              |          +--- kde.mo --------------+
              +---- /mnt/live
当所有的模块被挂载到union并且可读写分支在union最前面,pivot_root开始运行。这个工作也实现当复杂的,原始的根目录被挂载到/mnt/live下,而/union将成为新的根目录。在SLAX运行以后可以通过浏览/mnt/live文件夹看到ramdisk的原始内容。
接下来linuxrc执行/sbin/init启动所有的系统服务并且显示登录画面。
发表于 2006-11-8 16:57:17 | 显示全部楼层
恩 不错 不错 。。但是unionfs 在某些 version 的kernel上好像不是很 稳定的说
回复

使用道具 举报

发表于 2006-11-8 18:03:44 | 显示全部楼层
不是说mgc吧
回复

使用道具 举报

发表于 2006-11-8 18:10:28 | 显示全部楼层
不是 不是     我只是引用unionfs官方的话而已
回复

使用道具 举报

 楼主| 发表于 2006-11-9 18:01:37 | 显示全部楼层
是的,所以slax6.0以上改用aufs了,更稳定。
回复

使用道具 举报

发表于 2006-11-9 19:28:34 | 显示全部楼层
介绍一下aufs哦
回复

使用道具 举报

 楼主| 发表于 2006-11-10 12:18:15 | 显示全部楼层
还没有找到相关文档,找到了一定翻译过来
如果有人找到了,麻烦告诉一下地址
回复

使用道具 举报

发表于 2006-12-16 13:30:22 | 显示全部楼层
Aufs -- Another Unionfs
Junjiro Okajima

# $Id: README,v 1.28 2006/12/11 02:21:16 sfjro Exp $

0. Introduction
Aufs was entirely re-designed and re-implemented Unionfs. After
many original ideas, approaches, improvements and implementations, it
becomes totally different from Unionfs while keeping the basic features.
Unionfs is being developed by Professor Erez Zadok at Stony Brook
University and his team.
If you don't know Unionfs, I recommend you to try and know it before
using aufs. Some terminology in aufs follows Unionfs's.

Bug reports (including to my broken English), suggestions, comments
and donations are always welcome.

1. Features
- unite several directories into a single virtual filesystem. The member
  directory is called as a branch.
- you can specify the permission flags to the branch, which are 'readonly',
  'readwrite' and 'whiteout-able.'
- by upper writable branch, internal copyup and whiteout, files/dirs on
  readonly branch are modifiable logically.
- dynamic branch manipulation, add, del.
- etc... see Unionfs in detail.

Also there are many enhancements in aufs, such like,,,
- simplified, safer and faster
- keep inode number by external inode number table
- keep the timestamps of file/dir in internal copyup operation
- seekable directory, support NFS readdir.
- support mmap(2) including /proc/PID/exe symlink, without page-copy
- whiteout is hardlinked in order to reduce the consumption of inodes
  on branch
- do not copyup, nor create a whiteout when it is unnecessary
- revert a single systemcall when an error occurs in aufs
- remount interface instead of ioctl
- maintain /etc/mtab by an external shell script, /sbin/mount.aufs.
- loopback mounted filesystem as a branch
- kernel thread for removing the dir who has a plenty of whiteouts
- support copyup sparse file (a file which has a 'hole' in it)
- default permission flags for branches
- selectable permission flags for ro branch, whether whiteout can
  exist or not
- and more... see aufs manual in detail

Aufs is in still development stage, especially,,,
- pseudo hardlink (hardlink over branches)
- NFS or remote filesystem branch
- allow a direct access manually to a file on branch,
  eg. bypassing aufs. including NFS or remote filesystem branch.
- remount option copy/move between two branches, selecting writable branch
  policy.
- O_DIRECT (unnecessary?)
- export via NFS (unnecessary?)
- light version, without branch manipulation.
- SMP, because I don't have such machine.
- xattr, acl
- and documentation

2. Download and Contact
CVS tree is in aufs project of SourceForge.
I always try putting the stable version in CVS, so you can try CVS
instead of SourceForge File Release. And every changes are summarized
and reported to aufs-users at lists.sourceforge.net ML. It is recommended to
join this ML.

When you have any problems or strange behaviour in aufs, please let me
know with,,,
- /proc/mounts (instead of the output of mount()
- linux kernel version
- AUFS_VERSION (defined in include/linux/aufs_type.h)
- configuration (define/undefine CONFIG_AUFS_xxx, or plain local.mk is
  used or not)
- phenomenon
- actual operation, reproducible one is better
- mailto: aufs-users at lists.sourceforge.net

3. Configuration and Install
Aufs is being developed and tested on linux-2.6.16 and later.

o CONFIG_AUFS_UDBA_INOTIFY
"User's Direct Branch Access, UDBA" means to access a file on a branch
directly, eg. bypassing aufs.
If you want to modify files on branches directly and want aufs to
detect the changes of them fully, use 'udba=inotify' mount option.
To support this option, you need to enable both of CONFIG_INOTIFY and
CONFIG_AUFS_UDBA_INOTIFY.
This is valid for linux-2.6.18 and later.
See detail in aufs.5.

o CONFIG_AUFS_KSIZE_PATCH
Aufs sometimes needs to 'realloc' memory. In linux kernel, people
usually writes the sequence which is alloc/copy/free memory. If
'ksize' kernel internal function is exported to modules, aufs can omit
alloc and free in the sequence and runs efficiently in some cases.
Here is a patch for it, called ./ksize.patch which only exports the
function.
It is recommended to apply this patch to your kernel and enable
CONFIG_AUFS_KSIZE_PATCH (cf. local.mk).
This is valid for linux-2.6.16 and later.

If you don't want to modify/recompile your kernel, you can use aufs
without this patch and leave CONFIG_AUFS_KSIZE_PATCH as disabled.
When you link aufs to your kernel statically, ie. CONFIG_AUFS=y
instead of '=m', you don't need ./ksize.patch.

o CONFIG_AUFS_LHASH_PATCH
If you use NFS as an aufs branch filesystem in linux-2.6.19 or later, then
you need to apply the patch './lhash.patch' to you kernel source, and enable
CONFIG_AUFS_LHASH_PATCH (cf. local.mk).
This patch exports the kernel internal function __lookup_hash().
If your kernel is before 2.6.19 or you don't use NFS as a branch, you don't
need this patch.

o CONFIG_DEBUG_PROVE_LOCKING (in linux kernel)
If you enable CONFIG_DEBUG_PROVE_LOCKING in your linux kernel, you
will be warned at aufs compile time. And at aufs run time, some
harmless warnings will be issued, and CONFIG_DEBUG_PROVE_LOCKING will
be disabled automatically.
See detail in aufs.5.

Currently these configurations are written in ./local.mk, ./local.mk will work
for you in most cases.
        $ make -f local.mk
The local.mk searches your kernel source files by
        KDIR = /lib/modules/$(shell uname -r)/build
If you are cross-compiling the aufs module, try
        $ make KDIR=/your/kernel/source/path -f local.mk

If you are using 'sparse' which is commonly used for checking linux
kernel source files. You will meet this error.
        'error: undefined identifier '__func__''
Because aufs uses 'nested function' GCC extension.
While it is used in very limited and simple manner in aufs, sparse
says it is an error. You can ignore this message if your compilation
succeeds.
If you want to shut your sparse up, then apply
'./nested__func__.patch' to your sparse souce file (of course, it is
absolutely no warranty too).

4. Usage
        (after 'make')
        $ man -l ./aufs.5
        # install -m 500 -p mount.aufs /sbin (recommended)
        # insmod ./aufs.ko
        $ mkdir /tmp/rw /tmp/aufs
        # mount -t aufs -o dirs=/tmp/rw:${HOME}=ro none /tmp/aufs

Here is another example.

        # mount -t aufs -o br:/tmp/rw:${HOME}=ro none /tmp/aufs
        or
        # mount -t aufs -o br:/tmp/rw none /tmp/aufs
        # mount -o remount,append:${HOME}=ro /tmp/aufs

If you disable CONFIG_AUFS_COMPAT in your configuration, you can remove the
default branch permission '=ro.'

        # mount -t aufs -o br:/tmp/rw:${HOME} none /tmp/aufs

Then, you can see whole tree of your home dir through /tmp/aufs. If
you modify a file under /tmp/aufs, the one on your home directory is
not affected, but the same named file will be newly created under
/tmp/rw. And all of your modification to the file will be applied to
the one under /tmp/rw. This is called Copy on Write (COW) method.
Aufs mount options are described in ./util/aufs.in.5, and ./aufs.5
would be built by the first 'make'.
When you finish using aufs, you can unmount it by umount( simply.

When you load aufs module, aufs shows its version as
        'tested linux version'-'release or cvs committed date'
like
        2.6.18rc4-20060828
While I am trying to support linux after 2.6.16, I cannot have such
many test environments. This sample version means that "I have tested
on 2.6.18-rc4 fully, and tested on 2.6.17 partially."

5.
If you are an experienced user, no explanation is needed. Aufs is
just a linux filesystem module. take a glance at ./local.mk,
aufs.in.5, and Unionfs.

Enjoy!

# Local variables: ;
# mode: text;
# End: ;
回复

使用道具 举报

发表于 2007-2-2 15:59:59 | 显示全部楼层
最后什么也没有说清楚!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-20 04:53 , Processed in 0.060632 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表