Code: Select all
#!/bin/bash
# Variables
old=/tmp/old$$
new=/tmp/new$$
c='\e[36m'
r='\e[31m'
e=`tput sgr0`
if [ "$1" = "" ]; then
echo "launch me with full path to initrd.lz, example: ./resize-initrd /mnt/sr0/boot/initrd.lz"
exit 1
fi
echo -e "${c}creating 2 extra loop devices"$e
x=`ls /dev/loop* | sed s@/dev/loop@@ | sort -n | tail -n1`; y=$(($x+1)); z=$(($y+1))
mknod /dev/loop$y b 7 $y
mknod /dev/loop$z b 7 $z
echo -e "${c}unpacking and mounting initrd"$e
cp $1 /root/initrd.lzma
cd /root
lzma -d initrd.lzma
mkdir $old $new > /dev/null 2>&1
mount -o loop initrd $old
echo -e "${c}please provide size for your new initrd in KB (can't be less than 6666)"$e
read -e size
dd if=/dev/zero of=initrd-new bs=1024 count=$size 2> /dev/null
losetup /dev/loop$z initrd-new
mkfs.ext2 /dev/loop$z > /dev/null 2>&1
mount /dev/loop$z $new
cp -r $old/* $new
echo -e "${c}your $size KB initrd in mounted in $new, now you can copy some extra files to it - press enter when finished..."$e
echo -e "${r}be aware that you need at least 600KB of free space inside initrd, otherwise Porteus wont be able to boot"$e
read
umount $old
umount $new
lzma initrd-new
mv initrd-new.lzma initrd.lz
rm initrd
losetup -d /dev/loop$z
echo -e "${c}all jobs done...
your resized initrd is placed in /root directory"$e
echo -e "${r}please update your bootloader config file with new size of your initrd, add this kernel parameter:
ramdisk_size=$size"$e
echo && echo -e "${c}press enter to exit"$e
read
Launch it with full patch to initrd.lz