[Linux] 使用 cpio 指令解開 cpio 檔案
今天拿到了一個檔案,是很不熟悉的 cpio 格式:
testuser@localhost ~ $ file initrd initrd: ASCII cpio archive (SVR4 with no CRC)
查了一下,要把這種檔案解開,可以用同名的 cpio 指令。
來看一下它的說明:
testuser@localhost ~ $ cpio -h cpio(bsdcpio): manipulate archive files First option must be a mode specifier: -i Input -o Output -p Pass Common Options: -v Verbose filenames -V one dot per file Create: cpio -o [options] < [list of files] > [archive] -J,-y,-z,--lzma Compress archive with xz/bzip2/gzip/lzma --format {odc|newc|ustar} Select archive format List: cpio -it < [archive] Extract: cpio -i [options] < [archive] bsdcpio 3.3.2 - libarchive 3.3.2 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.6
可以用 cpio -iv 指令,傳入一個 cpio 檔案並將其解開:
testuser@localhost ~ $ cpio -iv < initrd dev lib lib/modules lib/modules/2.6.32.61 lib/modules/2.6.32.61/kernel lib/modules/2.6.32.61/kernel/arch/x86/kernel/cpuid.ko lib/modules/2.6.32.61/kernel/arch/x86/kernel/microcode.ko lib/modules/2.6.32.61/kernel/arch/x86/kernel/msr.ko ...... lib/modules/2.6.32.61/kernel/drivers/net/qlge/qlge.ko lib/modules/2.6.32.61/kernel/drivers/net/s2io.ko
用 ls 看一下,cpio 檔裡的目錄結構都有成功解出來了:
testuser@localhost ~ $ ll total 0 -rw-rw-r-- 1 testuser staff 0 Jun 16 11:57 auto_patch drwxrwxr-x 67 testuser staff 2144 Jun 16 11:57 bin/ drwxrwxr-x 6 testuser staff 192 Jun 16 11:57 boot/ drwxrwxr-x 9 testuser staff 288 Jun 16 11:57 dev/ drwxrwxr-x 11 testuser staff 352 Jun 16 11:57 etc/ lrwxrwxrwx 1 testuser staff 12 Jun 16 11:57 init@ -> /bin/busybox drwxrwxr-x 41 testuser staff 1312 Jun 16 11:57 lib/ drwxr-xr-x 63 testuser staff 2016 Jun 16 11:57 lib64/ drwxrwxr-x 2 testuser staff 64 Jun 16 11:57 proc/ drwxrwxr-x 44 testuser staff 1408 Jun 16 11:57 sbin/ drwxrwxr-x 2 testuser staff 64 Jun 16 11:57 sys/ lrwxrwxrwx 1 testuser staff 8 Jun 16 11:57 tmp@ -> /var/tmp drwxrwxr-x 6 testuser staff 192 Jun 16 11:57 usr/ drwxrwxr-x 6 testuser staff 192 Jun 16 11:57 var/
參考資料:Linux cpio Examples: How to Create and Extract cpio Archives (and tar archives)
(本頁面已被瀏覽過 2,252 次)