Howto unpack, edit and repack initrd.gz

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
Jim1911
Posts: 2460
Joined: Mon 19 May 2008, 20:39
Location: Texas, USA

Howto unpack, edit and repack initrd.gz

#1 Post by Jim1911 »

This post will show how to unpack and repack initrd.gz in order to edit the init file. This technique has worked well for me with initrd.gz files in pup431, dpup, upup, Lighthouse, and Stardust. Thanks to Mikeb for sharing what he called Pizzasgood's technique, otherwise I would not have found it.

Unpack the initrd.gz file
1. Make a tempinit directory and place the initrd.gz file that you want to edit in this new directory.
2. Using a console execute this:

Code: Select all

cd to directory containing initrd.gz 
mkdir initrd-tree 
cd initrd-tree/ 
zcat ../initrd.gz | cpio -i -d 

3. Using a text editor open the /initrd-tree/init file and make your changes.

4. Pack the new file using a console and this:

Code: Select all

cd again to initrd-tree 
rm ../initrd.gz 
find . | cpio -o -H newc | gzip -9 > ../initrd.gz 
The new initrd.gz is now ready for use, just copy it to the proper location. However before the copy, first rename the old initrd.gz.

Note: See Iguleder's suggestions in next post.
Last edited by Jim1911 on Sun 18 Apr 2010, 20:18, edited 3 times in total.

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#2 Post by Iguleder »

2 notes you should add:

- If you copy the directory with the extracted initrd, do it with "cp -pa" to preserve the permissions, as BusyBox needs SUID and 4755, and some files in /etc need specific permissions.
- it's possible to compress with other compression levels instead of 9, good for older hardware, might save 0.0000000000(...)1 seconds of wasted boot time. If you really insist on small size you can use AdvanceCOMP or some other gzip recompressor to recompress the gzipped CPIO archive, could save 100-200 KBs for an average initramfs.

Nice tutorial, keep up the good work :wink:

Jim1911
Posts: 2460
Joined: Mon 19 May 2008, 20:39
Location: Texas, USA

#3 Post by Jim1911 »

Thanks, the credit goes to Mikeb for sharing what he called Pizzasgood's technique that I just edited. The code is above my skill level.

emil
Posts: 633
Joined: Tue 10 Nov 2009, 08:36
Location: Austria
Contact:

#4 Post by emil »

nice Howto Jim!
I just needed exactly this.
I think this is the original post from pizzasgood ...
http://www.murga-linux.com/puppy/viewtopic.php?t=24899

nooby
Posts: 10369
Joined: Sun 29 Jun 2008, 19:05
Location: SwedenEurope

#5 Post by nooby »

very good thread. I guess this can be used to edit in European Keyboard stuff from scratch? And set the Firewall to be on from out of the box too.

Maybe add Firefox and Chrome or is that in the sfs?
I use Google Search on Puppy Forum
not an ideal solution though

User avatar
Sit Heel Speak
Posts: 2595
Joined: Fri 31 Mar 2006, 03:22
Location: downwind

#6 Post by Sit Heel Speak »

@iguleder:

cp -pa is good to know. Thanks!

@nooby:

Applications which start after the switchroot, such as Firefox and Chrome, are in the .sfs.

PaulBx1
Posts: 2312
Joined: Sat 17 Jun 2006, 03:11
Location: Wyoming, USA

#7 Post by PaulBx1 »

I found that if you make the tempinit directory in /mnt/home, then you get all sorts of "Operation not permitted" errors in the zcat step which makes the procedure fail. Putting it somewhere else, like in /root or /tmp, works fine.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#8 Post by rcrsn51 »

With what file system is your /mnt/home formatted?

PaulBx1
Posts: 2312
Joined: Sat 17 Jun 2006, 03:11
Location: Wyoming, USA

#9 Post by PaulBx1 »

I'm sorry I didn't see this question earlier. Now I can't tell you for sure. I've recently gone from ext2 back to FAT32, and also may have edited initrd.gz on different flash drives, so I can't really say. If I had to bet though, I'd say FAT32.

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#10 Post by RSH »

Hello!

Here is the GUI for that Stuff. Did it in /root and works.
http://murga-linux.com/puppy/viewtopic. ... 255#575255
Nice work.

Thanks, RSH

emil
Posts: 633
Joined: Tue 10 Nov 2009, 08:36
Location: Austria
Contact:

#11 Post by emil »

