一、启动镜像initrd.img 文件
类RedHat 系统从vmlinuz 核心引导后,会读取initrd.img 启动镜像。该文件中包含驱动模块等信息,是非常重要的文件。不同版本使用的格式不同。
1.RHEL 4.0 版本
采用ext2 文件格式镜像,再通过gzip 压缩:

引用
# file initrd.img
initrd.img: gzip compressed data, from Unix, max compression
# mv initrd.img initrd.img.gz
# gunzip initrd.img.gz
# file initrd.img
initrd.img: Linux rev 1.0 ext2 filesystem data

2.RHEL 5.0 版本
采用cpio 打包镜像,再通过gzip 压缩:

引用
# file initrd.img
initrd.img: gzip compressed data, from Unix, max compression
# mv initrd.img initrd.img.gz
# gunzip initrd.img.gz
# file initrd.img
initrd.img: ASCII cpio archive (SVR4 with no CRC)

3.RHEL 6.2 版本
RHEL 6.0 - 6.2 都采用与RHEL 5.0 相同的格式进行打包,但从6.2版本开始,改用LZMA 进行压缩。详见:Release Notes for Red Hat Enterprise Linux 6.2 Edition 2
如下:

引用
# file initrd.img
initrd.img: LZMA compressed data, streamed

※ 注意,若在低于RHEL 6.2 版本下执行file 命令,可能无法识别LZMA 压缩格式:

引用
# file initrd.img
initrd.img: data

这时,可把file 软件包升级到5.04-13.el6 即可。

二、xz 工具简介
xz 工具是LZMA 压缩算法的一个实现。具体可见:Wikipedia

