The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

30

The cpio block skip method given doesn't work reliably. That's because the initrd images I was getting myself didn't have both archives concatenated on a 512 byte boundary. Instead, do this: apt-get install binwalk legolas [mc]# binwalk initrd.img DECIMAL HEXADECIMAL DESCRIPTION --------------------------------------------------------------------...


20

If you know your initrd.img consists of an uncompressed cpio archive followed by a gz-compressed cpio archive, you can use the following to extract all files (from both archives) into your current working directory (tested in bash): (cpio -id; zcat | cpio -id) < /path/to/initrd.img The above command-line passes the contents of initrd.img as standard ...


16

It turns out the initrd generated by Debian's live-build (and to my surprise, accepted by the kernel) is actually the concatenation of two images: a CPIO archive containing microcode updates to be applied on the processor; a gzip-ed cpio archive, which actually contains the initrd file tree (with the /etc /bin /sbin /dev ... directories that were expected). ...


11

So recently I wanted to do this with tar. Some investigation indicated to me that it was more than a little nonsensical that I couldn't. I did come up with this weird split --filter="cat >file; tar -r ..." thing, but, well, it was terribly slow. And the more I read about tar the more nonsensical it seemed. You see, tar is just a concatenated list of ...


9

Quoting Documentation/filesystems/ramfs-rootfs-initramfs.txt: Why cpio rather than tar? This decision was made back in December, 2001. The discussion started here: http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1538.html And spawned a second thread (specifically on tar vs cpio), starting here: http://www.uwsg.iu.edu/...


9

