Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

11 votes
3 answers
10603 views
Appending files to initramfs image - reliable?
I'm modifying a bunch of `initramfs` archives from different Linux distros in which normally only one file is being changed. I would like to automate the process without switching to root user to extract all files inside the `initramfs` image and packing them again. First I've tried to generate a li...
I'm modifying a bunch of initramfs archives from different Linux distros in which normally only one file is being changed. I would like to automate the process without switching to root user to extract all files inside the initramfs image and packing them again. First I've tried to generate a list of files for gen_init_cpio *without* extracting all contents on the initramfs archive, i.e. parsing the output of cpio -tvn initrd.img (like ls -l output) through a script which changes all permissions to octal and arranges the output to the format gen_init_cpio wants, like: dir /dev 755 0 0 nod /dev/console 644 0 0 c 5 1 slink /bin/sh busybox 777 0 0 file /bin/busybox initramfs/busybox 755 0 0 This involves some replacements and the script may be hard to write for me, so I've found a better way and I'm asking about how safe and portable is: In some distros we have an initramfs file with concatenated parts, and apparently the kernel parses the whole file extracting all parts packed in a 1-byte boundary, so there is no need to fill each part to a multiple of 512 bytes. I thought this 'feature' can be useful for me to avoid recreating the archive when modifying files inside it. Indeed it works, at least for Debian and CloneZilla. For example if we have modified the /init file on initrd.gz of Debian 8.2.0, we can append it to initrd.gz image with: $ echo ./init | cpio -H newc -o | gzip >> initrd.gz so initrd.gz has two concatenated archives, the original and its modifications. Let's see the result of binwalk: DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 0 0x0 gzip compressed data, maximum compression, has original file name: "initrd", from Unix, last modified: Tue Sep 1 09:33:08 2015 6299939 0x602123 gzip compressed data, from Unix, last modified: Tue Nov 17 16:06:13 2015 It works perfectly. But it is reliable? what restrictions do we have when appending data to initfamfs files? it is safe to append without padding the original archive to a multiple of 512 bytes? from which kernel version is this feature supported?
Emilio Lazo (253 rep)
Nov 17, 2015, 06:05 PM • Last activity: Jul 21, 2025, 04:09 AM
9 votes
5 answers
8617 views
Extracting concatenated cpio archives
initramfs archives on Linux can consist of a series of concatenated, gzipped cpio files. Given such an archive, how can one extract *all* the embedded archives, as opposed to only the first one? The following is an example of a pattern which, while it appears to have potential to work, extracts only...
initramfs archives on Linux can consist of a series of concatenated, gzipped cpio files. Given such an archive, how can one extract *all* the embedded archives, as opposed to only the first one? The following is an example of a pattern which, while it appears to have potential to work, extracts only the first archive: while gunzip -c | cpio -i; do :; done skipcpio helper from dracut to move the file pointer past the first cpio image, but the following results in a corrupt stream (not at the correct point in the input) being sent to cpio: # this isn't ideal -- presumably would need to rerun with an extra skipcpio in the pipeline # ...until all files in the archive have been reached. gunzip -c
Charles Duffy (1890 rep)
Feb 26, 2016, 08:49 PM • Last activity: Dec 20, 2024, 06:07 PM
1 votes
1 answers
3488 views
Using cpio command to compress directory and move it
I want to make /lib/modules compress copy and move to /opt directory. using `cpio` I try this cpio /lib/modules > directory.cpio | mv directory.cpio /opt
I want to make /lib/modules compress copy and move to /opt directory. using cpio I try this cpio /lib/modules > directory.cpio | mv directory.cpio /opt
Top Music (11 rep)
Jan 4, 2019, 01:48 PM • Last activity: Jul 5, 2024, 04:02 PM
0 votes
1 answers
600 views
How to repack an initramfs cpio archive?
I have unpacked an initramfs cpio archive, and repacked it with `sudo find -depth | sudo cpio -o -H newc > ~/repacked_initramfs.cpio`, as per: https://salsa.debian.org/kernel-team/initramfs-tools/-/blob/master/mkinitramfs?ref_type=heads#L492 The repacked_initramfs.cpio is exactly the same size as th...
I have unpacked an initramfs cpio archive, and repacked it with sudo find -depth | sudo cpio -o -H newc > ~/repacked_initramfs.cpio, as per: https://salsa.debian.org/kernel-team/initramfs-tools/-/blob/master/mkinitramfs?ref_type=heads#L492 The repacked_initramfs.cpio is exactly the same size as the original:
~ $ ls -lA initramfs.cpio repacked_initramfs.cpio
-rw-r--r-- 1 fadedbee fadedbee 227892224 Apr  3 15:27 initramfs.cpio
-rw-r--r-- 1 fadedbee fadedbee 227892224 Apr  8 15:32 repacked_initramfs.cpio
The gzipped size is slightly different:
root@smarcimx8mq4g:~# ls -lA initramfs.cpio repacked_initramfs.cpio
-rw-r--r-- 1 root root 227892224 Apr  3 14:27 initramfs.cpio
-rw-r--r-- 1 user user 227892224 Apr  8 14:32 repacked_initramfs.cpio

