
어제 나는 몇 가지 실험을 하고 있었습니다.슬리타즈. 여러 개의 initrd.img를 사용하여 파일/변경 사항을 저장합니다.
initrd.gz 이미지(cpio 아카이브) 중 하나를 폴더로 추출하고 편집/제거하고 다시 압축하고 싶었습니다.
나는 다음 코드를 사용했습니다.
cat rootfs.img | cpio -idvm
그런 다음 모든 파일이 루트 파일 시스템으로 추출됩니다. 전체 OS가 손상되었습니다. (이 얼마나 당황스러운 상황인가...)
이러한 작업을 안전하면서도 쉽게 하려면 어떻게 해야 합니까? Chroot? 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