linux下squashfs使用方法,squashfs 文件系统简介

squashfs 是一个高度压缩的只读文件系统,它可以将高达 2-3GB 的数据压缩到一个只有 700M 的文件中。如果你有使用到 Linux 的 Live CD ,那么你会看到 squashfs 的身影。

当一个 Live CD 启动时,它将加载整个 Linux 系统环境。Live CD 所使用的正是这种高度压缩的只读 squashfs 文件系统,其中的 root 文件系统就被压缩存放在这个文件系统之中。

squashfs 系统支持以回环(loopback)的方式挂载,然后便可以访问其上的文件了,在访问这些文件时,它们就会被解压缩并装载在 RAM 中,而不需要将整个文件解压缩后才去访问其中的文件,这样一来访问速度就快多了。

我们可以打开一个 Ubuntu 的 Live CD ISO 文件,在目录 ISO_ROOT/casper/ 目录下可以看到 filesystem.squashfs 这个文件。squashfs 在其内部使用了如gzip和lzma这些压缩算法。

如果想创建 squashfs 文件,那么需要安装 squashfs-tools 软件包。

下面是创建 squashfs 工具 mksquashfs 的基本用法:

# mksquashfs command script_compressedfs.squashfs

Parallel mksquashfs: Using 1 processor

Creating 4.0 filesystem on script_compressedfs.squashfs, block size 131072.

[==============================================================================================================|] 12/12 100%

Exportable Squashfs 4.0 filesystem, data block size 131072

compressed data, compressed metadata, compressed fragments

duplicates are removed

Filesystem size 0.96 Kbytes (0.00 Mbytes)

58.55% of uncompressed filesystem size (1.63 Kbytes)

Inode table size 199 bytes (0.19 Kbytes)

41.29% of uncompressed inode table size (482 bytes)

Directory table size 174 bytes (0.17 Kbytes)

70.16% of uncompressed directory table size (248 bytes)

Number of duplicate files found 1

Number of inodes 15

Number of files 12

Number of fragments 1

Number of symbolic links  0

Number of device nodes 0

Number of fifo nodes 0

Number of socket nodes 0

Number of directories 3

Number of ids (unique uids + gids) 1

Number of uids 1

root (0)

Number of gids 1

root (0)

接下来我们创建一个目录,用来挂载刚才创建的文件系统:

# mkdir /mnt/squash

挂载刚才生成的文件:

# mount -o loop script_compressedfs.squashfs /mnt/squash/

# ls /mnt/squash/

cut  hello.c  paste  ver1.txt  ver2.txt  ver.patch

使用 -e 选项可以排除不希望被压缩的文件,如:

# mksquashfs /root/command script_compressedfs.squashfs -e /root/command/hello.c /root/command/paste

# mount -o loop script_compressedfs.squashfs /mnt/squash/

# ls -l /mnt/squash/

total 2

drwxr-xr-x 2 root root  31 2012-04-04 09:48 cut

-rw-r--r-- 1 root root  35 2012-04-03 12:15 ver1.txt

-rw-r--r-- 1 root root  35 2012-04-03 10:08 ver2.txt

-rw-r--r-- 1 root root 178 2012-04-03 12:15 ver.patch

如果要排除的文件很多,那么可以将这些文件写到一个文本中,然后使用 -f 选项指出该文本,如:

# mksquashfs /root/command script_compressedfs.squashfs -ef exclud_list

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值