root@smarcimx8mq4g:~# gzip initramfs.cpio

root@smarcimx8mq4g:~# gzip repacked_initramfs.cpio 

root@smarcimx8mq4g:~# ls -lA initramfs.cpio.gz repacked_initramfs.cpio.gz 
-rw-r--r-- 1 root root 68217581 Apr  3 14:27 initramfs.cpio.gz
-rw-r--r-- 1 user user 68212934 Apr  8 14:32 repacked_initramfs.cpio.gz
As are the sizes of the .img files:
root@smarcimx8mq4g:~# mkimage -A arm64 -O linux -T ramdisk -n "Initial Ram Disk" -d initramfs.cpio.gz initramfs.img
Image Name:   Initial Ram Disk
Created:      Mon Apr  8 15:29:54 2024
Image Type:   AArch64 Linux RAMDisk Image (gzip compressed)
Data Size:    68217581 Bytes = 66618.73 KiB = 65.06 MiB
Load Address: 00000000
Entry Point:  00000000

root@smarcimx8mq4g:~# mkimage -A arm64 -O linux -T ramdisk -n "Initial Ram Disk" -d repacked_initramfs.cpio.gz repacked_initramfs.img
Image Name:   Initial Ram Disk
Created:      Mon Apr  8 15:30:21 2024
Image Type:   AArch64 Linux RAMDisk Image (gzip compressed)
Data Size:    68212934 Bytes = 66614.19 KiB = 65.05 MiB
Load Address: 00000000
Entry Point:  00000000

