QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2145|回复: 1

实例:介绍unionfs用法

[复制链接]
发表于 2006-12-16 14:38:44 | 显示全部楼层 |阅读模式
大家对fanx很熟悉了 ,但是未必都知道它内部是怎么用unionfs的。那我就简单的说说这个unionfs是怎么用的。可以先参考本版版主翻译的“slax中的unionfs应用"一文

建立一系列目录
[code:1]
unionfs/      tmpfs/    squashfs/
[/code:1]

首先将fanx盘中base中的任意一.mo文件挂载到squashfs文件夹中。
[code:1]
mount -oloop -t squashfs  xx.mo squashfs/[/code:1]
.mo文件是用mksquashfs工具生成的,把它挂在到squashfs目录中是只读的。

然后将tmpfs目录挂载tmpfs系统
[code:1]
mount -t tmpfs tmpfs tmpfs/
[/code:1]
这样tmpfs目录是可读的,在内存中,是个tmpfs文件系统

再将tmpfs做为unionfs的首支挂载到unionfs目录中。
[code:1]
mount -t unionfs -o dir=tmpfs=rw unionfs unionfs/[/code:1]

最后利用unionctl工具,将文件系统统一
[code:1]
unionctl unionfs/ --add --after 0 --mode ro squashfs/
[/code:1]

此时进入unionfs目录,会发现有squashfs/目录下的东西,并且此unionfs目录是可以写的。

这样我想大家就应该明白flanx是如何利用unionfs来解决在只读介质利用内存来解决可写问题的强况了吧。(为什么要可写,呵呵,一个os启动必定要有一些要改动的文件吧,不可写就不能启动了哦)

enjoy it ;)
 楼主| 发表于 2006-12-16 14:48:19 | 显示全部楼层
或者看官方文档

Using unionfs

In the following example, we will merge contents of two directories into a single directory /mnt/union. We assume that all directories already exist.

$ modprobe unionfs
$ mount -t unionfs -o dirs=/mnt/cdrom1=ro:/mnt/cdrom2=ro unionfs /mnt/union

From now, the directory /mnt/union will contain all files and directories from /mnt/cdrom1 and /mnt/cdrom2, merged together and both read only. If the same filename is used in both cdrom directories, the one from cdrom1 has precedence (because it was specified leftmost in the list).
Using unionctl

Unionctl is a tool which is created (together with uniondbg) during unionfs compilation and is installed to /usr/local/sbin. Unionctl is intended to manage the existing union, to list, add, modify or delete existing branches. Some simple example follows, use unionctl command without any argument to see all available options.

To list branches in existing union, use

$ unionctl /mnt/union --list

which will produce the following output

     /mnt/cdrom1 (r-)
     /mnt/cdrom2 (r-)

To add another directory (/mnt/cdrom3) into existing union, use

$ unionctl /mnt/union --add --after /mnt/cdrom2 --mode ro /mnt/cdrom3

and unionctl --list will now produce

     /mnt/cdrom1 (r-)
     /mnt/cdrom2 (r-)
     /mnt/cdrom3 (r-)

In the case when you change the content of branches themselves, execute the following command to force revalidation of the union:

uniondbg -g /mnt/union
Writing to union

Merging read-only directories is useful in many cases, but the union itself remains read-only too, until a read-write branch is added to it. In that case, all changes are stored in leftmost branch (using copy-up method, see below) and file deletions are done by using one of the two methods available:

    *

      WHITEOUT mode, inserts a .wh (whiteout) file to mask out a real file
    *

      DELETE_ALL mode, tries to delete all instances of a file from all branches

WHITEOUT mode is used as default. Copy-up is a special method used to handle file modifications in union. A file from ro branch can't be modified, so it is copied to upper (left) read-write branch at the time when the modification should begin. Then the modification is possible and modified file remains in rw branch.

To add a rw branch at the top of union in our example, type

$ unionctl /mnt/union --add --before /mnt/cdrom1 --mode rw /mnt/changes

All the changes will be stored in /mnt/changes and the union will look like this:

   /mnt/changes (rw)
   /mnt/cdrom1 (r-)
   /mnt/cdrom2 (r-)
   /mnt/cdrom3 (r-)
回复

使用道具 举报

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

本版积分规则

GMT+8, 2024-4-25 08:31 , Processed in 0.051569 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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