It's very reliable and supported by all kernel versions that support initrd, AFAIK. It's a feature of the cpio archives that initramfs are made up of. cpio just keeps on extracting its input....we might know the file is two cpio archives one after the other, but cpio just sees it as a single input stream. Debian advises use of exactly this method (...


9

You can do this with GNU cpio: $ find . | cpio -o -H newc > /tmp/file 40 blocks $ file /tmp/file /tmp/file: ASCII cpio archive (SVR4 with no CRC)


8

thank you for all your answers. I solved the problem by using ps faux and identified that sync does nothing/waits forever. As i had an usb drive which somehow died and got disconnected the drive still showed up as being mounted. I renamed /bin/sync to /bin/sync2, copied /bin/ls to /bin/sync and ran apt-get upgrade. It was successful so I renamed the files, ...


5

Since you're using cpio, you're actually making an initramfs, not an initrd. An initrd would be stored as a filesystem image, not as a cpio archive. Initrd and initramfs have similar roles in the Linux boot process, to provide some files that are available before the true root filesystem (and that are used to mount the true root filesystem); they are handled ...


5

It is still relevant for unpacking RPMs. There is a rpm2cpio utility that converts an RPM package to a cpio archive. As far as I know, there is nothing to convert an RPM to a tar archive. Here is an example usage: rpm2cpio myrpmfile.rpm | cpio -idmv


5

The first error is because you're passing both -H newc and -c. You have to make up your mind on the format of the archive you want to generate. The "Operation not permitted" is a bug in GNU cpio, it's passing wrong arguments to the function that outputs that error message and should exit there. The other errors are because you're not running that command as ...


5

Archived with relative paths I would advise against running that type of command at your root level, /. That's asking for trouble. I always run cpio -idvm related commands in their own directories, and then use mv or cp to put the files where they need to be manually. You can also use the method I described in this other U&L Q&A titled: How do I ...


5

cpio (the older of the two utilities counting shipping with UNIX) only used to have hard link support for the -p option (i.e. copying from filesystem to filesystem), but the newc output format (not the default one cpio uses) also supports hard links in the output file. (GNU) tar supports hard links without any special options. A comparison can be found here....


4

For some weird reason, cpio doesn't like to take a file argument. Instead, you have to pipe the archive into cpio. An inexperienced user would do the following: cat initramfs-linux.img | cpio -i However, this would get you the Useless Use of cat Award. A better way would be: cpio -i < initramfs-linux.img This uses the shell's built-in redirection ...


4

You problem puzzled me for some time, and I think I have found a solution that would work. I think you can achieve what you want with 7z using the -si{NAME} flag. You will be able to adapt to your need. 7z a test.7z -siSDA2.txt < /dev/sda1 7z a test.7z -siSDA2.txt < /dev/sda2 7z l test.7z 7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-...


4

piping should be enough. Doing just: tar -cvj /path/to/your/files | ssh remote "cat > file.tar.bz2" (if you have set up passwordless log in using keys) Later on the other machine you can decompress the received file using tar -xvf path.tar.bz2 -C ./


4

gunzip needs to be run only once (consuming all input), whereas cpio should be run once per embedded archive, like so: gunzip -c <input.cgz | while cpio -i; do :; done


3

You can use the unp utility for this. unp is a utility for unpacking multiple formats. One of it's features (the -U argument) is the ability to look into the archive and see if it has multiple root elements. If it does, it extracts them into a directory. For example: $ echo $RANDOM > a $ echo $RANDOM > b $ tar -cf archive.tar a b $ rm a b $ unp -U ...


3

Those two option do the same, they make the directory towards where the file is to be created. If you don't specify either of those options and the directory where a file is going to be created doesn't exist, then cpio will throw an error. cd /tmp mkdir -p test1/a cd test1/a touch x1 x2 find . | cpio -pmv ../b Gives an error: cpio ../b/./x1 Cannot open: ...


3

Great! Rsync is your beast and is is well worth the learning curve, (there are many options). I wouldn't bother with worrying about your find modified last 2 days requirement either, since rsync will check for modification (which achieves more or less the the same, cuts down on what is transfered and only copies files that have been updated compared to ...


3

With pax as found on Debian, Suse, OpenBSD, NetBSD at least: find . -type f -name '*.pat' -print0 | pax -0rws'/?/_/gp' /path/to/dest/ pax is a standard utility (contrary to tar or cpio), but its -0 option is not, though can be found in a few implementations. If there's both a ?.pat and _.pat files, they will end up replaced with same name so one will ...


3

One can use GNU tar for it: $ find -type f -name '*.pat' -print0 | tar -c -f - --null --files-from - \ | tar -C /path/to/dest -v -x -f - --show-transformed --transform 's/?/_/g' Advantages: only 3 forks/execs needed (independent of the number of files) the selection of source files is very flexible - you can use the full power of (GNU) find for that (...


3

You should not process the output from ls into cpio. The 'standard' way of getting file names into cpio is using find: find /med*/ravb*/*36/b/c/* -type f | cpio ... or on Linux systems: find /med*/ravb*/*36/b/c/* -type f -print0 | cpio -0 ... that handles file names with newlines and other special characters as well. -type f only selects files.


3

If you have python and: install libarchive-c (e.g. using pip install libarchive-c) have all your files under directory root in the current directory ( I used mkdir -p root/xyz ; echo 1 > root/abc.txt ; echo 2> root/xyz/def.txt ) save the following as abscpio and make it executable (chmod 755 abscpio) #! /usr/bin/env python import os import sys from ...


3

Spaces in file names can be tricky, but I think this might help. Instead of cating your files-to-extract, try feeding it through xargs substituting the NULL character for EOL. Something like tr '\n' '\0' < list-of-files | xargs -0 -I{} sh -c 'cpio -icuBdmv "{}" < preserved.cpio' should do the trick.


3

You can use fakeroot. As the name says, it fakes the root user, by intercepting serveral syscalls with a LD_LIBRARY_PATH/LD_PRELOAD library wrapper, to have the process believe it's running as root. This has been created for the purpose of building and packaging applications without having to be root, including using make install which typically would be run ...


2

You are not using cpio correctly. http://www.gnu.org/software/cpio/ What you did is write the contents of the file to a block device representing a partition. You likely ruined the file system on that partition. cpio should be used to write things to a tape device, tar archive or other files. What you probably wanted is something like: mount /dev/sda10 /...


2

The options that the BusyBox commands have depends a lot on the options that BusyBox is compiled with. BusyBox aims to be highly configurable so that very small cut down versions can be compiled for systems where resources are very limited. Larger, more full featured versions can be built where this isn't an issue. In your case cpio needs the -p or --pass-...


2

In former times, there was an advantage of using cpio but this special feature is not implemented in e.g. gcpio. I am talking about the fact that the original AT&T cpio implementation did implement file extraction in a specific way that is similar to what install does and this is the reason why AT&T preferred to use cpio to install binaries on a live ...


2

If your system doesn't have a GNU tar with its -T and --null option cpio is the way to get a specific subset of files into a a tar archive: find . -name CVS -prune -o -print0 | cpio -o -Hustar > all.tar I also often find the -V/--dot much more informative on progress then full verbose mode (in tar or cpio)in cases where you rougly know how many files ...


Only top voted, non community-wiki answers of a minimum length are eligible