root@smarcimx8mq4g:~# ls -lA initramfs.img repacked_initramfs.img 
-rw-r--r-- 1 root root 68217645 Apr  8 15:29 initramfs.img
-rw-r--r-- 1 root root 68212998 Apr  8 15:30 repacked_initramfs.img
When I boot from the original initramfs, it mounts the real rootfs from the initramfs and I get the expected login prompt:
u-boot$ setenv loadinitrd ext4load mmc ${mmcdev}:2 ${initrd_addr} /root/initramfs.img
u-boot$ setenv mmcboot "echo Booting from mmc ...; run mmcargs; if test ${boot_fdt} = yes || test ${boot_fdt} = try; then if run loadfdt; then run loadinitrd ; booti ${loadaddr} ${initrd_addr} ${fdt_addr}; else echo WARN: Cannot load the DT; fi; else echo wait for boot; fi;"
u-boot$ run bootcmd
Setting bus to 0
1050 bytes read in 13 ms (78.1 KiB/s)
Importing environment from mmc (uEnv.txt)...
30075392 bytes read in 1280 ms (22.4 MiB/s)
49035 bytes read in 20 ms (2.3 MiB/s)
Booting from mmc ...
49035 bytes read in 19 ms (2.5 MiB/s)
68217645 bytes read in 2849 ms (22.8 MiB/s)
## Loading init Ramdisk from Legacy Image at 43800000 ...
   Image Name:   Initial Ram Disk
   Image Type:   AArch64 Linux RAMDisk Image (gzip compressed)
   Data Size:    68217581 Bytes = 65.1 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 43000000
   Booting using the fdt blob at 0x43000000
   Using Device Tree in place at 0000000043000000, end 000000004300ef8a

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
...
[    7.655738] Freeing unused kernel memory: 3008K
[    7.669121] Run /init as init process
Loading, please wait...
[    7.715755] udevd: starting version 3.2.9
...
smarcimx8mq4g login:
but with the repacked initramfs I see:
u-boot$ setenv loadinitrd ext4load mmc ${mmcdev}:2 ${initrd_addr} /root/repacked_initramfs.img
u-boot$ setenv mmcboot "echo Booting from mmc ...; run mmcargs; if test ${boot_fdt} = yes || test ${boot_fdt} = try; then if run loadfdt; then run loadinitrd ; booti ${loadaddr} ${initrd_addr} ${fdt_addr}; else echo WARN: Cannot load the DT; fi; else echo wait for boot; fi;"
u-boot$ run bootcmd
Setting bus to 0
1050 bytes read in 13 ms (78.1 KiB/s)
Importing environment from mmc (uEnv.txt)...
30075392 bytes read in 1281 ms (22.4 MiB/s)
49035 bytes read in 19 ms (2.5 MiB/s)
Booting from mmc ...
49035 bytes read in 19 ms (2.5 MiB/s)
68212998 bytes read in 2853 ms (22.8 MiB/s)
## Loading init Ramdisk from Legacy Image at 43800000 ...
   Image Name:   Initial Ram Disk
   Image Type:   AArch64 Linux RAMDisk Image (gzip compressed)
   Data Size:    68212934 Bytes = 65.1 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 43000000
   Booting using the fdt blob at 0x43000000
   Using Device Tree in place at 0000000043000000, end 000000004300ef8a

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
...
[    6.868638] Freeing unused kernel memory: 3008K
[    6.880635] Run /init as init process
[    6.884549] Failed to execute /init (error -2)
[    6.889004] Run /sbin/init as init process
[    6.893169] Run /etc/init as init process
[    6.897247] Run /bin/init as init process
[    6.901328] Run /bin/sh as init process
[    6.905221] Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.
[    6.919390] CPU: 3 PID: 1 Comm: swapper/0 Not tainted 5.10.9 #43
[    6.925394] Hardware name: Embedian SMARC-iMX8M Computer on Module HDMI (DT)
[    6.932440] Call trace:
[    6.932617] usb 3-1.2: new high-speed USB device number 3 using xhci-hcd
[    6.934895]  dump_backtrace+0x0/0x1b0
[    6.945239]  show_stack+0x18/0x68
[    6.948556]  dump_stack+0xd8/0x134
[    6.951957]  panic+0x174/0x33c
[    6.955012]  kernel_init+0xfc/0x118
[    6.958500]  ret_from_fork+0x10/0x34
[    6.962078] SMP: stopping secondary CPUs
[    6.966509] Kernel Offset: disabled
[    6.969997] CPU features: 0x0240002,2000200c
[    6.974264] Memory Limit: none
[    6.977324] ---[ end Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance. ]---
I've re-extracted the repacked-initramfs.cpio and proved that /init exists and has identical permissions, ownership and sha1sum as in initramfs.cpio. What repacking mistake could I be making, which would cause the kernel to not find /init, despite it existing correctly in the repacked_initramfs.cpio?
fadedbee (1113 rep)
Apr 8, 2024, 03:58 PM • Last activity: Apr 10, 2024, 01:50 PM
0 votes
1 answers
84 views
How can I rearchive an initramfs cpio, without losing the hard links?
I have a Debian initramfs, which: - I uncompressed with: ``` ~/my_initramfs $ sudo cpio -idmBv ~/my_initramfs.cpio . ./run ./usr ./usr/bin ... ./sbin ./init 81237 blocks ``` The new archive is now twice the size of the original. ``` ~/my_initramfs $ ls -lA ../*initramfs.cpio -rw-r--r-- 1 fadedbee fa...
I have a Debian initramfs, which: - I uncompressed with:
~/my_initramfs $ sudo cpio -idmBv  ~/my_initramfs.cpio
.
./run
./usr
./usr/bin
...
./sbin
./init
81237 blocks
The new archive is now twice the size of the original.
~/my_initramfs $ ls -lA ../*initramfs.cpio
-rw-r--r-- 1 fadedbee fadedbee 227892224 Apr  3 15:27 ../initramfs.cpio
-rw-r--r-- 1 radedbee fadedbee 415933440 Apr  8 11:03 ../my_initramfs.cpio
Looking at the contents of the two cpio archives, it looks as if the new archive has many (differently named) copies of busybox:
~/my_initramfs $ cpio -itv  ~/my_initramfs.cpio
cpio: --link is meaningless with --create
Try 'cpio --help' or 'cpio --usage' for more information.
fadedbee (1113 rep)
Apr 8, 2024, 10:35 AM • Last activity: Apr 8, 2024, 12:30 PM
3 votes
1 answers
87 views
Why is Tar speed not same?
I heard somewhere on the Internet that cpio is faster than tar. So I tried to check it with my shell script. ``` #1/bin/bash rm ct.tar ct.cpio sync && sudo sh -c "/usr/bin/echo 3 > /proc/sys/vm/drop_caches" #nocache start="$(date -u +%s.%N)" tar cf cpiotar.tar end="$(date -u +%s.%N)" elipsed="$(bc /...
I heard somewhere on the Internet that cpio is faster than tar. So I tried to check it with my shell script.
#1/bin/bash

