comparison root-image.sh @ 1606:941d2bf65620

Move image creation logic into sources/functions.sh so we can create cpio and squashfs in the same build.
author Rob Landley <rob@landley.net>
date Wed, 03 Jul 2013 22:51:41 -0500
parents 8bbf3038c0f2
children
comparison
equal deleted inserted replaced
1605:085c2b22ff06 1606:941d2bf65620
29 29
30 [ -z "$SYSIMAGE_TYPE" ] && SYSIMAGE_TYPE=squashfs 30 [ -z "$SYSIMAGE_TYPE" ] && SYSIMAGE_TYPE=squashfs
31 31
32 echo "Generating $SYSIMAGE_TYPE root filesystem from $NATIVE_ROOT." 32 echo "Generating $SYSIMAGE_TYPE root filesystem from $NATIVE_ROOT."
33 33
34 # Embed an initramfs image in the kernel? 34 SYSIMAGE_TYPE="$SYSIMAGE_TYPE" image_filesystem "$NATIVE_ROOT" "$STAGE_DIR/hda"
35
36 if [ "$SYSIMAGE_TYPE" == "initramfs" ]
37 then
38 # Borrow gen_init_cpio.c out of package cache copy of Linux source
39 extract_package linux &&
40 $CC "$(package_cache $PACKAGE)/usr/gen_init_cpio.c" -o "$WORK"/my_gen_init_cpio ||
41 dienow
42 "$WORK"/my_gen_init_cpio <(
43 "$SOURCES"/toys/gen_initramfs_list.sh "$NATIVE_ROOT" || dienow
44 [ ! -e "$NATIVE_ROOT"/init ] &&
45 echo "slink /init /sbin/init.sh 755 0 0"
46 [ ! -d "$NATIVE_ROOT"/dev ] && echo "dir /dev 755 0 0"
47 echo "nod /dev/console 660 0 0 c 5 1"
48 ) > "$STAGE_DIR/initramfs_data.cpio" || dienow
49 echo Initramfs generated.
50
51 elif [ "$SYSIMAGE_TYPE" == "ext2" ]
52 then
53 # Generate a 64 megabyte ext2 filesystem image from the $NATIVE_ROOT
54 # directory, with a temporary file defining the /dev nodes for the new
55 # filesystem.
56
57 [ -z "$SYSIMAGE_HDA_MEGS" ] && SYSIMAGE_HDA_MEGS=64
58
59 # Produce a filesystem with the currently used space plus 20% for filesystem
60 # overhead, which should always be big enough.
61
62 BLOCKS=$[1024*(($(du -m -s "$NATIVE_ROOT" | awk '{print $1}')*12)/10)]
63 [ $BLOCKS -lt 4096 ] && BLOCKS=4096
64 IMAGE="$STAGE_DIR/hda.ext2"
65
66 echo "/dev d 755 0 0 - - - - -" > "$WORK/devs" &&
67 echo "/dev/console c 640 0 0 5 1 0 0 -" >> "$WORK/devs" &&
68 genext2fs -z -D "$WORK/devs" -d "$NATIVE_ROOT" -b $BLOCKS -i 1024 "$IMAGE" &&
69 rm "$WORK/devs" || dienow
70
71 # Extend image size to HDA_MEGS if necessary, keeping it sparse. (Feeding
72 # a larger -b size to genext2fs is insanely slow, and not particularly
73 # sparse.)
74
75 if [ ! -z "$SYSIMAGE_HDA_MEGS" ] &&
76 [ $((`stat -c %s "$IMAGE"` / (1024*1024) )) -lt "$SYSIMAGE_HDA_MEGS" ]
77 then
78 echo resizing image to $SYSIMAGE_HDA_MEGS
79 resize2fs "$IMAGE" ${SYSIMAGE_HDA_MEGS}M || dienow
80 echo resize complete
81 fi
82
83 elif [ "$SYSIMAGE_TYPE" == "squashfs" ]
84 then
85 mksquashfs "${NATIVE_ROOT}" "$STAGE_DIR/hda.sqf" -noappend -all-root \
86 ${FORK:+-no-progress} -p "/dev d 755 0 0" \
87 -p "/dev/console c 666 0 0 5 1" || dienow
88 else
89 echo "Unknown image type $SYSIMAGE_TYPE" >&2
90 dienow
91 fi
92 35
93 create_stage_tarball 36 create_stage_tarball
94 37
95 echo Image generation complete. 38 echo Image generation complete.