Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 20 Sep 2014, 22:19
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Howto unpack, edit and repack initrd.gz
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [13 Posts]  
Author Message
Jim1911

Joined: 19 May 2008
Posts: 2457
Location: Texas, USA

PostPosted: Mon 01 Mar 2010, 13:14    Post subject:  Howto unpack, edit and repack initrd.gz  

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:
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:
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, 16:18; edited 3 times in total
Back to top
View user's profile Send private message 
Iguleder


Joined: 11 Aug 2009
Posts: 1907
Location: Israel, somewhere in the beautiful desert

PostPosted: Mon 01 Mar 2010, 14:22    Post subject:  

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
Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
ICQ Number 
Jim1911

Joined: 19 May 2008
Posts: 2457
Location: Texas, USA

PostPosted: Mon 01 Mar 2010, 16:46    Post subject:  

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.
Back to top
View user's profile Send private message 
emil

Joined: 10 Nov 2009
Posts: 618
Location: Austria

PostPosted: Tue 02 Mar 2010, 04:34    Post subject:  

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
Back to top
View user's profile Send private message Visit poster's website 
nooby

Joined: 29 Jun 2008
Posts: 10557
Location: SwedenEurope

PostPosted: Tue 02 Mar 2010, 07:23    Post subject:  

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
Back to top
View user's profile Send private message 
Sit Heel Speak


Joined: 30 Mar 2006
Posts: 2595
Location: downwind

PostPosted: Sun 18 Apr 2010, 15:33    Post subject:  

@iguleder:

cp -pa is good to know. Thanks!

@nooby:

Applications which start after the switchroot, such as Firefox and Chrome, are in the .sfs.
Back to top
View user's profile Send private message 
PaulBx1

Joined: 16 Jun 2006
Posts: 2308
Location: Wyoming, USA

PostPosted: Mon 18 Jul 2011, 12:34    Post subject:  

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.
Back to top
View user's profile Send private message 
rcrsn51


Joined: 05 Sep 2006
Posts: 9121
Location: Stratford, Ontario

PostPosted: Tue 19 Jul 2011, 04:35    Post subject:  

With what file system is your /mnt/home formatted?
Back to top
View user's profile Send private message 
PaulBx1

Joined: 16 Jun 2006
Posts: 2308
Location: Wyoming, USA

PostPosted: Sat 30 Jul 2011, 20:07    Post subject:  

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.
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Sat 22 Oct 2011, 03:31    Post subject:  

Hello!

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

Thanks, RSH
Back to top
View user's profile Send private message 
emil

Joined: 10 Nov 2009
Posts: 618
Location: Austria

PostPosted: Sat 22 Oct 2011, 07:32    Post subject:  

Sorry misspost - should have gone to
http://murga-linux.com/puppy/viewtopic.php?p=575255#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.
Back to top
View user's profile Send private message Visit poster's website 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Sat 22 Oct 2011, 11:48    Post subject:  

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.php?p=575255#575255

Edit: and now, there is a english GUI right here:http://murga-linux.com/puppy/viewtopic.php?p=575255#575255
Back to top
View user's profile Send private message 
dejan555


Joined: 30 Nov 2008
Posts: 2648
Location: Montenegro

PostPosted: Sun 20 Apr 2014, 04:17    Post subject:  

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:
#!/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

_________________


Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
Display posts from previous:   Sort by:   
Page 1 of 1 [13 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0793s ][ Queries: 12 (0.0040s) ][ GZIP on ]