summaryrefslogtreecommitdiff
path: root/mkinitram
blob: 5f2b8026833e683ac527a04b01760fadb2c297b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh

msg() {
	echo "==>" $@
}

die() {
	echo $@
	exit 1
}

APKS=tmp/apks

image=$PWD/image
dest=$PWD/test.gz
init=init


kernel=$1
# if no kernel specified, then guess...
if [ -z "$kernel" ]; then
	kernel=$(ls /lib/modules 2>/dev/null | tail -n 1)
fi

if [ ! -d /lib/modules/$kernel ]; then
	die "modules dir /lib/modules/$kernel was not found"
fi
msg "Using kernel $kernel"

# create empty image dir

rm -rf "$image"
mkdir -p "$image/dev" "$image/etc/rcS.d"

# unpack busybox and deps
tar -C $image -zxf $APKS/uclibc-[0-9]*.apk
tar -C $image -zxf $APKS/busybox-[0-9]*.apk
tar -C $image -zxf $APKS/alpine-baselayout-[0-9]*.apk
tar -C $image -zxf $APKS/apk-tools-[0-9]*.apk
rm -f $image/.PKGINFO
ln -sf /bin/busybox $image/init

# create misc devs and enable boot scripts
mknod $image/dev/null c 2 2
ln -s ../init.d/mdev $image/etc/rcS.d/S10mdev
ln -s ../init.d/hwdrivers $image/etc/rcS.d/S30hwdrivers
ln -s ../init.d/modutils $image/etc/rcS.d/S40modutils

# load those extra drivers
for i in ide-cd usb-storage ide-disk; do
	echo $i >> $image/etc/modules
done


# copy kernel modules
kmods=$image/lib/modules/$kernel
mkdir -p $kmods/kernel/drivers

for i in ata block ide ieee1394 scsi cdrom usb message; do
	cp -LpR /lib/modules/$kernel/kernel/drivers/$i $kmods/kernel/drivers/
done

for i in fs lib; do
	cp -LpR /lib/modules/$kernel/kernel/$i $kmods/kernel/
done

depmod $kernel -b $image
	

# generate the image
cd $image
find . | cpio -o -H newc | gzip -9 > $dest