一、啟動鏡像initrd.img 文件
類RedHat 系統從vmlinuz 核心引導后,會讀取initrd.img 啟動鏡像。該文件中包含驅動模塊等信息,是非常重要的文件。不同版本使用的格式不同。
1.RHEL 4.0 版本
采用ext2 文件格式鏡像,再通過gzip 壓縮:
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 壓縮:
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。
如下:
initrd.img: LZMA compressed data, streamed
※ 注意,若在低於RHEL 6.2 版本下執行file 命令,可能無法識別LZMA 壓縮格式:
initrd.img: data
這時,可把file 軟件包升級到5.04-13.el6 即可。
二、xz 工具簡介
xz 工具是LZMA 壓縮算法的一個實現。具體可見:Wikipedia
7-Zip supports xz since version 9.04 beta (stable since 9.20)
可見,Windows 下可使用7-Zip 打開.xz 文件。LZMA 算法比Gzip 算法壓縮率更高。幾個參數:
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 文件
解壓:
壓縮:
三、補充tar.lzma
由於LZMA具有優秀的壓縮率及占用資源少的特點,越來越多的工具采用lzma進行打包,后綴名為:tar.lzma。
對於Fedora 11 及以后的版本,可以使用下面的命令操作:
壓縮
解壓:
如果是CentOS 5.3 等老版本,需要安裝獨立的lzma 工具或用xz 進行:
壓縮:
解壓(兩個方式都可以):
# 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