ramdisk 文件系統(tǒng)的解壓與還原

1.通過file ramdisk.gz命令目標(biāo)文件是否為ramdisk文件系統(tǒng)查看如下:

~/workspace/s32v/uimg ? file rootfs.uimg 
rootfs.uimg: u-boot legacy uImage, fsl-image-nfs-initramfs-s32v234e\037\213\010\010\273\330\302Z\002\003fsl-image-nfs-initramfs-s32v234evb-20180403012440.roo, Linux/ARM 64-bit, RAMDisk Image (gzip), 4113365 bytes, Tue Apr  3 01:28:28 2018, Load Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0x260809A7, Data CRC: 0x18615E72

或者通過dumpimage -l rootfs.uimg

~/workspace/s32v/uimg ? dumpimage -l rootfs.uimg
Image Name:   fsl-image-nfs-initramfs-s32v234e
Created:      Tue Apr  3 09:28:28 2018
Image Type:   AArch64 Linux RAMDisk Image (gzip compressed)
Data Size:    4113365 Bytes = 4016.96 KiB = 3.92 MiB
Load Address: 00000000
Entry Point:  00000000
  1. 通過 dd if=rootfs.uimg of=rootfs.gz bs=64 skip=1 命令將頭部64字節(jié)的數(shù)據(jù)給去除,可以還原到gzip的包頭。
~/workspace/s32v/uimg ? dd if=rootfs.uimg of=rootfs.gz bs=64 skip=1
64271+1 records in
64271+1 records out
4113365 bytes (4.1 MB, 3.9 MiB) copied, 0.163262 s, 25.2 MB/s

通過 file 命令查看是否還原正確,輸出以下信息,可以看到文件已變成了gzip文件。

~/workspace/s32v/uimg ? file rootfs.gz
rootfs.gz: gzip compressed data, was "fsl-image-nfs-initramfs-s32v234evb-20180403012440.rootfs.cpio", last modified: Tue Apr  3 01:28:27 2018, max compression, from Unix
----

可知ramdisk.gz實(shí)際為ramdisk.img,且增加了u-boot頭,64Bytes大小


image.png
  1. 通過gunzip rootfs.gz 命令解壓文件(這個(gè)時(shí)候沒有任何輸出),然后通過 file命令看文件已解壓成CPIO文件。
~/workspace/s32v/uimg ? file rootfs 
rootfs: ASCII cpio archive (SVR4 with no CRC)

  1. 通過cpio解壓
 mkdir tmp
 cd tmp/
 sudo cpio -idv < ../rootfs
 ls
-----------------------------------------------------------------------
bin   dev  home  lib      media  proc  sbin  tmp  var
boot  etc  init  linuxrc  mnt    run   sys   usr

此時(shí)已將ramdisk.gz文件解壓為目錄形式,可進(jìn)行相應(yīng)修改。
為方便使用制作成簡(jiǎn)易執(zhí)行腳本,保存以下內(nèi)容為unimage.sh 然后chmod 755 unimage.sh 添加可執(zhí)行權(quán)限。
運(yùn)行方法 unimage.sh rootfs.uimg

#!/bin/bash
dd if=$1 of=rootfs.gz bs=64 skip=1
gunzip rootfs.gz
mkdir tmp
cd tmp
cpio -idv < ../rootfs
  1. 重新打包,步驟與解壓相反。
cd tmp
find . | cpio -o --format=newc > ../rootfs.img
cd ..
gzip -c rootfs.img > rootfs.img.gz
mkimage -A arm64 -C none -O linux -T ramdisk -d rootfs.img.gz -a 0x84000000 \
    -e 0x84000000 rootfs.uimg
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容