3 # create_initrd_loop(size)
6 [ "$#" -ne '1' ] && gen_die 'create_initrd_loop(): Not enough arguments!'
7 mkdir -p ${TEMP}/initrd-mount ||
8 gen_die 'Could not create loopback mount directory!'
9 dd if=/dev/zero of=${TMPDIR}/initrd-${KV} bs=1k count=${1} >> "${LOGFILE}" 2>&1 ||
10 gen_die "Could not zero initrd-${KV}"
11 mke2fs -F -N750 -q "${TMPDIR}/initrd-${KV}" >> "${LOGFILE}" 2>&1 ||
12 gen_die "Could not format initrd-${KV}!"
13 mount -t ext2 -o loop "${TMPDIR}/initrd-${KV}" "${TEMP}/initrd-mount" >> "${LOGFILE}" 2>&1 ||
14 gen_die 'Could not mount the initrd filesystem!'
17 create_initrd_unmount_loop() {
19 umount "${TEMP}/initrd-mount" ||
20 gen_die 'Could not unmount initrd system!'
23 move_initrd_to_loop() {
24 cd "${TEMP}/initrd-temp"
25 mv * "${TEMP}/initrd-mount" >> ${LOGFILE} 2>&1
28 # check for static linked file with objdump
30 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
34 create_base_initrd_sys() {
35 rm -rf "${TEMP}/initrd-temp" > /dev/null
36 mkdir -p ${TEMP}/initrd-temp/dev
37 mkdir -p ${TEMP}/initrd-temp/bin
38 mkdir -p ${TEMP}/initrd-temp/etc
39 mkdir -p ${TEMP}/initrd-temp/usr
40 mkdir -p ${TEMP}/initrd-temp/proc
41 mkdir -p ${TEMP}/initrd-temp/temp
42 mkdir -p ${TEMP}/initrd-temp/sys
43 mkdir -p ${TEMP}/initrd-temp/.initrd
44 mkdir -p ${TEMP}/initrd-temp/var/lock/dmraid
45 ln -s bin ${TEMP}/initrd-temp/sbin
46 ln -s ../bin ${TEMP}/initrd-temp/usr/bin
47 ln -s ../bin ${TEMP}/initrd-temp/usr/sbin
49 echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initrd-temp/etc/fstab
50 echo "proc /proc proc defaults 0 0" >> ${TEMP}/initrd-temp/etc/fstab
52 cd ${TEMP}/initrd-temp/dev
56 if [ "${DISKLABEL}" -eq '1' ]; then
57 cp "${BLKID_BINCACHE}" "${TEMP}/initrd-temp/bin/blkid.bz2" ||
58 gen_die 'Could not copy blkid from bincache!'
59 bunzip2 "${TEMP}/initrd-temp/bin/blkid.bz2" ||
60 gen_die 'Could not uncompress blkid!'
61 chmod +x "${TEMP}/initrd-temp/bin/blkid"
64 tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initrd-temp/bin" busybox ||
65 gen_die 'Could not extract busybox bincache!'
66 chmod +x "${TEMP}/initrd-temp/bin/busybox"
69 if [ "${DMRAID}" -eq '1' ]
71 print_info 1 'DMRAID: Adding support (compiling binaries)...'
73 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initrd-temp" ||
74 gen_die "Could not extract dmraid binary cache!";
78 if [ "${LVM}" -eq '1' ]
80 if [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable';
82 print_info 1 'LVM: Adding support (using local static binaries)...'
83 cp /sbin/lvm "${TEMP}/initrd-temp/bin/lvm" ||
84 gen_die 'Could not copy over lvm!'
86 print_info 1 'LVM: Adding support (compiling binaries)...'
89 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initrd-temp" ||
90 gen_die "Could not extract lvm binary cache!";
91 mv ${TEMP}/initrd-temp/bin/lvm.static ${TEMP}/initrd-temp/bin/lvm ||
92 gen_die 'LVM error: Could not move lvm.static to lvm!'
94 for i in vgchange vgscan; do
95 ln ${TEMP}/initrd-temp/bin/lvm ${TEMP}/initrd-temp/bin/$i ||
96 gen_die "LVM error: Could not link ${i}!"
98 mkdir -p ${TEMP}/initrd-temp/etc/lvm
101 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
105 cp /etc/lvm/lvm.conf "${TEMP}/initrd-temp/etc/lvm/" ||
106 gen_die 'Could not copy over lvm.conf!'
108 # gen_die 'Could not copy over lvm.conf!'
114 if [ "${EVMS}" -eq '1' ]
116 if [ -e '/sbin/evms_activate' ]
118 print_info 1 'EVMS: Adding support...'
119 mkdir -p ${TEMP}/initrd-temp/lib
120 mkdir -p ${TEMP}/initrd-temp/sbin
121 mkdir -p ${TEMP}/initrd-temp/etc
122 mkdir -p ${TEMP}/initrd-temp/bin
123 cp -a /lib/ld-* "${TEMP}/initrd-temp/lib" \
124 || gen_die 'Could not copy files for EVMS!'
125 if [ -n "`ls /lib/libgcc_s*`" ]
127 cp -a /lib/libgcc_s* "${TEMP}/initrd-temp/lib" \
128 || gen_die 'Could not copy files for EVMS!'
130 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initrd-temp/lib" \
131 || gen_die 'Could not copy files for EVMS!'
132 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initrd-temp/lib" \
133 || gen_die 'Could not copy files for EVMS!'
134 cp -a /lib/libpthread* "${TEMP}/initrd-temp/lib" \
135 || gen_die 'Could not copy files for EVMS!'
136 cp -a /lib/libuuid*so* "${TEMP}/initrd-temp/lib" \
137 || gen_die 'Could not copy files for EVMS!'
138 cp -a /lib/libevms*so* "${TEMP}/initrd-temp/lib" \
139 || gen_die 'Could not copy files for EVMS!'
140 cp -a /lib/evms "${TEMP}/initrd-temp/lib" \
141 || gen_die 'Could not copy files for EVMS!'
142 cp -a /lib/evms/* "${TEMP}/initrd-temp/lib/evms" \
143 || gen_die 'Could not copy files for EVMS!'
144 cp -a /etc/evms.conf "${TEMP}/initrd-temp/etc" \
145 || gen_die 'Could not copy files for EVMS!'
146 cp /sbin/evms_activate "${TEMP}/initrd-temp/sbin" \
147 || gen_die 'Could not copy over evms_activate!'
148 # Fix EVMS complaining that it cant find the swap utilities.
149 # These are not required in the initrd
150 for swap_libs in "${TEMP}/initrd-temp/lib/evms/*/swap*.so"
157 for i in '[' ash basename cat chroot clear cp dirname echo env false find \
158 grep gunzip gzip ln ls loadkmap losetup lsmod mdev mkdir mknod more mount \
159 mv pivot_root ps awk pwd rm rmdir rmmod sed sh sleep tar test touch true \
160 umount uname xargs yes zcat chmod chown cut kill killall; do
161 rm -f ${TEMP}/initrd-temp/bin/$i > /dev/null
162 ln ${TEMP}/initrd-temp/bin/busybox ${TEMP}/initrd-temp/bin/$i ||
163 gen_die "Busybox error: could not link ${i}!"
168 if is_static /bin/cryptsetup
170 print_info 1 "Including LUKS support"
171 rm -f ${TEMP}/initrd-temp/sbin/cryptsetup
172 cp /bin/cryptsetup ${TEMP}/initrd-temp/sbin/cryptsetup
173 chmod +x "${TEMP}/initrd-temp/sbin/cryptsetup"
174 elif is_static /sbin/cryptsetup
176 print_info 1 "Including LUKS support"
177 rm -f ${TEMP}/initrd-temp/sbin/cryptsetup
178 cp /sbin/cryptsetup ${TEMP}/initrd-temp/sbin/cryptsetup
179 chmod +x "${TEMP}/initrd-temp/sbin/cryptsetup"
181 print_info 1 "LUKS support requires static cryptsetup at /bin/cryptsetup or /sbin/cryptsetup"
182 print_info 1 "Not including LUKS support"
195 create_initrd_modules() {
199 if [ "${PAT}" -gt "4" ]
206 print_info 2 "initrd: >> Searching for modules..."
208 if [ "${INSTALL_MOD_PATH}" != '' ]
210 cd ${INSTALL_MOD_PATH}
215 for i in `gen_dep_list`
217 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1`
220 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
223 print_info 2 "initrd: >> Copying ${i}${MOD_EXT}..."
224 cp -ax --parents "${mymod}" "${TEMP}/initrd-temp"
227 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initrd-temp 2>/dev/null
229 mkdir -p "${TEMP}/initrd-temp/etc/modules"
230 for group_modules in ${!MODULES_*}; do
231 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
232 print_list ${!group_modules} > "${TEMP}/initrd-temp/etc/modules/${group}"
236 create_initrd_aux() {
237 if [ -f "${CMD_LINUXRC}" ]
239 cp "${CMD_LINUXRC}" "${TEMP}/initrd-temp/linuxrc"
240 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC}"
242 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
244 cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initrd-temp/linuxrc"
246 cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initrd-temp/linuxrc"
250 # Make sure it's executable
251 chmod 0755 "${TEMP}/initrd-temp/linuxrc"
253 if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
255 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
257 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
260 if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
262 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
264 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
267 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
268 for group_modules in ${!MODULES_*}; do
269 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
270 echo -n "${group} " >> "${TEMP}/initrd-temp/etc/initrd.defaults"
272 echo '"' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
274 if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
276 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
278 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
280 if isTrue $CMD_DOKEYMAPAUTO
282 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
284 if isTrue $CMD_KEYMAP
286 mkdir -p "${TEMP}/initrd-temp/lib/keymaps"
287 /bin/tar -C "${TEMP}/initrd-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
289 if isTrue $CMD_SLOWUSB
291 echo 'MY_HWOPTS="${MY_HWOPTS} slowusb"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
294 cd ${TEMP}/initrd-temp/sbin && ln -s ../linuxrc init
296 chmod +x "${TEMP}/initrd-temp/linuxrc"
297 chmod +x "${TEMP}/initrd-temp/etc/initrd.scripts"
298 chmod +x "${TEMP}/initrd-temp/etc/initrd.defaults"
299 chmod +x "${TEMP}/initrd-temp/sbin/modprobe"
304 cd ${TEMP}/initrd-temp/
305 TEST=`du -sk 2> /dev/null`
306 echo $TEST | cut "-d " -f1
312 print_info 1 "initrd: >> Initializing..."
313 create_base_initrd_sys
315 if [ "${NOINITRDMODULES}" -eq '0' ]
317 print_info 1 " >> Copying modules..."
318 create_initrd_modules
320 print_info 1 "initrd: Not copying modules..."
323 print_info 1 " >> Copying auxilary files..."
326 INITRD_CALC_SIZE=`calc_initrd_size`
327 INITRD_SIZE=`expr ${INITRD_CALC_SIZE} + 250`
328 print_info 1 " :: Size is at ${INITRD_SIZE}K"
329 print_info 1 " >> Creating loopback filesystem..."
330 create_initrd_loop ${INITRD_SIZE}
332 print_info 1 " >> Moving initrd files to the loopback..."
335 print_info 1 " >> Cleaning up and compressing the initrd..."
336 create_initrd_unmount_loop
338 if [ "${COMPRESS_INITRD}" ]
340 gzip -f -9 ${TMPDIR}/initrd-${KV}
341 mv ${TMPDIR}/initrd-${KV}.gz ${TMPDIR}/initrd-${KV}
344 if ! isTrue "${CMD_NOINSTALL}"
346 copy_image_with_preserve "initrd" \
347 "${TMPDIR}/initrd-${KV}" \
348 "initrd-${KNAME}-${ARCH}-${KV}"
351 # if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
353 # # Pegasos hack for merging the initramfs into the kernel at compile time
354 # cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz &&
355 # rm ${TMPDIR}/initrd-${KV}