How to unpack and modify/customize the initrd

This document (000019918) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Server 15
SUSE Linux Enterprise Server 12

 


Situation

Need to verify what modules are packaged into the initrd or make custom changes to it.

Resolution

The command:
lsinitrd

will show what files got packaged into initrd.

The initrd contains 2 cpio archives a early cpio and the generic one.

To extract content of the generic cpio:

export LANG=C

TMP=`mktemp -d` 
umask 022
mkdir -p $TMP/earlycpio
mkdir $TMP/initramfs
umask 077 

cd $TMP/earlycpio
chmod 755 $TMP/earlycpio
cat /boot/initrd-4.12.14-122.57-default|cpio -idmv 

cd $TMP/initramfs
/usr/lib/dracut/skipcpio /boot/initrd-4.12.14-122.57-default 2>/dev/null| xzcat -- |cpio -idvm 

To repackage initrd:
cd $TMP/earlycpio 
find . -print0| cpio -H newc --null -o > ../initrd.new 

cd $TMP/initramfs 
find . -print0| sort -z | cpio --null -H newc --quiet -o > ../initramfs.img 

cd $TMP 
cat initramfs.img|xz -0 --check=crc32 --memlimit-compress=50% >> initrd.new 

Note: There willbe still difference in size as timestamps differ.

 

Cause

Dracut script /usr/bin/dracut creates 2 cpio archives concatenated.
 

Additional Information

Compare lsinitrd output without timestamps:

lsinitrd $TMP/initrd.new > /tmp/selfbuild 
lsinitrd /boot/initrd-4.12.14-122.57-default >/tmp/dracutbuild 
sed -i "s/Mar .. ..:..//" /tmp/selfbuild /tmp/dracutbuild 

diff -bu /tmp/dracutbuild /tmp/selfbuild

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:000019918
  • Creation Date: 12-Apr-2021
  • Modified Date:12-Apr-2021
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

Join Our Community

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.


SUSE Customer Support Quick Reference Guide SUSE Technical Support Handbook Update Advisories
Support FAQ

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.

Go to Customer Center