美文网首页
ramdisk 文件系统的解压与还原

ramdisk 文件系统的解压与还原

作者: 黑鼠_DEAN | 来源:发表于2020-04-28 14:12 被阅读0次

    1.通过file ramdisk.gz命令目标文件是否为ramdisk文件系统查看如下:

    ~/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字节的数据给去除,可以还原到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实际为ramdisk.img,且增加了u-boot头,64Bytes大小


    image.png
    1. 通过gunzip rootfs.gz 命令解压文件(这个时候没有任何输出),然后通过 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
    

    此时已将ramdisk.gz文件解压为目录形式,可进行相应修改。
    为方便使用制作成简易执行脚本,保存以下内容为unimage.sh 然后chmod 755 unimage.sh 添加可执行权限。
    运行方法 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
    

    相关文章

      网友评论

          本文标题:ramdisk 文件系统的解压与还原

          本文链接:https://www.haomeiwen.com/subject/oqpvwhtx.html