# initramfs 解压方法
Date: 2019-04-23


最近在学习 _**[鸟哥私房菜第19章](http://linux.vbird.org/linux_basic/0510osloader.php#startup_loader)**_，文章在分析Boot Loader 过程中， 提到到了**虚拟档案系统(Initial RAM Disk或Initial RAM Filesystem)**，

### 1\. CentOS7 initramfs  CPIO解压方案：

用是cpio分解 initramfs文件， 处理过程如下（以CentOS7 为例）：

-    lsinitrd 查看initramfs文件内容；头部说明文档+需要加载内存的核心组件；
-    cpio 算出头部文件占用的block ， dd 命令将头部文件跳过， 输出压缩文件；

分解步骤：

```
cpio -i -d --no-absolute-filenames -I /boot/initramfs-3.10.0-862.el7.x86_64.img
```

输出 26 blocks， 计算获得  512\*26=13312bytes

```
dd if=/boot/initramfs-3.10.0-862.el7.x86_64.img of=initramfs.gz bs=13312 skip=1
```

输出：

1620+1 records in  
1620+1 records out  
21576502 bytes (22 MB) copied, 0.0304529 s, 709 MB/s

再用gzip，cpio 解压 initramfs.gz。

具体步骤参考鸟哥私房菜 19.3.4 initramfs 的重要性与建立新initramfs 档案

### 2\. 其他方法

google下面有两篇关于解压initramfs文件的文章。

[CentOS / RHEL 7 : How to extract initramfs image and edit/view it](https://www.thegeekdiary.com/centos-rhel-7-how-to-extract-initramfs-image-and-editview-it/)

[CentOS / RHEL 6 : How to extract initramfs image and edit/view it](https://www.thegeekdiary.com/centos-rhel-6-how-to-extract-initramfs-image-and-editview-it/)

CenOS7 可以使用 skipcpio 跳过mcrocode部分，之后使用和 CenOS6 一样方式，gzip cpio组合就可以了完成解压