引用
xz is a lossless data compression file format incorporating theLZMA2 compression algorithm. While xz can only support one file the convention is to bundle a file that is an archive itself, such as those created by the tar or cpio Unix programs. The original 7zip program implementing LZMA2 compression achieved small files (at the cost of speed compared to gzip or bzip2), but also created its own unique archive format which was Windows-centric and did not support Unix functionality; xz is essentially a stripped down 7zip with little archive format functionality, that compresses a single file (as opposed to 7zip's more complex capabilities like concatenating & compressing entire directories).
7-Zip supports xz since version 9.04 beta (stable since 9.20)

可见,Windows 下可使用7-Zip 打开.xz 文件。LZMA 算法比Gzip 算法压缩率更高。几个参数:

引用
# xz --help
Usage: xz [OPTION]... [FILE]...
Compress or decompress FILEs in the .xz format.

Mandatory arguments to long options are mandatory for short options too.

-z, --compress      force compression
  -d, --decompress    force decompression
  -t, --test          test compressed file integrity
  -l, --list          list information about files
  -k, --keep          keep (don't delete) input files
  -f, --force         force overwrite of output file and (de)compress links
  -c, --stdout        write to standard output and don't delete input files
  -0 .. -9            compression preset; 0-2 fast compression, 3-5 good
                      compression, 6-9 excellent compression; default is 6
  -e, --extreme       use more CPU time when encoding to increase compression
                      ratio without increasing memory usage of the decoder

三、手动修改initrd.img 文件
解压:

# xz -dc initrd.img | cpio -id

压缩:

# find . | cpio -c -o | xz -9 --format=lzma > initrd.img

三、补充tar.lzma
由于LZMA具有优秀的压缩率及占用资源少的特点,越来越多的工具采用lzma进行打包,后缀名为:tar.lzma。
对于Fedora 11 及以后的版本,可以使用下面的命令操作:
压缩

# tar cfv backup.tar.lzma a/dir --lzma

解压:

# tar xfv backup.tar.lzma --lzma

如果是CentOS 5.3 等老版本,需要安装独立的lzma 工具或用xz 进行: 
压缩:

# tar cv a/dir | lzma -c -z > backup.tar.lzma

解压(两个方式都可以):

# cat backup.tar.lzma | lzma -d | tar xv 
# xz -dc backup.tar.lzma | tar xvf -
 

1."gunzip initrd.img-2.6.27-7-generic.gz",得到一个未压缩的initrd.img-2.6.27-7-generic 2. ”cpio -iv < initrd.img-2.6.27-7-generic",提取成功

#制作cpio格式的initrd(新2012年使用过的)

#cd /root/busybox-1.15.3/rootfs9260
#find . | cpio -H newc -o > ../initrd_cpio.img

#制作cpio格式的initrd(2009年制作的LFS的方式):
dd if=/dev/zero of=/tmp/rootfs bs=1k count=35000
losetup /dev/loop0 /tmp/rootfs
mkfs.ext2 –F –i 2000 /tmp/rootfs
mkdir /tmp/loop
mount –o loop /tmp/rootfs /tmp/loop
#然后将刚才建立的基本系统拷贝到/tmp/loop
cp /lfs/* /tmp/loop –arfp
find . | cpio –o –H newc | gzip –c > /tmp/initrd.img

find .|cpio -o -H newc|gzip>~/myinitramfs.gz

1.  find .    查找显示当前目录下的所有文件、文件夹
2. | 管道,将 | 左边命令的结果(也就是find . 得到的所有文件、文件夹路径名称)传给右边(也就cpio命令)
3. cpio -o -H newc cpio是将文件系统打包或解包, -o 是打包 ,-H 指定格式 为newc
newc The new (SVR4) portable format, which supports file systems having more than 65536 i-nodes. (4294967295 bytes)
4 | 将cpio打好的包传给gzip压缩
5 gzip 压缩命令的一种,gnuzip。类似zip,rar。 6 >~/myinitramfs.gz 将压缩后的数据 存为 文件myinitramfs.gz

cpio命令
    利用cpio 可将文件或目录从文件库获取出来或将散列文件拷贝到文件库。cpio 的指令格式:
        cpio –i[bcdmrtuv] [patterns]
        cpio –o [abcv]
        cpio –p [adlmuv][directory]

说明:cpio 共有三种基本模式,-o即copy-out 模式,将一组文件copy到一个文件库,-i 即copy-in 模式,读取文件库,并将其展开在当前目录。-p 能从某个目录读取所有文件(包括子目录到另一个目录),且不以archive(归档)的方式存放。
    cpio 常配合shell使用。-o常用标准输入设备读取要copy 的文件名称,并将copy成的archive file 通过标准输出设备输出。一般利用输入/输出重定向或管道的原理,达到真正复制的功能。

(一)利用cpio备份:
[例1]
        $ find temo –print | cpio –ocdv > /dev/rfd0135ds18 
例: find . |cpio -co > ../initrd

将temp目录下的文件备份到软盘上。-o表示输出模式,-c生成一个带有头信息的文件。 -d表示按需要生成目录,-v表示命令执行时不断显示信息。用“>”把结果定向到软盘。
[例2]
        $ ls |cpio –o >/usr/backup
将当前目录下的所有文件复制成backup archive file
[例3]
        $ ls *.c | cpio –o>backup
复制工作目录中的所有的c程序.
[例4]
        $ ls| cpio –p /usr/linfs/tempdir
复制当前工作目录下的文件到/usr/linfs/tempdir 目录,不生成archive  file

(二)利用cpio 复原:
[例5]
        $ cpio –icdv < /dev/rfd0135ds18
例: cpio -i < ../initrd将上层目录的initrd文件释放到当前文件夹

将软盘中的文件复原。-i告诉cpio把文件作为它的输入,-d按需要生成目录,-v显示执行时的所有信息,-c具有头文件格式。
[例6]
        $ cpio –icdv "*stat.wp" < /dev/rfd0135ds18
仅复原*stat.wp的文件
[例7]
        $ cpio –i </usr/linfs/old1 *.f
仅复原*.f 文件

序:
(gzip 压缩文件)
gzip 压缩文件对应的解压缩文件为gunzip。压缩后的文件名称为“.gz”。命令格式:
        gzip  filename
        gunzip  filename

initrd.img的压缩(制作)及解压的过程的更多相关文章

  1. 对称加密之AES、压缩解压以及压缩加密解密解压综合实战

    AES 压缩解压 压缩加密解密解压 对称加密: 就是采用这种加密方法的双方使用方式用同样的密钥进行加密和解密.密钥是控制加密及解密过程的指令.算法是一组规则,规定如何进行加密和解密.   因此加密的安 ...

  2. PHP zip压缩文件及解压

    PHP zip压缩文件及解压 利用ZipArchive 类实现 只有有函数.界面大家自己写 ZipArchive(PHP 5.3 + 已自带不需要安装dll) /** * 文件解压 * @param ...

  3. SpringMVC上传压缩文件,解压文件,并检测上传文件中是否有index.html

    SpringMVC上传压缩文件,解压文件,并检测上传文件中是否有index.html 说明: 1.环境:SpringMVC+Spring+Tomcat7+JDK1.7 2.支持 zip和rar格式的压 ...

  4. innobackup stream 压缩备份,解压后的qp文件

    是用innobackup stream 压缩备份,解压后很多文件还是qp格式的压缩文件,需要再解压. 备份: [root@ ~]# /usr/bin/innobackupex --defaults-f ...

  5. spring boot 过滤器实现接收 压缩数据 并解压

    1.新加类GzipRequestWrapper 继承HttpServletRequestWrapper类 public class GzipRequestWrapper extends HttpSer ...

  6. linux下分卷压缩,合并解压的3种方法

    我们上传东西的时候,由于文件过大而不能上传,或者不给上传,最明显的就是发邮件了,附件最大5M,有的10M.如果超过了就郁闷了.这个时候,如果能把压缩的东西,分割开来就比较爽了,windows下面我想大 ...

  7. mariadb 最新精简压缩版 win64 解压即用

    包含版本: mariadb-10.1.18-winx64 mariadb-5.5.53-winx64 32的没有压缩,估计用的人也比较少. 网盘链接: http://pan.baidu.com/s/1 ...

  8. linux 中压缩记得压缩用c,解压用x

    tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...

  9. Unity3D研究院之LZMA压缩文件与解压文件

    原地址:http://www.xuanyusong.com/archives/3095 前两天有朋友告诉我Unity的Assetbundle是LZMA压缩的,刚好今天有时间那么就研究研究LZMA.它是 ...

随机推荐

  1. VC++ Debug产生异常时中断程序执行Break on Exception

    It is possible to instruct the debugger to break when an exception occurs, before a handler is invok ...

  2. TaoKeeper

    基于zookeeper的监控管理工具taokeeper,由淘宝团队开源的zk管理中间件: 按照taokeeper官方说明 http://jm-blog.aliapp.com/?p=1450 下载tao ...

  3. Poj1426

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25721   Accepted: 106 ...

  4. 【BZOJ1509】[NOI2003]逃学的小孩 直径

    [BZOJ1509][NOI2003]逃学的小孩 Description Input 第一行是两个整数N(3  N  200000)和M,分别表示居住点总数和街道总数.以下M行,每行给出一条街道的 ...

  5. i o s 崩溃日志分析

    转自:http://blog.csdn.net/totogo2010/article/details/39892467 要分析崩溃日志,首先需要保留发布时的编译出来的.xcarchive文件.这个文件 ...

  6. iOS 如何用JSONKit读写JSON文件

     如何用JSONKit读写JSON文件 分类: ios2013-04-20 12:46 510人阅读 评论(0) 收藏 举报 JSON文件格式简单,使用方便,值得一用. 目前已经有多个库支持Json文 ...

  7. activeMQ "HelloWorld"实现

    本文主要介绍activeMQ在应用程序中是如何使用的,同个两个实例进行说明,这两个实例分别针对P2P模式和Pub/Sub模式. 开发环境 操作系统:Ubuntu 16.10 开发平台:Eclipse  ...

  8. bootstrap 媒体查询

    //各类设备的分辨率 /*超小设备(手机,小于768px)*/ /* Bootstrap 中默认情况下没有媒体查询 */ /*超小型设备(小于768px)*/ @media (min-width:@s ...

  9. 160714、解决虚拟机上的tomcat无法被主机访问的问题

    备注:我虚拟机是centos 6.5    在wmware中安装linux后安装好数据库,JDK及tomcat后启动服务,虚拟机中可以访问,但是主机却无法访问,但是同时主机和虚拟机之间可以ping的通 ...

  10. Understanding Tensorflow using Go

    原文: https://pgaleone.eu/tensorflow/go/2017/05/29/understanding-tensorflow-using-go/ Tensorflow is no ...