-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkbootimg.sh
More file actions
executable file
·168 lines (122 loc) · 4.26 KB
/
mkbootimg.sh
File metadata and controls
executable file
·168 lines (122 loc) · 4.26 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
PACKAGES=" "
EXCLUDE_FROM_WORLD="1"
COMPRESSISO="0"
BOOTIMG_VOLUME_ID="boot"
BOOTIMG_EXTRA_SPACE="512"
#build_directory=/home/wrsadmin/build/toshiba/server-xorg
#set -x
echo "lets begining ..."
build_fat_img() {
if [ $# -neq 2 ] ; then
echo "the para need 2"
fi
FATSOURCEDIR=$1
FATIMG=$2
# Calculate the size required for the final image including the
# data and filesystem overhead.
# Sectors: 512 bytes
# Blocks: 1024 bytes
# Determine the sector count just for the data
SECTORS=$(expr $(du --apparent-size -ks ${FATSOURCEDIR} | cut -f 1) \* 2)
# Account for the filesystem overhead. This includes directory
# entries in the clusters as well as the FAT itself.
# Assumptions:
# FAT32 (12 or 16 may be selected by mkdosfs, but the extra
# padding will be minimal on those smaller images and not
# worth the logic here to caclulate the smaller FAT sizes)
# < 16 entries per directory
# 8.3 filenames only
# 32 bytes per dir entry
DIR_BYTES=$(expr $(find ${FATSOURCEDIR} | tail -n +2 | wc -l) \* 32)
# 32 bytes for every end-of-directory dir entry
DIR_BYTES=$(expr $DIR_BYTES + $(expr $(find ${FATSOURCEDIR} -type d | tail -n +2 | wc -l) \* 32))
# 4 bytes per FAT entry per sector of data
FAT_BYTES=$(expr $SECTORS \* 4)
# 4 bytes per FAT entry per end-of-cluster list
FAT_BYTES=$(expr $FAT_BYTES + $(expr $(find ${FATSOURCEDIR} -type d | tail -n +2 | wc -l) \* 4))
# Use a ceiling function to determine FS overhead in sectors
DIR_SECTORS=$(expr $(expr $DIR_BYTES + 511) / 512)
# There are two FATs on the image
FAT_SECTORS=$(expr $(expr $(expr $FAT_BYTES + 511) / 512) \* 2)
SECTORS=$(expr $SECTORS + $(expr $DIR_SECTORS + $FAT_SECTORS))
# Determine the final size in blocks accounting for some padding
BLOCKS=$(expr $(expr $SECTORS / 2) + ${BOOTIMG_EXTRA_SPACE})
# Ensure total sectors is an integral number of sectors per
# track or mcopy will complain. Sectors are 512 bytes, and we
# generate images with 32 sectors per track. This calculation is
# done in blocks, thus the mod by 16 instead of 32.
BLOCKS=$(expr $BLOCKS + $(expr 16 - $(expr $BLOCKS % 16)))
# mkdosfs will sometimes use FAT16 when it is not appropriate,
# resulting in a boot failure from SYSLINUX. Use FAT32 for
# images larger than 512MB, otherwise let mkdosfs decide.
if [ $(expr $BLOCKS / 1024) -gt 512 ]; then
FATSIZE="-F 32"
fi
# mkdosfs will fail if ${FATIMG} exists. Since we are creating an
# new image, it is safe to delete any previous image.
if [ -e ${FATIMG} ]; then
rm ${FATIMG}
fi
if [ -z "${HDDIMG_ID}" ]; then
mkdosfs ${FATSIZE} -n ${BOOTIMG_VOLUME_ID} -S 512 -C ${FATIMG} \
${BLOCKS}
else
mkdosfs ${FATSIZE} -n ${BOOTIMG_VOLUME_ID} -S 512 -C ${FATIMG} \
${BLOCKS} -i ${HDDIMG_ID}
fi
# Copy FATSOURCEDIR recursively into the image file directly
mcopy -i ${FATIMG} -s ${FATSOURCEDIR}/* ::/
}
build_iso() {
#build_fat_img ${EFIIMGDIR} ${ISODIR}/efi.img
mkisofs_compress_opts="-r"
isohybrid_args="-u"
cd new-iso
tree
$MKISOFS -A boot -V boot -o ../boot-uefi.iso -b isolinux/isolinux.bin -c isolinux/boot.cat \
-r -no-emul-boot -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot -eltorito-platform efi -b efi.img -no-emul-boot .
cd ..
isohybrid $isohybrid_args boot-uefi.iso
}
if [ ! -e efi-syslinux ]
then
echo "efi-syslinux missing"
fi
echo -n "Enter your build directory: "
read build_directory
MKISOFS="${build_directory}/bitbake_build/tmp/sysroots/x86_64-linux/usr/bin/mkisofs"
echo "MKISOFS=$MKISOFS"
if [ ! -e $MKISOFS ]
then
echo "build_directory needed"
exit
fi
echo -n "Enter your sudo passwd: "
read -s sudo_passwd
mkdir -p mnt-64
mkdir -p efi-64
mkdir -p efi
echo
echo $sudo_passwd | sudo -Sk mount $build_directory/export/intel-x86-64-*-dist.iso mnt-64
echo $sudo_passwd | sudo -Sk mount mnt-64/efi.img efi-64
cp efi-64/* efi -rv
rm efi/EFI/BOOT/* -rf
chmod u+w efi-64 -R
cp efi-syslinux/* efi -rv
build_fat_img efi efi.img
mkdir -p new-iso
cp mnt-64/* new-iso -rv
chmod u+w new-iso -R
rm new-iso/EFI/BOOT/* -rf
cp efi-syslinux/EFI/BOOT/* new-iso/EFI/BOOT/ -rv
cp efi.img new-iso -v
build_iso
echo $sudo_passwd | sudo -Sk umount efi-64
echo $sudo_passwd | sudo -Sk umount mnt-64
rm -rf efi efi-64
rm -rf mnt-64 new-iso
rm efi.img
echo done!
#set +x