Extraction -> Customization -> Rebuilding
- commands issued under the temporary working directory.
- switch to root if required like mknod needs privilege.
GZ Based (Debian)
Extraction
gzip -dc ../initrd.gz | cpio -idmv --no-absolute-filenames
Rebuilding
find . | cpio -o -H newc | gzip -9 > ../initrd.gz
XZ Based (Redhat)
Extraction
xz -dc ../initrd.img | cpio -idmv --no-absolute-filenames
Rebuilding
find . | cpio -o -H newc | xz -9 > ../initrd.img
Other Distros

Analyze file format then do extraction and rebuilding accordingly.