This is a solution for, "if you decompress you initrd.gz file to somewhere where you shouldn't (like /mnt/home) and you want to rebuild it". However, the easy way to solve this problem would probably just be to delete the directories and recopy initrd.gz from the CD.
However, this won't let us edit the files if we want to and I tried to add some variables in the script so it is easy to adapt the code to a more sensible place to decompress the ram disk.
The scripts hard codes all the initrd directories individually so that if for some reason you wanted to pull one or two directories from some place else it would be easy to do this. But then again would someone really want to do this? I don't know I said it was pointless code...well mostly pointless. This is practice code for me and I haven't even tested it yet. But you know it gives me something to look at when I'm away from my computer and want to think about it. I will updated this post with the modified code after I test it and fix the bugs.
The code is loosely based on the mkird script from an IBM tutorial.
https://www.ibm.com/developerworks/library/l-initrd/
but any remnants of the initial tutorial is mostly for reference.
Here is the code:
Code: Select all
#!/bin/bash
# s243a: Not sure I need this yet
## Housekeeping...
#rm -f /tmp/ramdisk.img
#rm -f /tmp/ramdisk.img.gz
SOURCE=/mnt/home #If we decompressed initrd.gz without moving it
#See: http://murga-linux.com/puppy/viewtopic.php?p=979708#979708
MOUNT_POINT=/mnt/new_initrd #s243a we can't mount at initrd because puppy already uses this.
# Ramdisk Constants
RDSIZE=1490 #This is the compressed size but what is the uncompressed size?
BLKSIZE=1024
# Create an empty ramdisk image
dd if=/dev/zero of=/tmp/ramdisk.img bs=$BLKSIZE count=$RDSIZE
# Make it an ext2 mountable file system
/sbin/mke2fs -F -m 0 -b $BLKSIZE /tmp/ramdisk.img $RDSIZE
# Mount it so that we can populate
mount /tmp/ramdisk $MOUNT_POINT -t ext2 -o loop=/dev/loop0 #s243a removed the .img since puppy doesn't seem to use it.
#s243a Let's instead copy the files from an existing puppy initrd system
## Populate the filesystem (subdirectories)
#mkdir /mnt/initrd/bin
#mkdir /mnt/initrd/sys
#mkdir /mnt/initrd/dev
#mkdir /mnt/initrd/proc
#
mkdir -p $MOUNT_POINT tmp
declare -a dirs= \
('bin' 'dev' 'etc' 'lib' 'locale' 'mnt' 'proc' 'sbin' 'sys' 'tmp' 'usr' 'var' 'pup_a' 'pup_f' 'pup_ro3' 'pup_ro4' \
'pup_ro5' 'pup_ro6' 'pup_ro7' 'pup_ro8' 'pup_ro9' 'pup_y''pup_z' \
\
'pup_new' # The Layer being added in the /initrd/init script
\
\ #See Lines #14 to #15 for def of puppy layers
\ #pmedia: ram atahd usbhd atahd usbflash Multisession
\ #savetype pfx=ram Full Full Frugal Frugal
\ #PUPMODE:5 6 7 12 13 77
'pup_rw' \ # tmpfs PDEV1 tmpfs pup_save.3fs tmpfs tmpfs
'pup_ro1' \ # ---- ----- PDEV1 ------------ pup_save.3fs folders
'pup_ro2') \ # pup_xxx.sfs pup_xxx.sfs pup_xxx.sfs pup_xxx.sfs pup_xxx.sfs pup_xxx.sfs
for d in "${dirs[@]}"; do
mkdir -p "$MOUNT_POINT/$d"
cp -a $SOURCE/$d/. $MOUNT_POINT
done
#In the orginal tutorial there was a bunch stuff about copying busybox and making various symbolic links
cp -a $SOURCE/README.txt $MOUNT_POINT
cp -a $SOURCE/DISTRO_SPECS $MOUNT_POINT
cp -a $SOURCE/init $MOUNT_POINT
# Will use the existing init file instead (See Previous Line)
## Create the init file
#cat >> /mnt/initrd/linuxrc << EOF
##!/bin/ash
#echo
#echo "Simple initrd is active"
#echo
#mount -t proc /proc /proc
#mount -t sysfs none /sys
#/bin/ash --login
#EOF
#Our init script should already have the correct permissions and is called init.
#chmod +x /mnt/initrd/linuxrc
# Finish up...
umount /mnt/initrd
gzip -9 /tmp/initrd
cp /tmp/initrd.gz $SOURCE/ramdisk.gz #Stuf about .img extension removed because puppy doesn't use it.