linux-live/initramfs/initramfs_create

99 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
. ../.config
INITRAMFS=/tmp/$LIVEKITNAME-initramfs-$$
# copy file to initramfs tree, including
# all library dependencies (as shown by ldd)
# $1 = file to copy (full path)
copy_including_deps()
{
# if source doesn't exist or target exists, do nothing
if [ ! -e "$1" -o -e "$INITRAMFS"/"$1" ]; then
return
fi
cp -R --parents "$1" "$INITRAMFS"
if [ -L "$1" ]; then
DIR="$(dirname "$1")"
LNK="$(readlink "$1")"
copy_including_deps "$(cd "$DIR"; realpath -s "$LNK")"
fi
ldd "$1" 2>/dev/null | sed -r "s/.*=>|[(].*//g" | sed -r "s/^\\s+|\\s+\$//" \
| while read LIB; do
copy_including_deps "$LIB"
done
shift
if [ "$1" != "" ]; then
copy_including_deps "$@"
fi
}
rm -Rf $INITRAMFS
mkdir -p $INITRAMFS/{bin,dev,etc,lib,lib64,mnt,proc,root,run,sbin,sys,tmp,usr,var/log}
if [ ! -e busybox/busybox ]; then
cd busybox
./update
cd ..
fi
cp busybox/busybox $INITRAMFS/bin
busybox/busybox | grep , | grep -v Copyright | tr "," " " | while read LINE; do
for TOOL in $LINE; do
ln -s busybox $INITRAMFS/bin/$TOOL
ln -s ../bin/busybox $INITRAMFS/sbin/$TOOL
done
done
mknod $INITRAMFS/dev/console c 5 1
mknod $INITRAMFS/dev/null c 1 3
mknod $INITRAMFS/dev/ram0 b 1 0
#mknod $INITRAMFS/dev/systty
mknod $INITRAMFS/dev/tty1 c 4 1
mknod $INITRAMFS/dev/tty2 c 4 2
mknod $INITRAMFS/dev/tty3 c 4 3
mknod $INITRAMFS/dev/tty4 c 4 4
#tar -C $INITRAMFS -xf initrd-tree.tar.gz
#rm $INITRAMFS/* 2>/dev/null # only files
#copy_including_deps /lib64/libc.so.*
#copy_including_deps /lib64/libm.so.*
#copy_including_deps /dev/ram /dev/systty /dev/fuse
#copy_including_deps /dev/tty /dev/tty?
#copy_including_deps /bin/bash /bin/mount /bin/umount /bin/mkdir
#copy_including_deps /bin/ln /bin/cat /bin/ls /bin/free
#copy_including_deps /sbin/blkid /sbin/swapon /sbin/mkswap /sbin/modprobe
#copy_including_deps /bin/grep /bin/egrep /bin/cut /bin/tr
#copy_including_deps /sbin/lsmod
#copy_including_deps /sbin/fdisk
#copy_including_deps /bin/uname
#copy_including_deps /usr/bin/vi
#copy_including_deps /usr/bin/strace
# TODO: add all comon filesystems which are NOT compiled in kernel already
copy_including_deps /$LMK/kernel/fs/squashfs
copy_including_deps /$LMK/kernel/drivers/staging/zram
copy_including_deps /$LMK/modules.*
depmod -b $INITRAMFS
echo "root::0:0::/root:/bin/bash" >$INITRAMFS/etc/passwd
touch $INITRAMFS/etc/{m,fs}tab
cp init $INITRAMFS/
chmod a+x $INITRAMFS/init
cp ../livekitlib $INITRAMFS/
cp ../.config $INITRAMFS/
cd $INITRAMFS
find . -print | cpio -o -H newc 2>/dev/null | gzip -f --best >$INITRAMFS.img
echo $INITRAMFS.img
cd ..
rm -Rf $INITRAMFS