Files
linuxkit/alpine/mkinitrd.sh
Justin Cormack b6cb412309 Align compressed initrd to 4 bytes
Allows appending another initrd.

Also build initrd on tmpfs as should be a bit faster now we have to do
another copy.

Fix #618

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
2016-12-02 16:05:49 +00:00

63 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
set -e
rm -rf /tmp/*
for f in $(ls | grep -vE 'dev|sys|proc|tmp|export|mnt')
do
cp -a $f /tmp
done
mkdir -m 555 /tmp/dev /tmp/proc /tmp/sys /tmp/mnt
mkdir -m 1777 /tmp/tmp
# these three files are bind mounted in by docker so they are not what we want
cat << EOF > /tmp/etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
cat << EOF > /tmp/etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
EOF
printf 'moby' > /tmp/etc/hostname
cd /tmp
rm mkinitrd.sh
find . | cpio -H newc -o | gzip -9 > /initrd/initrd.img
cd /initrd
SIZE=$(stat -c "%s" initrd.img)
SIZE4=$(( $SIZE / 4 \* 4 ))
DIFF=$(( $SIZE - $SIZE4 ))
[ $DIFF -ne 0 ] && DIFF=$(( 4 - $DIFF ))
dd if=/dev/zero bs=1 count=$DIFF of=zeropad
cat zeropad >> initrd.img
SIZE=$(stat -c "%s" initrd.img)
SIZE4=$(( $SIZE / 4 \* 4 ))
DIFF=$(( $SIZE - $SIZE4 ))
if [ $DIFF -ne 0 ]
then
echo "Bad aligment" >2
exit 1
fi
cat initrd.img