-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmake_initramfs
executable file
·132 lines (112 loc) · 1.98 KB
/
make_initramfs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
ROOT=/boot
INITRAMFS="$ROOT/initramfs"
XZ_OPTS="--check=crc32 --lzma2=dict=512KiB"
if [ -z $1 ]
then
CREATE=1
INITRAM_DIR=`mktemp -d -t initramfs.XXX`
else
CREATE=0
INITRAM_DIR=$1
fi
DIRS=" sys
proc
dev
etc
newroot
usr/lib
usr/bin
"
declare -A LINKS=(
[bin]="usr/bin"
[sbin]="usr/bin"
[usr/sbin]="bin"
[lib]="usr/lib"
[lib64]="usr/lib"
[usr/lib64]="lib"
)
BINS=" /sbin/zpool
/sbin/mount.zfs
/sbin/zfs
/bin/busybox
/lib/libgcc_s.so.1
"
EXTRA=" /etc/hostid
"
declare -A LIBS=()
resolve_libs() {
for lib in `objdump -p $1 | grep NEEDED | sed 's/\s\+NEEDED\s\+//'`
do
if [[ ! -n "${LIBS[/lib/${lib}]}" ]]
then
LIBS[/lib/${lib}]=0;
fi
done
}
echo "composing initramfs in $INITRAM_DIR"
if [ $CREATE == 0 ]
then
echo "Remove old initramfs in $INITRAM_DIR? (y/n)"
read ANS
if [ $ANS == "y" ]
then
rm -r $INITRAM_DIR
fi
fi
for dir in $DIRS
do
mkdir -p $INITRAM_DIR/$dir
done
for link in ${!LINKS[@]}
do
ln -s ${LINKS[$link]} $INITRAM_DIR/${link}
done
for bin in ${BINS}
do
echo "\tresolving $bin"
cp $bin ${INITRAM_DIR}/$bin
resolve_libs $bin
done
for i in {1..10}
do
for lib in ${!LIBS[@]}
do
if [[ ${LIBS[${lib}]} == 0 ]]
then
echo "\tresolving $lib"
cp -L $lib ${INITRAM_DIR}/$lib
LIBS[${lib}]=1;
resolve_libs $lib
fi
done
done
# add /dev/console
mknod $INITRAM_DIR/dev/console c 5 1 2>/dev/null
for bin in $EXTRA
do
[ -e $bin ] || continue
mkdir -p $INITRAM_DIR/`dirname $bin`
cp -L $bin $INITRAM_DIR/$bin
done
# populate plymouth if available
if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]
then
/usr/libexec/plymouth/plymouth-populate-initrd -t $INITRAM_DIR
fi
# init
cp /root/bin/init.tpl $INITRAM_DIR/init
chmod +x $INITRAM_DIR/init
cp /etc/zfs/*.cache $INITRAM_DIR/etc/
if [ $CREATE == 1 ]
then
# backup
echo "backing up $INITRAMFS"
mv $INITRAMFS $INITRAMFS.old
# create
echo "creating new $INITRAMFS"
cd $INITRAM_DIR
find . | cpio --quiet -o -H newc | xz $XZ_OPTS > $INITRAMFS
cd
rm -r $INITRAM_DIR
fi