source: live-build/trunk/fuentes/scripts/build/lb_binary_hdd @ 900

Last change on this file since 900 was 900, checked in by kbut, 3 years ago

add original source

  • Property svn:executable set to *
File size: 6.5 KB
Line 
1#!/bin/sh
2
3## live-build(7) - System Build Scripts
4## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
5##
6## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7## This is free software, and you are welcome to redistribute it
8## under certain conditions; see COPYING for details.
9
10
11set -e
12
13# Including common functions
14( . "${LIVE_BUILD}/scripts/build.sh" > /dev/null 2>&1 || true ) || . /usr/lib/live/build.sh
15
16# Setting static variables
17DESCRIPTION="$(Echo 'build binary image')"
18HELP=""
19USAGE="${PROGRAM} [--force]"
20
21Arguments "${@}"
22
23# Reading configuration files
24Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
25Set_defaults
26
27if ! In_list hdd "${LB_BINARY_IMAGES}"
28then
29        exit 0
30fi
31
32Echo_message "Begin building binary hdd image..."
33
34# Requiring stage file
35Require_stagefile .build/config .build/bootstrap .build/chroot_proc
36
37# Checking stage file
38Check_stagefile .build/binary_hdd
39
40# Checking lock file
41Check_lockfile .lock
42
43# Creating lock file
44Create_lockfile .lock
45
46# Checking depends
47case "${LB_BINARY_FILESYSTEM}" in
48        fat*)
49                Check_package chroot/sbin/mkdosfs dosfstools
50                ;;
51
52        ntfs)
53                case "${LB_PARENT_DISTRIBUTION}" in
54                        squeeze)
55                                Check_package chroot/sbin/mkfs.ntfs ntfsprogs
56                                ;;
57
58                        *)
59                                Check_package chroot/sbin/mkfs.nfts ntfs-3g
60                                ;;
61                esac
62                ;;
63esac
64
65Check_package chroot/usr/share/doc/mtools mtools
66Check_package chroot/sbin/parted parted
67
68if [ "${LB_ARCHITECTURES}" = "sparc" ]
69then
70        case "${LB_BINARY_FILESYSTEM}" in
71                ext2|ext3|ext4)
72                        Check_package chroot/sbin/mkfs.${LB_BINARY_FILESYSTEM} e2fsprogs
73                        ;;
74
75                *)
76                        Echo_error "Sparc only supports booting from ext2, ext3, ext4 or ufs."
77                        exit 1
78                        ;;
79        esac
80fi
81
82case "${LB_BOOTLOADER}" in
83        grub)
84                Check_package chroot/usr/sbin/grub grub
85                ;;
86
87        syslinux)
88                Check_package chroot/usr/bin/syslinux syslinux
89                ;;
90esac
91
92# Restoring cache
93Restore_cache cache/packages.binary
94
95# Installing depends
96Install_package
97
98# Remove old binary
99if [ -f binary.img ]
100then
101        rm -f binary.img
102fi
103
104# Enforce fat32 if we find individual files bigger than 2GB
105if [ "${LB_BINARY_FILESYSTEM}" = "fat16" ] && [ -n "$(find binary -size +1999M)" ]
106then
107        Echo_warning "FAT16 doesn't support files larger than 2GB, automatically enforcing FAT32."
108
109        LB_BINARY_FILESYSTEM="fat32"
110        export LB_BINARY_FILESYSTEM
111fi
112
113# Enforce fat32 if we have images in total bigger than 2GB
114if [ "${LB_BINARY_FILESYSTEM}" = "fat16" ] && [ "$(du -s binary | awk '{ print $1 }')" -gt "1900000" ]
115then
116        Echo_warning "FAT16 doesn't support partitions larger than 2GB, automatically enforcing FAT32"
117
118        LB_BINARY_FILESYSTEM="fat32"
119        export LB_BINARY_FILESYSTEM
120fi
121
122# Enforce ntfs if we find individual files bigger than 4GB
123if [ "${LB_BINARY_FILESYSTEM}" = "fat32" ] && [ -n "$(find binary -size +3999M)" ]
124then
125        Echo_warning "FAT32 doesn't support files larger than 4GB, automatically enforcing NTFS."
126
127        LB_BINARY_FILESYSTEM="ntfs"
128        export LB_BINARY_FILESYSTEM
129fi
130
131# Everything which comes here needs to be cleaned up,
132DU_DIM="$(du -ms binary | cut -f1)"
133REAL_DIM="$(Calculate_partition_size ${DU_DIM} ${LB_BINARY_FILESYSTEM})"
134dd if=/dev/zero of=chroot/binary.img bs=1024k count=0 seek=${REAL_DIM}
135FREELO="$(${LB_LOSETUP} -f)"
136if [ ! -b chroot/${FREELO} ]
137then
138        MAKEDEV="true"
139
140        mv chroot/dev chroot/dev.tmp
141        find /dev | cpio -dmpu chroot
142fi
143
144echo "!!! The following error/warning messages can be ignored !!!"
145Losetup $FREELO chroot/binary.img 0
146
147case "${LB_ARCHITECTURES}" in
148        sparc)
149                PARTITION_TABLE_TYPE="sun"
150                ;;
151        *)
152                PARTITION_TABLE_TYPE="msdos"
153                ;;
154esac
155
156case "${LB_BINARY_FILESYSTEM}" in
157        ext2|ext3|ext4)
158                PARTITION_TYPE="ext2"
159                ;;
160
161        fat16|fat32)
162                PARTITION_TYPE="${LB_BINARY_FILESYSTEM}"
163                ;;
164
165        ntfs)
166                PARTITION_TYPE="NTFS"
167                ;;
168
169        *)
170                Echo_error "Unsupported binary filesystem %s" "${LB_BINARY_FILESYSTEM}"
171                exit 1
172                ;;
173esac
174
175case "${LB_BUILD_WITH_CHROOT}" in
176        true)
177                Chroot chroot "parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE}" || true
178                Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
179                Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
180                Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
181
182                if [ "${LB_BOOTLOADER}" = "syslinux" ]
183                then
184                        dd if=chroot/usr/lib/syslinux/mbr.bin of=${FREELO} bs=440 count=1
185                fi
186                ;;
187
188        false)
189                parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE} || true
190                parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100% || true
191                parted -s "${FREELO}" set 1 boot on || true
192                parted -s "${FREELO}" set 1 lba off || true
193
194                if [ "${LB_BOOTLOADER}" = "syslinux" ]
195                then
196                        dd if=/usr/lib/syslinux/mbr.bin of=${FREELO} bs=440 count=1
197                fi
198                ;;
199esac
200
201Lodetach ${FREELO}
202
203FREELO="$(${LB_LOSETUP} -f)"
204Losetup $FREELO chroot/binary.img 1
205
206case "${LB_BINARY_FILESYSTEM}" in
207        ext2|ext3|ext4)
208                MKFS="${LB_BINARY_FILESYSTEM}"
209                MKFS_OPTIONS="-L ${LB_HDD_LABEL} -m 0"
210                ;;
211
212        fat16)
213                MKFS="vfat"
214                MKFS_OPTIONS="-F 16 -n ${LB_HDD_LABEL}"
215                ;;
216
217        fat32)
218                MKFS="vfat"
219                MKFS_OPTIONS="-F 32 -n ${LB_HDD_LABEL}"
220                ;;
221
222        ntfs)
223                MKFS="ntfs"
224                MKFS_OPTIONS="-L ${LB_HDD_LABEL}"
225                ;;
226esac
227
228case "${LB_BUILD_WITH_CHROOT}" in
229        true)
230                Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
231                ;;
232
233        false)
234                mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}
235                ;;
236esac
237
238case "${LB_BINARY_FILESYSTEM}" in
239        fat*)
240                CP_OPTIONS="-L"
241                ;;
242esac
243
244mkdir -p chroot/binary.tmp
245${LB_ROOT_COMMAND} mount ${FREELO} chroot/binary.tmp
246cp -r -T ${CP_OPTIONS} binary/ chroot/binary.tmp
247
248FIXME()
249{
250if [ "${LB_BOOTLOADER}" = "grub" ]
251then
252
253cat > chroot/grub.sh << EOF
254cd binary.tmp
255grub --batch << EOM
256find /live/vmlinuz
257EOM
258EOF
259
260        rootpartition="$(Chroot chroot 'sh grub.sh' 2>/dev/null | grep -A 1 'find /live/vmlinuz' | grep -v 'find /live/vmlinuz')"
261        hdddev="$(echo $rootpartition | sed -e 's|,[[:digit:]]||')"
262        echo "Root partition is $rootpartition, device is: $hdddev"
263
264        echo "WAITING..." && read WAIT
265
266#cat > chroot/grub.sh << EOF
267#grub --batch << EOM
268#root $rootpartition
269#setup $hdddev
270#EOM
271#EOF
272
273#Chroot chroot "sh grub.sh"
274
275        rm -f chroot/grub.sh
276fi
277}
278
279${LB_ROOT_COMMAND} umount chroot/binary.tmp
280rmdir chroot/binary.tmp
281
282if [ "${LB_BOOTLOADER}" = "syslinux" ]
283then
284        case "${LB_BUILD_WITH_CHROOT}" in
285                true)
286                        Chroot chroot "syslinux ${FREELO}"
287                        ;;
288
289                false)
290                        syslinux ${FREELO}
291                        ;;
292        esac
293fi
294
295Lodetach ${FREELO}
296
297echo "!!! The above error/warning messages can be ignored !!!"
298
299if [ -n "${MAKEDEV}" ]
300then
301        rm -rf chroot/dev
302        mv chroot/dev.tmp chroot/dev
303fi
304
305mv chroot/binary.img ./
306
307# Saving cache
308Save_cache cache/packages.binary
309
310# Removing depends
311Remove_package
312
313# Creating stage file
314Create_stagefile .build/binary_hdd
Note: See TracBrowser for help on using the repository browser.