파일을 안전하게 추출하는 기술은 무엇입니까?

파일을 안전하게 추출하는 기술은 무엇입니까?

어제 몇 가지 실험을 하다가슬리타즈. 여러 initrd.img를 사용하여 파일/변경 사항을 저장합니다.

initrd.gz 이미지(cpio 아카이브) 중 하나를 폴더로 추출하고 편집/삭제한 후 다시 패키지하고 싶습니다.

나는 다음 코드를 사용했습니다.

cat rootfs.img | cpio -idvm

그런 다음 모든 파일이 루트 파일 시스템으로 추출됩니다. 전체 운영 체제가 손상되었습니다. (이 얼마나 당황스러운 장면인가...)

안전하고 쉽게 하려면 어떻게 해야 하나요? 엉긴 덩어리? LXC? (VirtualBox는 최후의 수단입니다)

답변1

상대 경로를 사용하여 보관

루트 수준에서는 이러한 명령을 실행하지 않는 것이 좋습니다 /. 그것은 문제를 요구하고 있습니다. 나는 항상 cpio -idvm내 디렉터리에서 관련 명령을 실행한 다음 필요한 위치에 파일을 사용하거나 수동으로 넣습니다 mv.cp

다른 U&L Q&A에서 설명하는 방법을 사용할 수도 있습니다.SliTaz Linux에 TazPkg를 설치하는 방법, 이는 또한 활용됩니다 cpio.

절대 경로를 사용하여 보관

절대 경로를 사용하여 아카이브를 구축한 경우 스위치를 cpio사용하여 --no-absolute-filenames아카이브가 /.

$ mkdir /tmp/cpio-root
$ cd /tmp/cpio-root
$ cat rootfs.img | cpio -idvm --no-absolute-filenames

인용하다

답변2

unp유틸리티를 사용하여 이를 수행할 수 있습니다.

unp다양한 형식의 압축을 풀기 위한 유틸리티입니다. 해당 기능( -U매개변수) 중 하나는 아카이브를 보고 여러 루트 요소가 있는지 확인하는 기능입니다. 그렇다면 디렉토리로 추출합니다.

예를 들어:

$ echo $RANDOM > a
$ echo $RANDOM > b
$ tar -cf archive.tar a b
$ rm a b
$ unp -U archive.tar
$ ls -l a b archive
ls: cannot access a: No such file or directory
ls: cannot access b: No such file or directory
archive:
total 8
-rw-r--r-- 1 root root 5 Jun 15 03:16 a
-rw-r--r-- 1 root root 6 Jun 15 03:16 b

unp다양한 형식으로 제공됩니다(포함 cpio). 아카이브를 처리하기 위해 적절한 유틸리티를 호출합니다.

# unp -s
Known archive formats and tools:
7z:           p7zip or p7zip-full
ace:          unace
ar,deb:       binutils
arj:          arj
bz2:          bzip2
cab:          cabextract
chm:          libchm-bin or archmage
cpio,afio:    cpio or afio
dat:          tnef
dms:          xdms
exe:          maybe orange or unzip or unrar or unarj or lha 
gz:           gzip
hqx:          macutils
lha,lzh:      lha
lz:           lzip
lzma:         xz-utils or lzma
lzo:          lzop
lzx:          unlzx
mbox:         formail and mpack
pmd:          ppmd
rar:          rar or unrar or unrar-free
rpm:          rpm2cpio and cpio
sea,sea.bin:  macutils
shar:         sharutils
tar:          tar
tar.bz2,tbz2: tar with bzip2
tar.lzip:     tar with lzip
tar.lzop,tzo: tar with lzop
tar.xz,txz:   tar with xz-utils
tar.z:        tar with compress
tgz,tar.gz:   tar with gzip
uu:           sharutils
xz:           xz-utils
zip,cbz,cbr,jar,war,ear,xpi,adf: unzip
zoo:          zoo

출력에는 --help수행할 수 있는 작업이 표시됩니다.

# unp --help

USAGE:
   /usr/bin/unp [ options ] file [ files... ]
   file: compressed file(s) to expand/extract

   Use -- [ ARGUMENTS ] to pass arguments to external programs, eg. some tar options:
   unp fastgl.tgz xmnt.tgz -- -C /tmp

   Options:
   -f Continue even if program availability checks fail or directory collision occurs
   -u Special helper mode.
      For most archive types:
      - create directory <filename without suffix>/
      - extract contents there
      For Debian/Ubuntu packages:
      - extract data.tar.gz after each operation in local directory
      - extract control.tar.gz into control/<package_version_arch>/
   -U Smart mode, acts like -u (see above) if archive contains multiple
      elements but if there is only one file/directory element then it's stored 
      in the current directory.
   -s Show the list of supported formats
   -v More verbosity
   -h Show this help

관련 정보