Why is it that my initrd only has one directory, namely, 'kernel'?initrd.img contains many archivesConvert...
How did Kirk identify Gorgan in "And the Children Shall Lead"?
Do Maps have an Reliable Relationship between keySet() order and values() order?
If I readied a spell with the trigger "When I take damage", do I have to make a constitution saving throw to avoid losing Concentration?
Can my company stop me from working overtime?
Hyperlink on red background
Why is "Vayechulu" said 3 times on Leil Shabbat?
Did we get closer to another plane than we were supposed to, or was the pilot just protecting our delicate sensibilities?
BOOM! Perfect Clear for Mr. T
Why is the relative clause in the following sentence not directly after the noun and why is the verb not in the end of the sentence?
Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?
Why was the battle set up *outside* Winterfell?
Pressure inside an infinite ocean?
Randomness of Python's random
How long would it take for people to notice a mass disappearance?
what to look for in luxury cars like Acura/Lexus
Which module had more 'comfort' in terms of living space, the Lunar Module or the Command module?
How might a mountain bowl form?
Can you complete the sequence?
How does this change to the opportunity attack rule impact combat?
Fitch Proof Question
If your medical expenses exceed your income does the IRS pay you?
Using a microphone from the 1930s
Mic, cable, pre-amp setup for acoustic guitar to perform with big band through mic and guitar amp?
Missing Piece of Pie - Can you find it?
Why is it that my initrd only has one directory, namely, 'kernel'?
initrd.img contains many archivesConvert Debian Live USB persistent filesystem to a standalone installationLive Distros: UBCD boot Deft, Caine, and Tails from Custom Menuinitrd.img contains many archivesHow to create ASCII cpio archive (SVR4 with no CRC)?Why kernel cannot do the initrd/initramfs job itself?Change device tree on boothow does the copy cp command differentiate between the ESP and root partition?Kernel can't find initrd?Boot custom CentOS 7 Live ISO from hard disk to RAMHow to merge squashfs file during booting of “live” linux distros from GRUB manually?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
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?
linux debian initrd cpio
add a comment |
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?
linux debian initrd cpio
1
The 'lsinitramfs' command was designed for this.
– earlgrey
Aug 5 '18 at 15:50
add a comment |
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?
linux debian initrd cpio
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?
linux debian initrd cpio
linux debian initrd cpio
asked Oct 21 '14 at 12:28
user986730user986730
36838
36838
1
The 'lsinitramfs' command was designed for this.
– earlgrey
Aug 5 '18 at 15:50
add a comment |
1
The 'lsinitramfs' command was designed for this.
– earlgrey
Aug 5 '18 at 15:50
1
1
The 'lsinitramfs' command was designed for this.
– earlgrey
Aug 5 '18 at 15:50
The 'lsinitramfs' command was designed for this.
– earlgrey
Aug 5 '18 at 15:50
add a comment |
6 Answers
6
active
oldest
votes
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
--------------------------------------------------------------------------------
0 0x0 ASCII cpio archive (SVR4 with no CRC), file name: "kernel", file name length: "0x00000007", file size: "0x00000000"
120 0x78 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86", file name length: "0x0000000B", file size: "0x00000000"
244 0xF4 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode", file name length: "0x00000015", file size: "0x00000000"
376 0x178 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/GenuineIntel.bin", file name length: "0x00000026", file size: "0x00005000"
21004 0x520C ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
21136 0x5290 gzip compressed data, from Unix, last modified: Sat Feb 28 09:46:24 2015
Use the last number (21136) which is not on a 512 byte boundary for me:
legolas [mc]# dd if=initrd.img bs=21136 skip=1 | gunzip | cpio -tdv | head
drwxr-xr-x 1 root root 0 Feb 28 09:46 .
drwxr-xr-x 1 root root 0 Feb 28 09:46 bin
-rwxr-xr-x 1 root root 554424 Dec 17 2011 bin/busybox
lrwxrwxrwx 1 root root 7 Feb 28 09:46 bin/sh -> busybox
-rwxr-xr-x 1 root root 111288 Sep 23 2011 bin/loadkeys
-rwxr-xr-x 1 root root 2800 Aug 19 2013 bin/cat
-rwxr-xr-x 1 root root 856 Aug 19 2013 bin/chroot
-rwxr-xr-x 1 root root 5224 Aug 19 2013 bin/cpio
-rwxr-xr-x 1 root root 3936 Aug 19 2013 bin/dd
-rwxr-xr-x 1 root root 984 Aug 19 2013 bin/dmesg
Indeed, your answer beats mine. I haven't ever thought that alignment would be a problem. I wonder, though, if cpio would give some more interesting output if the first image contained within the multi-image file was not 512B-lined.
– user986730
Mar 25 '15 at 16:52
How to revert it back (repack to original state) after modifying, with the same folder hierarchy ?
– EdiD
May 25 '16 at 9:39
2
Justcdinto the directory where you extracted your cpio archive, runfind | cpio -H newc -o > /tmp/my_archive.cpio, then gzip it withgzip /tmp/my_archive.cpioand finally, concatenate it with the with the microcode image, if you had one:cat my_microcode_image.cpio /tmp/my_archive.cpio.gz > mynewinitrd.img. If you didn't have a microcode image, then you can just use you gzipped file as is in your bootloader
– user986730
Jun 2 '16 at 12:50
add a comment |
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).
Upon extracting the original initrd.img, straight out of the live-build output, I got this output:
$cpio -idv ../initrd.img
kernel
kernel/x86
kernel/x86/microcode
kernel/x86/microcode/GenuineIntel.bin
896 blocks
Which means that the cpio extraction ended after parsing 896 blocks of 512 Bytes each. But the original initrd.img was way bigger than 896*512 = 458752B = 448 KB :
$ls -liah initrd.img
3933924 -r--r--r-- 1 root root 21M Oct 21 10:05 initrd.img
So the actual initrd image I was looking for was appended right after the first cpio archive (the one containing the microcode updates) and could be accessed using dd:
$dd if=initrd.img of=myActualInitrdImage.img.gz bs=512 skip=896
add a comment |
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 input into a subshell which executes the two commands cpio -id and zcat | cpio -id sequentially. The first command (cpio -id) terminates once it has read all the data belonging to the first cpio archive. The remaining content is then passed to zcat | cpio -id, which decompresses and unpacks the second archive.
1
This looks like the cleanest solution by far
– velis
Jan 30 '17 at 8:38
1
It works beautifully
– TurboHz
Jun 7 '18 at 17:28
Mysteriously, @woolpool's fine answer is the sole answer that user has ever posted. That's style. If you were going to post only one answer during your entire StackExchange career, then you could hardly do better than to post one such as this. OP might consider changing the accepted answer to this one.
– thb
Dec 1 '18 at 13:07
add a comment |
You can use unmkinitramfs from initramfs-tools >= 0.126, which is included since Debian 9 (stretch) and Ubuntu 18.04 (bionic).
add a comment |
If you need to perform this task often, you may want to create a small bash function like the following (and maybe add it to your .bashrc):
initramfs-extract() {
local target=$1
local offset=$(binwalk -y gzip $1 | awk '$3 ~ /gzip/ { print $1; exit }')
shift
dd if=$target bs=$offset skip=1 | zcat | cpio -id --no-absolute-filenames $@
}
The code is based on Marc's answer, but it's significantly faster since binwalk will only look for gzip files.
You can invoke it, like this:
$ initramfs-extract /boot/initrd.img -v
You will need binwalk installed to make it work.
add a comment |
Based on the idea given in @woolpool's answer I wrote a recursive function that will work for any cpio archive regardless of the arrangement of the concatenated data and doesn't require any special tools like binwalk. For example my mkinitramfs was producing a cpio;cpio;gzip file. It works by extracting each part of the concatenated initrd file, saving the rest into a tempfile and then using the "file" program to decide what to do with the next part.
uncpio(){
if [[ $(wc -c $1 | cut -d ' ' -f1) -eq 0 ]]; then
return
fi
type=$(cat $1 | file -)
local tmpfile=$(date +%s.%N)
echo -e "n$type"
if [[ $type =~ .*cpio.* ]]; then
cat $1 | (cpio -id; cat >$tmpfile)
elif [[ $type =~ .*gzip.* ]]; then
zcat $1 | (cpio -id; cat >$tmpfile)
else
return
fi
uncpio $tmpfile
rm $tmpfile
}
To use type: uncpio initrdfilename
New contributor
Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f163346%2fwhy-is-it-that-my-initrd-only-has-one-directory-namely-kernel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
--------------------------------------------------------------------------------
0 0x0 ASCII cpio archive (SVR4 with no CRC), file name: "kernel", file name length: "0x00000007", file size: "0x00000000"
120 0x78 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86", file name length: "0x0000000B", file size: "0x00000000"
244 0xF4 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode", file name length: "0x00000015", file size: "0x00000000"
376 0x178 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/GenuineIntel.bin", file name length: "0x00000026", file size: "0x00005000"
21004 0x520C ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
21136 0x5290 gzip compressed data, from Unix, last modified: Sat Feb 28 09:46:24 2015
Use the last number (21136) which is not on a 512 byte boundary for me:
legolas [mc]# dd if=initrd.img bs=21136 skip=1 | gunzip | cpio -tdv | head
drwxr-xr-x 1 root root 0 Feb 28 09:46 .
drwxr-xr-x 1 root root 0 Feb 28 09:46 bin
-rwxr-xr-x 1 root root 554424 Dec 17 2011 bin/busybox
lrwxrwxrwx 1 root root 7 Feb 28 09:46 bin/sh -> busybox
-rwxr-xr-x 1 root root 111288 Sep 23 2011 bin/loadkeys
-rwxr-xr-x 1 root root 2800 Aug 19 2013 bin/cat
-rwxr-xr-x 1 root root 856 Aug 19 2013 bin/chroot
-rwxr-xr-x 1 root root 5224 Aug 19 2013 bin/cpio
-rwxr-xr-x 1 root root 3936 Aug 19 2013 bin/dd
-rwxr-xr-x 1 root root 984 Aug 19 2013 bin/dmesg
Indeed, your answer beats mine. I haven't ever thought that alignment would be a problem. I wonder, though, if cpio would give some more interesting output if the first image contained within the multi-image file was not 512B-lined.
– user986730
Mar 25 '15 at 16:52
How to revert it back (repack to original state) after modifying, with the same folder hierarchy ?
– EdiD
May 25 '16 at 9:39
2
Justcdinto the directory where you extracted your cpio archive, runfind | cpio -H newc -o > /tmp/my_archive.cpio, then gzip it withgzip /tmp/my_archive.cpioand finally, concatenate it with the with the microcode image, if you had one:cat my_microcode_image.cpio /tmp/my_archive.cpio.gz > mynewinitrd.img. If you didn't have a microcode image, then you can just use you gzipped file as is in your bootloader
– user986730
Jun 2 '16 at 12:50
add a comment |
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
--------------------------------------------------------------------------------
0 0x0 ASCII cpio archive (SVR4 with no CRC), file name: "kernel", file name length: "0x00000007", file size: "0x00000000"
120 0x78 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86", file name length: "0x0000000B", file size: "0x00000000"
244 0xF4 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode", file name length: "0x00000015", file size: "0x00000000"
376 0x178 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/GenuineIntel.bin", file name length: "0x00000026", file size: "0x00005000"
21004 0x520C ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
21136 0x5290 gzip compressed data, from Unix, last modified: Sat Feb 28 09:46:24 2015
Use the last number (21136) which is not on a 512 byte boundary for me:
legolas [mc]# dd if=initrd.img bs=21136 skip=1 | gunzip | cpio -tdv | head
drwxr-xr-x 1 root root 0 Feb 28 09:46 .
drwxr-xr-x 1 root root 0 Feb 28 09:46 bin
-rwxr-xr-x 1 root root 554424 Dec 17 2011 bin/busybox
lrwxrwxrwx 1 root root 7 Feb 28 09:46 bin/sh -> busybox
-rwxr-xr-x 1 root root 111288 Sep 23 2011 bin/loadkeys
-rwxr-xr-x 1 root root 2800 Aug 19 2013 bin/cat
-rwxr-xr-x 1 root root 856 Aug 19 2013 bin/chroot
-rwxr-xr-x 1 root root 5224 Aug 19 2013 bin/cpio
-rwxr-xr-x 1 root root 3936 Aug 19 2013 bin/dd
-rwxr-xr-x 1 root root 984 Aug 19 2013 bin/dmesg
Indeed, your answer beats mine. I haven't ever thought that alignment would be a problem. I wonder, though, if cpio would give some more interesting output if the first image contained within the multi-image file was not 512B-lined.
– user986730
Mar 25 '15 at 16:52
How to revert it back (repack to original state) after modifying, with the same folder hierarchy ?
– EdiD
May 25 '16 at 9:39
2
Justcdinto the directory where you extracted your cpio archive, runfind | cpio -H newc -o > /tmp/my_archive.cpio, then gzip it withgzip /tmp/my_archive.cpioand finally, concatenate it with the with the microcode image, if you had one:cat my_microcode_image.cpio /tmp/my_archive.cpio.gz > mynewinitrd.img. If you didn't have a microcode image, then you can just use you gzipped file as is in your bootloader
– user986730
Jun 2 '16 at 12:50
add a comment |
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
--------------------------------------------------------------------------------
0 0x0 ASCII cpio archive (SVR4 with no CRC), file name: "kernel", file name length: "0x00000007", file size: "0x00000000"
120 0x78 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86", file name length: "0x0000000B", file size: "0x00000000"
244 0xF4 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode", file name length: "0x00000015", file size: "0x00000000"
376 0x178 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/GenuineIntel.bin", file name length: "0x00000026", file size: "0x00005000"
21004 0x520C ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
21136 0x5290 gzip compressed data, from Unix, last modified: Sat Feb 28 09:46:24 2015
Use the last number (21136) which is not on a 512 byte boundary for me:
legolas [mc]# dd if=initrd.img bs=21136 skip=1 | gunzip | cpio -tdv | head
drwxr-xr-x 1 root root 0 Feb 28 09:46 .
drwxr-xr-x 1 root root 0 Feb 28 09:46 bin
-rwxr-xr-x 1 root root 554424 Dec 17 2011 bin/busybox
lrwxrwxrwx 1 root root 7 Feb 28 09:46 bin/sh -> busybox
-rwxr-xr-x 1 root root 111288 Sep 23 2011 bin/loadkeys
-rwxr-xr-x 1 root root 2800 Aug 19 2013 bin/cat
-rwxr-xr-x 1 root root 856 Aug 19 2013 bin/chroot
-rwxr-xr-x 1 root root 5224 Aug 19 2013 bin/cpio
-rwxr-xr-x 1 root root 3936 Aug 19 2013 bin/dd
-rwxr-xr-x 1 root root 984 Aug 19 2013 bin/dmesg
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
--------------------------------------------------------------------------------
0 0x0 ASCII cpio archive (SVR4 with no CRC), file name: "kernel", file name length: "0x00000007", file size: "0x00000000"
120 0x78 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86", file name length: "0x0000000B", file size: "0x00000000"
244 0xF4 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode", file name length: "0x00000015", file size: "0x00000000"
376 0x178 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/GenuineIntel.bin", file name length: "0x00000026", file size: "0x00005000"
21004 0x520C ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
21136 0x5290 gzip compressed data, from Unix, last modified: Sat Feb 28 09:46:24 2015
Use the last number (21136) which is not on a 512 byte boundary for me:
legolas [mc]# dd if=initrd.img bs=21136 skip=1 | gunzip | cpio -tdv | head
drwxr-xr-x 1 root root 0 Feb 28 09:46 .
drwxr-xr-x 1 root root 0 Feb 28 09:46 bin
-rwxr-xr-x 1 root root 554424 Dec 17 2011 bin/busybox
lrwxrwxrwx 1 root root 7 Feb 28 09:46 bin/sh -> busybox
-rwxr-xr-x 1 root root 111288 Sep 23 2011 bin/loadkeys
-rwxr-xr-x 1 root root 2800 Aug 19 2013 bin/cat
-rwxr-xr-x 1 root root 856 Aug 19 2013 bin/chroot
-rwxr-xr-x 1 root root 5224 Aug 19 2013 bin/cpio
-rwxr-xr-x 1 root root 3936 Aug 19 2013 bin/dd
-rwxr-xr-x 1 root root 984 Aug 19 2013 bin/dmesg
answered Mar 23 '15 at 18:41
Marc MerlinMarc Merlin
45642
45642
Indeed, your answer beats mine. I haven't ever thought that alignment would be a problem. I wonder, though, if cpio would give some more interesting output if the first image contained within the multi-image file was not 512B-lined.
– user986730
Mar 25 '15 at 16:52
How to revert it back (repack to original state) after modifying, with the same folder hierarchy ?
– EdiD
May 25 '16 at 9:39
2
Justcdinto the directory where you extracted your cpio archive, runfind | cpio -H newc -o > /tmp/my_archive.cpio, then gzip it withgzip /tmp/my_archive.cpioand finally, concatenate it with the with the microcode image, if you had one:cat my_microcode_image.cpio /tmp/my_archive.cpio.gz > mynewinitrd.img. If you didn't have a microcode image, then you can just use you gzipped file as is in your bootloader
– user986730
Jun 2 '16 at 12:50
add a comment |
Indeed, your answer beats mine. I haven't ever thought that alignment would be a problem. I wonder, though, if cpio would give some more interesting output if the first image contained within the multi-image file was not 512B-lined.
– user986730
Mar 25 '15 at 16:52
How to revert it back (repack to original state) after modifying, with the same folder hierarchy ?
– EdiD
May 25 '16 at 9:39
2
Justcdinto the directory where you extracted your cpio archive, runfind | cpio -H newc -o > /tmp/my_archive.cpio, then gzip it withgzip /tmp/my_archive.cpioand finally, concatenate it with the with the microcode image, if you had one:cat my_microcode_image.cpio /tmp/my_archive.cpio.gz > mynewinitrd.img. If you didn't have a microcode image, then you can just use you gzipped file as is in your bootloader
– user986730
Jun 2 '16 at 12:50
Indeed, your answer beats mine. I haven't ever thought that alignment would be a problem. I wonder, though, if cpio would give some more interesting output if the first image contained within the multi-image file was not 512B-lined.
– user986730
Mar 25 '15 at 16:52
Indeed, your answer beats mine. I haven't ever thought that alignment would be a problem. I wonder, though, if cpio would give some more interesting output if the first image contained within the multi-image file was not 512B-lined.
– user986730
Mar 25 '15 at 16:52
How to revert it back (repack to original state) after modifying, with the same folder hierarchy ?
– EdiD
May 25 '16 at 9:39
How to revert it back (repack to original state) after modifying, with the same folder hierarchy ?
– EdiD
May 25 '16 at 9:39
2
2
Just
cd into the directory where you extracted your cpio archive, run find | cpio -H newc -o > /tmp/my_archive.cpio, then gzip it with gzip /tmp/my_archive.cpio and finally, concatenate it with the with the microcode image, if you had one: cat my_microcode_image.cpio /tmp/my_archive.cpio.gz > mynewinitrd.img. If you didn't have a microcode image, then you can just use you gzipped file as is in your bootloader– user986730
Jun 2 '16 at 12:50
Just
cd into the directory where you extracted your cpio archive, run find | cpio -H newc -o > /tmp/my_archive.cpio, then gzip it with gzip /tmp/my_archive.cpio and finally, concatenate it with the with the microcode image, if you had one: cat my_microcode_image.cpio /tmp/my_archive.cpio.gz > mynewinitrd.img. If you didn't have a microcode image, then you can just use you gzipped file as is in your bootloader– user986730
Jun 2 '16 at 12:50
add a comment |
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).
Upon extracting the original initrd.img, straight out of the live-build output, I got this output:
$cpio -idv ../initrd.img
kernel
kernel/x86
kernel/x86/microcode
kernel/x86/microcode/GenuineIntel.bin
896 blocks
Which means that the cpio extraction ended after parsing 896 blocks of 512 Bytes each. But the original initrd.img was way bigger than 896*512 = 458752B = 448 KB :
$ls -liah initrd.img
3933924 -r--r--r-- 1 root root 21M Oct 21 10:05 initrd.img
So the actual initrd image I was looking for was appended right after the first cpio archive (the one containing the microcode updates) and could be accessed using dd:
$dd if=initrd.img of=myActualInitrdImage.img.gz bs=512 skip=896
add a comment |
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).
Upon extracting the original initrd.img, straight out of the live-build output, I got this output:
$cpio -idv ../initrd.img
kernel
kernel/x86
kernel/x86/microcode
kernel/x86/microcode/GenuineIntel.bin
896 blocks
Which means that the cpio extraction ended after parsing 896 blocks of 512 Bytes each. But the original initrd.img was way bigger than 896*512 = 458752B = 448 KB :
$ls -liah initrd.img
3933924 -r--r--r-- 1 root root 21M Oct 21 10:05 initrd.img
So the actual initrd image I was looking for was appended right after the first cpio archive (the one containing the microcode updates) and could be accessed using dd:
$dd if=initrd.img of=myActualInitrdImage.img.gz bs=512 skip=896
add a comment |
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).
Upon extracting the original initrd.img, straight out of the live-build output, I got this output:
$cpio -idv ../initrd.img
kernel
kernel/x86
kernel/x86/microcode
kernel/x86/microcode/GenuineIntel.bin
896 blocks
Which means that the cpio extraction ended after parsing 896 blocks of 512 Bytes each. But the original initrd.img was way bigger than 896*512 = 458752B = 448 KB :
$ls -liah initrd.img
3933924 -r--r--r-- 1 root root 21M Oct 21 10:05 initrd.img
So the actual initrd image I was looking for was appended right after the first cpio archive (the one containing the microcode updates) and could be accessed using dd:
$dd if=initrd.img of=myActualInitrdImage.img.gz bs=512 skip=896
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).
Upon extracting the original initrd.img, straight out of the live-build output, I got this output:
$cpio -idv ../initrd.img
kernel
kernel/x86
kernel/x86/microcode
kernel/x86/microcode/GenuineIntel.bin
896 blocks
Which means that the cpio extraction ended after parsing 896 blocks of 512 Bytes each. But the original initrd.img was way bigger than 896*512 = 458752B = 448 KB :
$ls -liah initrd.img
3933924 -r--r--r-- 1 root root 21M Oct 21 10:05 initrd.img
So the actual initrd image I was looking for was appended right after the first cpio archive (the one containing the microcode updates) and could be accessed using dd:
$dd if=initrd.img of=myActualInitrdImage.img.gz bs=512 skip=896
answered Oct 21 '14 at 13:01
user986730user986730
36838
36838
add a comment |
add a comment |
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 input into a subshell which executes the two commands cpio -id and zcat | cpio -id sequentially. The first command (cpio -id) terminates once it has read all the data belonging to the first cpio archive. The remaining content is then passed to zcat | cpio -id, which decompresses and unpacks the second archive.
1
This looks like the cleanest solution by far
– velis
Jan 30 '17 at 8:38
1
It works beautifully
– TurboHz
Jun 7 '18 at 17:28
Mysteriously, @woolpool's fine answer is the sole answer that user has ever posted. That's style. If you were going to post only one answer during your entire StackExchange career, then you could hardly do better than to post one such as this. OP might consider changing the accepted answer to this one.
– thb
Dec 1 '18 at 13:07
add a comment |
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 input into a subshell which executes the two commands cpio -id and zcat | cpio -id sequentially. The first command (cpio -id) terminates once it has read all the data belonging to the first cpio archive. The remaining content is then passed to zcat | cpio -id, which decompresses and unpacks the second archive.
1
This looks like the cleanest solution by far
– velis
Jan 30 '17 at 8:38
1
It works beautifully
– TurboHz
Jun 7 '18 at 17:28
Mysteriously, @woolpool's fine answer is the sole answer that user has ever posted. That's style. If you were going to post only one answer during your entire StackExchange career, then you could hardly do better than to post one such as this. OP might consider changing the accepted answer to this one.
– thb
Dec 1 '18 at 13:07
add a comment |
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 input into a subshell which executes the two commands cpio -id and zcat | cpio -id sequentially. The first command (cpio -id) terminates once it has read all the data belonging to the first cpio archive. The remaining content is then passed to zcat | cpio -id, which decompresses and unpacks the second archive.
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 input into a subshell which executes the two commands cpio -id and zcat | cpio -id sequentially. The first command (cpio -id) terminates once it has read all the data belonging to the first cpio archive. The remaining content is then passed to zcat | cpio -id, which decompresses and unpacks the second archive.
answered Dec 12 '16 at 22:47
woolpoolwoolpool
14113
14113
1
This looks like the cleanest solution by far
– velis
Jan 30 '17 at 8:38
1
It works beautifully
– TurboHz
Jun 7 '18 at 17:28
Mysteriously, @woolpool's fine answer is the sole answer that user has ever posted. That's style. If you were going to post only one answer during your entire StackExchange career, then you could hardly do better than to post one such as this. OP might consider changing the accepted answer to this one.
– thb
Dec 1 '18 at 13:07
add a comment |
1
This looks like the cleanest solution by far
– velis
Jan 30 '17 at 8:38
1
It works beautifully
– TurboHz
Jun 7 '18 at 17:28
Mysteriously, @woolpool's fine answer is the sole answer that user has ever posted. That's style. If you were going to post only one answer during your entire StackExchange career, then you could hardly do better than to post one such as this. OP might consider changing the accepted answer to this one.
– thb
Dec 1 '18 at 13:07
1
1
This looks like the cleanest solution by far
– velis
Jan 30 '17 at 8:38
This looks like the cleanest solution by far
– velis
Jan 30 '17 at 8:38
1
1
It works beautifully
– TurboHz
Jun 7 '18 at 17:28
It works beautifully
– TurboHz
Jun 7 '18 at 17:28
Mysteriously, @woolpool's fine answer is the sole answer that user has ever posted. That's style. If you were going to post only one answer during your entire StackExchange career, then you could hardly do better than to post one such as this. OP might consider changing the accepted answer to this one.
– thb
Dec 1 '18 at 13:07
Mysteriously, @woolpool's fine answer is the sole answer that user has ever posted. That's style. If you were going to post only one answer during your entire StackExchange career, then you could hardly do better than to post one such as this. OP might consider changing the accepted answer to this one.
– thb
Dec 1 '18 at 13:07
add a comment |
You can use unmkinitramfs from initramfs-tools >= 0.126, which is included since Debian 9 (stretch) and Ubuntu 18.04 (bionic).
add a comment |
You can use unmkinitramfs from initramfs-tools >= 0.126, which is included since Debian 9 (stretch) and Ubuntu 18.04 (bionic).
add a comment |
You can use unmkinitramfs from initramfs-tools >= 0.126, which is included since Debian 9 (stretch) and Ubuntu 18.04 (bionic).
You can use unmkinitramfs from initramfs-tools >= 0.126, which is included since Debian 9 (stretch) and Ubuntu 18.04 (bionic).
answered Jan 19 at 20:56
Benjamin DrungBenjamin Drung
112
112
add a comment |
add a comment |
If you need to perform this task often, you may want to create a small bash function like the following (and maybe add it to your .bashrc):
initramfs-extract() {
local target=$1
local offset=$(binwalk -y gzip $1 | awk '$3 ~ /gzip/ { print $1; exit }')
shift
dd if=$target bs=$offset skip=1 | zcat | cpio -id --no-absolute-filenames $@
}
The code is based on Marc's answer, but it's significantly faster since binwalk will only look for gzip files.
You can invoke it, like this:
$ initramfs-extract /boot/initrd.img -v
You will need binwalk installed to make it work.
add a comment |
If you need to perform this task often, you may want to create a small bash function like the following (and maybe add it to your .bashrc):
initramfs-extract() {
local target=$1
local offset=$(binwalk -y gzip $1 | awk '$3 ~ /gzip/ { print $1; exit }')
shift
dd if=$target bs=$offset skip=1 | zcat | cpio -id --no-absolute-filenames $@
}
The code is based on Marc's answer, but it's significantly faster since binwalk will only look for gzip files.
You can invoke it, like this:
$ initramfs-extract /boot/initrd.img -v
You will need binwalk installed to make it work.
add a comment |
If you need to perform this task often, you may want to create a small bash function like the following (and maybe add it to your .bashrc):
initramfs-extract() {
local target=$1
local offset=$(binwalk -y gzip $1 | awk '$3 ~ /gzip/ { print $1; exit }')
shift
dd if=$target bs=$offset skip=1 | zcat | cpio -id --no-absolute-filenames $@
}
The code is based on Marc's answer, but it's significantly faster since binwalk will only look for gzip files.
You can invoke it, like this:
$ initramfs-extract /boot/initrd.img -v
You will need binwalk installed to make it work.
If you need to perform this task often, you may want to create a small bash function like the following (and maybe add it to your .bashrc):
initramfs-extract() {
local target=$1
local offset=$(binwalk -y gzip $1 | awk '$3 ~ /gzip/ { print $1; exit }')
shift
dd if=$target bs=$offset skip=1 | zcat | cpio -id --no-absolute-filenames $@
}
The code is based on Marc's answer, but it's significantly faster since binwalk will only look for gzip files.
You can invoke it, like this:
$ initramfs-extract /boot/initrd.img -v
You will need binwalk installed to make it work.
answered Dec 12 '16 at 22:26
tyriontyrion
1134
1134
add a comment |
add a comment |
Based on the idea given in @woolpool's answer I wrote a recursive function that will work for any cpio archive regardless of the arrangement of the concatenated data and doesn't require any special tools like binwalk. For example my mkinitramfs was producing a cpio;cpio;gzip file. It works by extracting each part of the concatenated initrd file, saving the rest into a tempfile and then using the "file" program to decide what to do with the next part.
uncpio(){
if [[ $(wc -c $1 | cut -d ' ' -f1) -eq 0 ]]; then
return
fi
type=$(cat $1 | file -)
local tmpfile=$(date +%s.%N)
echo -e "n$type"
if [[ $type =~ .*cpio.* ]]; then
cat $1 | (cpio -id; cat >$tmpfile)
elif [[ $type =~ .*gzip.* ]]; then
zcat $1 | (cpio -id; cat >$tmpfile)
else
return
fi
uncpio $tmpfile
rm $tmpfile
}
To use type: uncpio initrdfilename
New contributor
Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Based on the idea given in @woolpool's answer I wrote a recursive function that will work for any cpio archive regardless of the arrangement of the concatenated data and doesn't require any special tools like binwalk. For example my mkinitramfs was producing a cpio;cpio;gzip file. It works by extracting each part of the concatenated initrd file, saving the rest into a tempfile and then using the "file" program to decide what to do with the next part.
uncpio(){
if [[ $(wc -c $1 | cut -d ' ' -f1) -eq 0 ]]; then
return
fi
type=$(cat $1 | file -)
local tmpfile=$(date +%s.%N)
echo -e "n$type"
if [[ $type =~ .*cpio.* ]]; then
cat $1 | (cpio -id; cat >$tmpfile)
elif [[ $type =~ .*gzip.* ]]; then
zcat $1 | (cpio -id; cat >$tmpfile)
else
return
fi
uncpio $tmpfile
rm $tmpfile
}
To use type: uncpio initrdfilename
New contributor
Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Based on the idea given in @woolpool's answer I wrote a recursive function that will work for any cpio archive regardless of the arrangement of the concatenated data and doesn't require any special tools like binwalk. For example my mkinitramfs was producing a cpio;cpio;gzip file. It works by extracting each part of the concatenated initrd file, saving the rest into a tempfile and then using the "file" program to decide what to do with the next part.
uncpio(){
if [[ $(wc -c $1 | cut -d ' ' -f1) -eq 0 ]]; then
return
fi
type=$(cat $1 | file -)
local tmpfile=$(date +%s.%N)
echo -e "n$type"
if [[ $type =~ .*cpio.* ]]; then
cat $1 | (cpio -id; cat >$tmpfile)
elif [[ $type =~ .*gzip.* ]]; then
zcat $1 | (cpio -id; cat >$tmpfile)
else
return
fi
uncpio $tmpfile
rm $tmpfile
}
To use type: uncpio initrdfilename
New contributor
Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Based on the idea given in @woolpool's answer I wrote a recursive function that will work for any cpio archive regardless of the arrangement of the concatenated data and doesn't require any special tools like binwalk. For example my mkinitramfs was producing a cpio;cpio;gzip file. It works by extracting each part of the concatenated initrd file, saving the rest into a tempfile and then using the "file" program to decide what to do with the next part.
uncpio(){
if [[ $(wc -c $1 | cut -d ' ' -f1) -eq 0 ]]; then
return
fi
type=$(cat $1 | file -)
local tmpfile=$(date +%s.%N)
echo -e "n$type"
if [[ $type =~ .*cpio.* ]]; then
cat $1 | (cpio -id; cat >$tmpfile)
elif [[ $type =~ .*gzip.* ]]; then
zcat $1 | (cpio -id; cat >$tmpfile)
else
return
fi
uncpio $tmpfile
rm $tmpfile
}
To use type: uncpio initrdfilename
New contributor
Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 28 mins ago
BenjaminBenjamin
11
11
New contributor
Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f163346%2fwhy-is-it-that-my-initrd-only-has-one-directory-namely-kernel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The 'lsinitramfs' command was designed for this.
– earlgrey
Aug 5 '18 at 15:50