[SCRIPT] for resizing initrd with specified size

Post tutorials, HOWTO's and other useful resources here.
User avatar
fanthom
Moderator Team
Moderator Team
Posts: 5666
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland
Contact:

[SCRIPT] for resizing initrd with specified size

Post#1 by fanthom » 08 Jan 2011, 19:52

Use this script to resize and tweak initrd.

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
Save it as '/usr/bin/resize-initrd' or whatever, and make executable: 'chmod +x /usr/bin/resize-initrd'.
Launch it with full patch to initrd.lz
Please add [Solved] to your thread title if the solution was found.

User avatar
Ahau
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

Re: [SCRIPT] for resizing initrd with specified size

Post#2 by Ahau » 30 Jun 2011, 14:18

This script was for Version 0.9. Fanthom updated this script for Version 1.0 (using xz compression). Get that script here

Thanks!
Please take a look at our online documentation, here. Suggestions are welcome!

Post Reply