rm ct.tar ct.cpio
sync && sudo sh -c "/usr/bin/echo 3 > /proc/sys/vm/drop_caches"  #nocache

start="$(date -u +%s.%N)"
tar cf cpiotar.tar
end="$(date -u +%s.%N)"
elipsed="$(bc  /proc/sys/vm/drop_caches"  #nocache

start="$(date -u +%s.%N)"
find $1 -depth | cpio -o > ct.cpio
end="$(date -u +%s.%N)"
elapsed="$(bc <<<"$end-$start")"
echo "cpio $elapsed"
This shell script archive 'parameter' directory and check time elapsed. I ran script with a directory whose size is nearly 1GB. The result is below.
tar 74.157502069
cpio 10.269119009
and if I run script again, the result is below.
tar 3.335409300
cpio 7.097516017
The result is really weird. tar suddenly became dramatically fast, since cpio show no difference. Why did this happen?
gdhong (31 rep)
Apr 2, 2024, 01:36 AM • Last activity: Apr 2, 2024, 01:44 PM
1 votes
1 answers
75 views
CPIO Archive Hexdump on a Big-Endian Linux Machine
I'm on a little-endian linux machine and would like to see the canoncial hexdump of a cpio archive on big-endian linux machine. Can someone please run these commands on a big-endian linux and post the output: echo TESTING > /tmp/test cpio -o /tmp/test.cpio hexdump -C /tmp/test.cpio If you are curiou...
I'm on a little-endian linux machine and would like to see the canoncial hexdump of a cpio archive on big-endian linux machine. Can someone please run these commands on a big-endian linux and post the output: echo TESTING > /tmp/test cpio -o /tmp/test.cpio hexdump -C /tmp/test.cpio If you are curious, I need this because libmagic does the following to determine the cpio archive type: # same byteorder machine 0 short 070707 26 string >\0 cpio archive # opposite byteorder machine 0 short 0143561 byte-swapped cpio archive I want to see if there's a reason libmagic doesn't check 26th byte of the archive for the opposite byteorder machine. The output of the command on my little-endian machine: 1 block 00000000 c7 71 1b 00 57 01 a4 81 e8 03 e8 03 01 00 00 00 |.q..W...........| 00000010 ff 65 ce a4 0a 00 00 00 08 00 2f 74 6d 70 2f 74 |.e......../tmp/t| 00000020 65 73 74 00 54 45 53 54 49 4e 47 0a c7 71 00 00 |est.TESTING..q..| 00000030 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 |................| 00000040 0b 00 00 00 00 00 54 52 41 49 4c 45 52 21 21 21 |......TRAILER!!!| 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000200
Arash Rohani (130 rep)
Mar 24, 2024, 04:09 AM • Last activity: Mar 26, 2024, 02:58 AM
15 votes
3 answers
5772 views
How to convince tar (etc.) to archive block device contents?
I have six Linux logical volumes that together back a virtual machine. The VM is currently shutdown, so its easy to take consistent images of them. I'd like to pack all six images together in an archive. Trivially, I could do something like this: cp /dev/Zia/vm_lvraid_* /tmp/somedir tar c /tmp/somed...
I have six Linux logical volumes that together back a virtual machine. The VM is currently shutdown, so its easy to take consistent images of them. I'd like to pack all six images together in an archive. Trivially, I could do something like this: cp /dev/Zia/vm_lvraid_* /tmp/somedir tar c /tmp/somedir | whatever But that of course creates an extra copy. I'd like to avoid the extra copy. The obvious approach: tar c /dev/Zia/vm_lvraid_* | whatever does not work, as tar recognizes the files a special (symlinks in this case) and basically stores the ln -s in the archive. Or, with --dereference or directly pointed at /dev/dm-X, it recognizes them as special (device files) and basically stores the mknod in the archive. I've searched for command-line options to tar to override this behavior, and couldn't find any. I also tried cpio, same problem, and couldn't find any options to override it there, either. I also tried 7z (ditto). Same with pax. I even tried zip, which just got itself confused. edit: Looking at the source code of GNU tar and GNU cpio, it appears neither of them can do this. At least, not without serious trickery (the special handling of device files can't be disabled). So, suggestions of serious trickery would be appreciated or alternate utilities. *TLDR:* Is there some archiver that will pack multiple disk images together (taken from raw devices) and stream that output, without making extra on-disk copies? My preference would be output in a common format, like POSIX or GNU tar.
derobert (112979 rep)
Aug 19, 2014, 08:37 PM • Last activity: Dec 31, 2023, 02:16 PM
7 votes
2 answers
9634 views
How to extract a single file from a cpio archive?
I have a cpio archive with lots of files and I need to extract only one file, not all. With `tar` I could just use `tar -xf archive.tar path/to/file`, but that does not work with `cpio`: cpio -i < archive.cpio path/to/file bash: path/to/file: No such file or directory Does anyone know how to extract...
I have a cpio archive with lots of files and I need to extract only one file, not all. With tar I could just use tar -xf archive.tar path/to/file, but that does not work with cpio: cpio -i < archive.cpio path/to/file bash: path/to/file: No such file or directory Does anyone know how to extract just a single file from a cpio archive?
manifestor (2563 rep)
Mar 2, 2019, 08:42 AM • Last activity: Sep 21, 2023, 10:08 PM
9 votes
4 answers
10964 views
How to generate initramfs image with busybox links?
Having been directed to initramfs by an answer to [my earlier question][1] (thanks!), I've been working on getting initramfs working. I can now boot the kernel and drop to a shell prompt, where I can execute busybox commands, which is awesome. Here's where I'm stuck-- there are (at least) two method...
Having been directed to initramfs by an answer to my earlier question (thanks!), I've been working on getting initramfs working. I can now boot the kernel and drop to a shell prompt, where I can execute busybox commands, which is awesome. Here's where I'm stuck-- there are (at least) two methods of generating initramfs images: 1. By passing the kernel a path to a prebuilt directory hierarchy to be compressed 2. By passing the kernel the name of a file that lists the files to be included. The second method seemed a little cleaner, so I've been using that. Just for reference, here's my file list so far: dir /dev 755 0 0 nod /dev/console 644 0 0 c 5 1 nod /dev/loop0 644 0 0 b 7 0 dir /bin 755 1000 1000 slink /bin/sh busybox 777 0 0 file /bin/busybox /home/brandon/rascal-initramfs/bin/busybox 755 0 0 dir /proc 755 0 0 dir /sys 755 0 0 dir /mnt 755 0 0 file /init /home/brandon/rascal-initramfs/init.sh 755 0 0 Unfortunately, I have learned that busybox requires a long list of links to serve as aliases to all of its different commands. Is there a way to generate the list of all these commands so I can add it to my file list? Alternatively, I could switch to method 1, using the prebuilt directory hierarchy, but I'm not sure how to make the /dev nodes in that case. Both of these paths seem messy. Is there an elegant solution to this?
pingswept (1135 rep)
Dec 9, 2010, 09:59 PM • Last activity: Feb 22, 2023, 05:46 PM
-1 votes
2 answers
1284 views
Archived rootfs: convert tar to cpio for initramfs
I have a Debian rootfs as a tar file. I would like to specify it as the initramfs source in Kconfig (using PetaLinux), but the source must be a cpio archive. How can I convert the .tar to .cpio, maintaining its structure, permissions, etc.?
I have a Debian rootfs as a tar file. I would like to specify it as the initramfs source in Kconfig (using PetaLinux), but the source must be a cpio archive. How can I convert the .tar to .cpio, maintaining its structure, permissions, etc.?
A. Michael (67 rep)
Mar 17, 2019, 03:56 PM • Last activity: Dec 7, 2022, 01:17 AM
0 votes
1 answers
207 views
The file produced unpacking a kernel file with (gunzip and cpio),overwriting some files and repacking everything,is not bootable
How the title says,I'm trying to unpacking a kernel file (let's say the first one : initrd.img-5.10.0-18-amd64.gz) with gunzip and cpio,overwriting some files and repacking everything. The issue is that the new kernel file produced is not bootable. Someone can help me to understand why ? Even the si...
How the title says,I'm trying to unpacking a kernel file (let's say the first one : initrd.img-5.10.0-18-amd64.gz) with gunzip and cpio,overwriting some files and repacking everything. The issue is that the new kernel file produced is not bootable. Someone can help me to understand why ? Even the size is different. What I would like to do is to alter the content of the initrd.img* files because I'm trying to customize the Debian 11 ISO image with a set of new configuration files,logos and images using CUBIC on Ubuntu 22.04 as host os and Debian 11 as "guest" inside CUBIC. Below are the commands that I have issued : mkdir /home/ziomario/Scrivania/PassT-Cubic/kernels mkdir /home/ziomario/Scrivania/PassT-Cubic/kernels/unzipped mkdir /home/ziomario/Scrivania/PassT-Cubic/kernels/unzipped/initrd.img-5.10.0-18-amd64 cd /home/ziomario/Scrivania/PassT-Cubic/kernels/ gunzip -k initrd.img-5.10.0-18-amd64.gz mkdir /home/ziomario/Scrivania/PassT-Cubic/kernels/unzipped/initrd.img-5.10.0-18-amd64 cpio -idv ../../initrd.img-5.10.0-18-amd64 find: warning: you have specified the global option -depth after the argument -print, but global options are not positional, i.e., -depth affects tests specified before it as well as those specified after it. Please specify global options before other arguments. 893621 blocks cd ../.. gzip initrd.img-5.10.0-18-amd64 After "burning" a new ISO image with CUBIC and chosing the default kernel to boot with, I seen that the produced kernel files are not able to boot. Infact their size are bigger than the original ones. This is the error reported when I tried to boot them within a VM : https://ibb.co/rm5WRSz I don't know why. Inside the kernel files It seems that everything is ok. I have placed the wrong files in my google drive. Maybe you want to test them on your side ? Thanks for your very very useful support. https://drive.google.com/drive/folders/16z5INJTSB3YcpzE980q9eqRIRVG02-JH?usp=sharing Anyway,the error reported is : https://ibb.co/rm5WRSz
Marietto (579 rep)
Oct 27, 2022, 02:29 PM • Last activity: Nov 1, 2022, 10:43 AM
0 votes
1 answers
86 views
"initrd.img-5.10.0-18-amd64" exists but is not a a directory. Function "open" failed: is not a directory : trying to overwrite a file inside cpio arch
I would like to overwrite a file that's already located inside a cpio folder with a new file that has the same name. I'm having some troubles by finding the working parameters. I've found this webpage that may have the solution,but I'm not sure : https://drumperl.wordpress.com/2014/01/12/forcing-cpi...
I would like to overwrite a file that's already located inside a cpio folder with a new file that has the same name. I'm having some troubles by finding the working parameters. I've found this webpage that may have the solution,but I'm not sure : https://drumperl.wordpress.com/2014/01/12/forcing-cpio-to-overwrite-files/ Anyway,I tried to do this : echo usr/share/plymouth/themes/homeworld/debian.png | cpio -pumd /home/ziomario/Scrivania/PassT-Cubic/kernels/initrd.img-5.10.0-18-amd64 Keep in consideration that the file that I want to copy inside the cpio archive (initrd.img-5.10.0-18-amd64) is called "debian.png" and that inside it there is a file with the same name. The command that I have issued above give the following error : **"initrd.img-5.10.0-18-amd64" exists but is not a a directory. Function "open" failed: is not a directory** thanks very much.
Marietto (579 rep)
Oct 27, 2022, 04:18 PM • Last activity: Oct 27, 2022, 04:53 PM
0 votes
0 answers
250 views
cpio archive with folder named . (only a single dot character)
I'm trying to make an install package for Mac OS from my Linux PC. For this purpose I need to pack my folders with data inside the (POSIX.1) portable format archive. This archive should have the folder named dot in the root and the rest of the folders under it, like this (I've took Adop OpenJDK Mac...
I'm trying to make an install package for Mac OS from my Linux PC. For this purpose I need to pack my folders with data inside the (POSIX.1) portable format archive. This archive should have the folder named dot in the root and the rest of the folders under it, like this (I've took Adop OpenJDK Mac OS install package as an example):
$ cpio -itv  Payload
I've got:
$ cpio -itv < ./Payload                                              
drwxr-xr-x   3 root     80              0 Feb 10 10:29 .
drwxr-xr-x   3 root     80              0 Feb 10 10:29 Applications
drwxr-xr-x   2 root     80              0 Feb 10 10:30 Applications/Test.app
-rw-r--r--   1 root     80              0 Feb 10 10:30 Applications/Test.app/testFiles
Folder Applications located in the archive root folder with the empty folder named dot. In the first case archive root folder contains a single folder named dot in the second case archive root folder contains 2 folders: folder named dot with no content inside and a folder named Applications. I need folder Applications to be inside folder named dot like in the first case. I've tried different combinations of cpio options with no success. Edit: The look of the first archive in the 7zip: Look of the first archive in 7zip The look of the second (my) archive in the 7zip: Look of my archive in 7zip Edit 2: find . command output: find . output
Zur13 (101 rep)
Feb 10, 2022, 04:46 PM • Last activity: Feb 10, 2022, 09:29 PM
3 votes
1 answers
13453 views
Getting "cpio: Bad magic" when trying to rpm install into a mounted Logical Volume
I am trying to follow the [Xen guide](http://book.xen.prgmr.com/mediawiki/index.php/Chapter_3:_Provisioning_domUs#Using_the_Package_Management_System_with_an_Alternate_Root) to provision a domU using package installation of the Fedora 15 release (the dom0 is CentOS 5.6). I've run the rpm install com...
I am trying to follow the [Xen guide](http://book.xen.prgmr.com/mediawiki/index.php/Chapter_3:_Provisioning_domUs#Using_the_Package_Management_System_with_an_Alternate_Root) to provision a domU using package installation of the Fedora 15 release (the dom0 is CentOS 5.6). I've run the rpm install command with an alternate root to a mounted root LV, but I keep running into this issue: # rpm -ivh --nodeps --root /mnt/fedRoot fedora-release-15-1.noarch.rpm warning: fedora-release-15-1.noarch.rpm: Header V3 RSA/SHA256 signature: NOKEY, key ID 069c8460 Preparing... ########################################### [100%] 1:fedora-release ########################################### [100%] error: unpacking of archive failed: cpio: Bad magic I'm not sure where to begin with troubleshooting this. As I understand it, rpm reads the "root" filesystem (which I've designated to the mounted drive) and bases its verification and install directory structure based on the "root" system. What is the cpio: Bad magic bit? Any recommendations for making this rpm install work? let me know if more information is needed...
Hari Seldon (797 rep)
Jun 13, 2011, 10:09 PM • Last activity: Jan 11, 2022, 10:22 PM
0 votes
1 answers
859 views
What are the advantages of cpio over tar, zip, etc?
With cpio, you need to direct a list of files into cpio's standard input, whereas with tools such as tar, zip, etc, it's possible to recursively archive a directory (or multiple directories). I understand it's considered good manners and/or best practice to archive a directory so that if you give yo...
With cpio, you need to direct a list of files into cpio's standard input, whereas with tools such as tar, zip, etc, it's possible to recursively archive a directory (or multiple directories). I understand it's considered good manners and/or best practice to archive a directory so that if you give your *.tar or *.zip archive to somebody else, when they extract it, they don't get a splattering of files all over the place in whatever directory they're extracting it to. If other archive tools can archive both files and directories and cpio can only archive files, what are the advantages and/or use cases of cpio?
Kourosh Taheri-Golvarzi (17 rep)
Jun 27, 2021, 05:20 PM • Last activity: Jun 27, 2021, 10:15 PM
51 votes
6 answers
20425 views
Why is it that my initrd only has one directory, namely, 'kernel'?
I'm using debian live-build to work on a bootable system. By the end of the process i get the typical files used to boot a live system: a squashfs file, some GRUB modules and config files, and an initrd.img file. I can boot just fine using those files, passing the initrd to the kernel via initrd=/pa...
I'm using debian live-build to work on a bootable system. By the end of the process i get the typical files used to boot a live system: a squashfs file, some GRUB modules and config files, and an initrd.img file. I can boot just fine using those files, passing the initrd to the kernel via initrd=/path/to/my/initrd.img on the bootloader command line. But when I try to examine the contents of my initrd image, like so: $file initrd.img initrd.img: ASCII cpio archive (SVR4 with no CRC) $mkdir initTree && cd initTree $cpio -idv < ../initrd.img the file tree i get looks like this: $tree --charset=ASCII . `-- kernel `-- x86 `-- microcode `-- GenuineIntel.bin Where is the actual filesystem tree, with the typical /bin , /etc, /sbin ... containing the actual files used during boot?
user986730 (823 rep)
Oct 21, 2014, 12:28 PM • Last activity: May 17, 2021, 08:23 PM
4 votes
3 answers
2526 views
Transform tar into cpio without rooting?
I have a tarball containing many files with root:root owner and/or special device inodes. `cpio` only accepts paths existing in the file system when it is creating a cpio archive. And I don't want to have to `sudo` in order to transform tar into cpio, while I want to preserve all the permissions, ow...
I have a tarball containing many files with root:root owner and/or special device inodes. cpio only accepts paths existing in the file system when it is creating a cpio archive. And I don't want to have to sudo in order to transform tar into cpio, while I want to preserve all the permissions, owners, and special inodes. Is there some clean way of handling this? EDIT1: I believe that fakeroot can be seen as somewhat clean way. However it does not scale as expected - nearly 1,000x speed difference: [user@computer root]$ ls -l ../fanbox.tar -rw-rw-r-- 1 user user 56555520 May 22 03:33 ../fanbox.tar [user@computer root]$ time tar -x --delay-directory-restore -f ../fanbox.tar tar: dev/null: Cannot mknod: Operation not permitted tar: dev/random: Cannot mknod: Operation not permitted tar: dev/urandom: Cannot mknod: Operation not permitted tar: Exiting with failure status due to previous errors real 0m0.255s user 0m0.062s sys 0m0.193s [user@computer root]$ rm -rf * [user@computer root]$ time fakeroot tar -x --delay-directory-restore -f ../fanbox.tar real 3m49.381s user 0m0.812s sys 0m2.760s [user@computer root]$ Based on the output of time command I guess it is because of the communication between fakeroot and faked. For reference, there is no much difference between a 2M tarball and 50M tarball when I changed fakeroot into sudo bash in my script. And also I believe that the problem is the number of files in the tarball, not the size: I used the same script on a ~10M tarball with two 5M binaries, and the script is not so slow.
Thiner (41 rep)
May 18, 2018, 06:02 AM • Last activity: Jan 9, 2021, 06:32 AM
0 votes
1 answers
1072 views
How to extract a compressed tar using cpio to a particular directory location
I created the compressed tar file using the below command. find /app/jboss -not -name "*.err" -not -name "*.log" | cpio -o | gzip >/app/patchbkp/test/REDHAT_jboss-eap-7.2_18-Aug-2020.tar.gz I got the compressed file here [user1@myhost test]$ ls -ltr /app/patchbkp/test/REDHAT_jboss-eap-7.2_18-Aug-202...
I created the compressed tar file using the below command. find /app/jboss -not -name "*.err" -not -name "*.log" | cpio -o | gzip >/app/patchbkp/test/REDHAT_jboss-eap-7.2_18-Aug-2020.tar.gz I got the compressed file here [user1@myhost test]$ ls -ltr /app/patchbkp/test/REDHAT_jboss-eap-7.2_18-Aug-2020.tar.gz -rwxrwxr-x 1 user1 mygrp 363997224 Aug 18 16:08 /app/patchbkp/test/REDHAT_jboss-eap-7.2_18-Aug-2020.tar.gz I want to extract the /app/jboss directory under /app/patchbkp/test so i get /app/patchbkp/test/app/jboss/.......; thus i try the below command. cd /app/patchbkp/test/ zcat /app/patchbkp/test/REDHAT_jboss-eap-7.2_18-Aug-2020.tar.gz | cpio -i But this does not generate any files under /app/patchbkp/test I get permission denied error when i try gunzip /app/patchbkp/test/REDHAT_jboss-eap-7.2_18-Aug-2020.tar.gz Can you please guide me as to how can I extract the tar compressed /app/jboss under /app/patchbkp/test directory?
Ashar (527 rep)
Aug 18, 2020, 11:12 AM • Last activity: Aug 18, 2020, 01:01 PM
1 votes
2 answers
1327 views
Is there a practical way to make binary-reproducible CPIO (initramfs) archives?
I would like my initramfs to have the same hash no matter when or where I build it if the contents of the files are the same (and are owned by root and have same permissions). I don't see any options in GNU cpio to strip or set timestamps of files in the archive. Is there a relatively standard way t...
I would like my initramfs to have the same hash no matter when or where I build it if the contents of the files are the same (and are owned by root and have same permissions). I don't see any options in GNU cpio to strip or set timestamps of files in the archive. Is there a relatively standard way to massage the input to cpio and other archive programs so you can get reproducible products? Going along with this, is there a conventional "We aren't giving this a date" timestamp? Something most software won't wig out about? For example 0 epoch-seconds? For example, if I did a find pass on an input directory for an initramfs and manually set all the timestamps to 0, could I build that archive, extract it on another system, repeat the process, and build it again and get bit-identical files?
davolfman (847 rep)
Nov 25, 2019, 08:21 PM • Last activity: May 25, 2020, 07:04 PM
Showing page 1 of 20 total questions