Sorry misspost - should have gone to
http://murga-linux.com/puppy/viewtopic. ... 255#575255

Super das es geklappt hat - ich habe das mit dem Abändern der Namen auch schon einmal probiert - habs allerdings nicht geschafft und dann darauf verzichtet.

Einen Kommentar habe ich noch zum Link - in einem Kommentar heisst es man müsste mit cp -pa kopieren, da busybox das SUID flag benötigen würde. Da bin ich mir überhaupt nicht sicher.

So gut kenne ich mich in Linux nicht aus, aber
SUID heisst das alle Busybox Befehle (/bin/busybox) immer mit root Berechtigung ausgeführt werden, egal welcher user (immerhin können auch unter puppy einige Server und daemons gestartet werden die jeweils unter ihrem eigenen user laufen.) Und busybox beinhaltet sehr viele shell Befehle.

Ich habe z.b. im slacko RC geschaut, hier ist das SUID nicht gesetzt.

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#12 Post by RSH »

Hello,

SUID? I think that means Super User ID.

So, after I failed editing the initrd.gz, my Puppy Studio doesn't boot anymore. I've used Puppy 4.1 and edited the initrd.gz again. After repacking the initrd.gz copying the File with Mouseaction (Drag & Drop) did not work. Always getting an Error Message. Using the "cp -pa" did not work, because i did not know enough about the Syntax.

Please: could anyone post a Full-Syntax-Example, using "cp -pa"? and maybe one or two other examples to explain Terminalksyntaxes to me?

So, I've edited the initrd.gz again (outside of Puppy, sdb1) and it prints a long List of "no permissions"-Messages on my Screen. I quit Puppy 4.1 and reboot my PC with Puppy Studio from DVD. Edited the initrd.gz again, inserted the Line: DISTRO_FILE_PREFIX="cpup" after inserting the Line: DISTRO_PUPPYSFS="cpup_330.sfs" end repack the initrd.gz. It works. No "No-Permissions"-Messages on the Scrren and the initrd.gz has been copied by Drag & Drop.

The "New"-Puppy now searches for "cpup_330.sfs. The Savefile is now cpupsave-blablabla.2fs and it is loaded by the new Puppy as well.

NOW I WILL OVERCOME THE WORLD WITH NEW PUPPIES. (just kidding)

RSH

Any further Messages will be posted here: http://murga-linux.com/puppy/viewtopic. ... 255#575255

Edit: and now, there is a english GUI right here:http://murga-linux.com/puppy/viewtopic. ... 255#575255

User avatar
dejan555
Posts: 2798
Joined: Sun 30 Nov 2008, 11:57
Location: Montenegro
Contact:

#13 Post by dejan555 »

I made this into simple script cli-only to include in dpup
I named it initrd-edit but you can save into script and give whatever name you want.

Code: Select all

#!/bin/bash

case $1 in

-u|--unpack)
if [ ! -f initrd.gz ];then
echo "initrd.gz not found. Change to directory containing initrd.gz then run this command again"
exit
fi

echo "Making initrd-tree directory..."
mkdir initrd-tree
cd initrd-tree/
echo "Unpacking initrd.gz..."
zcat ../initrd.gz | cpio -i -d 
echo "Done. Now you can edit files inside initrd-tree dir, then run \"initrd-edit -r\" to make new initrd.gz"
;;

-r|--repack)
if [ ! -d initrd-tree ];then
echo "initrd-tree not found. Change to directory containing initrd-tree then run this command again"
exit
fi

if [ -f initrd.gz ];then
	echo "Backup old initrd.gz? (y/n)"
	read bkpchoice
		if [ "$bkpchoice" = "y" ];then
			echo "Making backup of old initrd,gz..."
			mv initrd.gz initrd.gz.bkp
		fi
fi

cd initrd-tree
echo "Repacking initrd.gz..."
find . | cpio -o -H newc | gzip -9 > ../initrd.gz 
cd ..
echo "Remove initrd-tree? (y/n)"
read choice
[ "$choice" = "y" ] && rm -rf initrd-tree
echo "Done."
;;

*)
echo "Script to unpack or repack initrd.gz 
You need to run it from directory containing initrd.gz or initrd-tree 
Usage: 
inird-edit [command] 
Commands: 
-u | --unpack :Unpacks initrd.gz 
-r | --repack :Repacks initrd.gz"
;;

esac
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]

Post Reply