3
# lh_binary_usb-hdd(1) - build binary usb-hdd image
4
# Copyright (C) 2006-2009 Daniel Baumann <daniel@debian.org>
6
# live-helper 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.
12
# Including common functions
13
. "${LH_BASE:-/usr/share/live-helper}"/functions.sh
15
# Setting static variables
16
DESCRIPTION="$(Echo 'build binary image')"
18
USAGE="${PROGRAM} [--force]"
22
# Reading configuration files
23
Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
26
if ! In_list usb-hdd "${LH_BINARY_IMAGES}"
31
Echo_message "Begin building binary usb-hdd image..."
33
# Requiring stage file
34
Require_stagefile .stage/config .stage/bootstrap .stage/chroot_proc
37
Check_stagefile .stage/binary_usb-hdd
46
Check_package chroot/sbin/mkdosfs dosfstools
47
Check_package chroot/usr/share/doc/mtools mtools
48
Check_package chroot/sbin/parted parted
50
if [ "${LH_ARCHITECTURE}" = "sparc" ]
52
case "${LH_BINARY_FILESYSTEM}" in
54
Check_package chroot/sbin/mkfs.ext2 e2fsprogs
58
Echo_error "Sparc only supports booting from ext2, ext3 (or ufs)"
64
case "${LH_BOOTLOADER}" in
66
Check_package chroot/usr/sbin/grub grub
70
Check_package chroot/usr/bin/syslinux syslinux
75
Restore_cache cache/packages_binary
86
# Enforce fat32 if we find individual files bigger than 2GB
87
if [ "${LH_BINARY_FILESYSTEM}" = "fat16" ] && [ -n "$(find binary -size +1999M)" ]
89
Echo_warning "FAT16 doesn't support files larger than 2GB, automatically enforcing FAT32."
91
LH_BINARY_FILESYSTEM="fat32"
92
export LH_BINARY_FILESYSTEM
95
# Enforce fat32 if we have images in total bigger than 2GB
96
if [ "${LH_BINARY_FILESYSTEM}" = "fat16" ] && [ "$(du -s binary | awk '{ print $1 }')" -gt "1900000" ]
98
Echo_warning "FAT16 doesn't support partitions larger than 2GB, automatically enforcing FAT32"
100
LH_BINARY_FILESYSTEM="fat32"
101
export LH_BINARY_FILESYSTEM
104
# Everything which comes here needs to be cleaned up,
105
DU_DIM="$(du -ms binary | cut -f1)"
106
REAL_DIM="$(Calculate_partition_size ${DU_DIM} ${LH_BINARY_FILESYSTEM})"
107
dd if=/dev/zero of=chroot/binary.img bs=1024k count=0 seek=${REAL_DIM}
108
FREELO="$(${LH_LOSETUP} -f)"
109
if [ ! -b chroot/${FREELO} ]
113
mv chroot/dev chroot/dev.tmp
114
find /dev | cpio -dmpu chroot
117
echo "!!! The following error/warning messages can be ignored !!!"
118
Losetup $FREELO chroot/binary.img 0
120
case "${LH_ARCHITECTURE}" in
122
PARTITION_TABLE_TYPE="sun"
125
PARTITION_TABLE_TYPE="msdos"
129
case "${LH_BINARY_FILESYSTEM}" in
131
PARTITION_TYPE="ext2"
135
PARTITION_TYPE="${LH_BINARY_FILESYSTEM}"
139
Echo_error "Unsupported binary filesystem %s" "${LH_BINARY_FILESYSTEM}"
144
case "${LH_CHROOT_BUILD}" in
146
Chroot chroot "parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE}" || true
147
Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
148
Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
149
Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
151
if [ "${LH_BOOTLOADER}" = "syslinux" ]
153
dd if=chroot/usr/lib/syslinux/mbr.bin of=${FREELO} bs=440 count=1
158
parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE} || true
159
parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100% || true
160
parted -s ${FREELO} set 1 boot on || true
161
parted -s ${FREELO} set 1 lba off || true
163
if [ "${LH_BOOTLOADER}" = "syslinux" ]
165
dd if=/usr/lib/syslinux/mbr.bin of=${FREELO} bs=440 count=1
170
${LH_LOSETUP} -d ${FREELO}
172
FREELO="$(${LH_LOSETUP} -f)"
173
Losetup $FREELO chroot/binary.img 1
175
case "${LH_BINARY_FILESYSTEM}" in
177
MKFS="${LH_BINARY_FILESYSTEM}"
178
MKFS_OPTIONS="-L DEBIAN_LIVE -m 0"
183
MKFS_OPTIONS="-F 16 -n DEBIAN_LIVE"
188
MKFS_OPTIONS="-F 32 -n DEBIAN_LIVE"
192
case "${LH_CHROOT_BUILD}" in
194
Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
198
mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}
202
case "${LH_BINARY_FILESYSTEM}" in
208
mkdir -p chroot/binary.tmp
209
${LH_ROOT_COMMAND} mount ${FREELO} chroot/binary.tmp
210
cp -r -T ${CP_OPTIONS} binary/ chroot/binary.tmp
214
if [ "${LH_BOOTLOADER}" = "grub" ]
217
cat > chroot/grub.sh << EOF
224
rootpartition="$(Chroot chroot 'sh grub.sh' 2>/dev/null | grep -A 1 'find /live/vmlinuz' | grep -v 'find /live/vmlinuz')"
225
usbdev="$(echo $rootpartition | sed -e 's|,[[:digit:]]||')"
226
echo "Root partition is $rootpartition, device is: $usbdev"
228
echo "WAITING..." && read WAIT
230
#cat > chroot/grub.sh << EOF
237
#Chroot chroot "sh grub.sh"
243
${LH_ROOT_COMMAND} umount chroot/binary.tmp
244
rmdir chroot/binary.tmp
246
if [ "${LH_BOOTLOADER}" = "syslinux" ]
248
case "${LH_CHROOT_BUILD}" in
250
Chroot chroot "syslinux ${FREELO}"
259
${LH_LOSETUP} -d ${FREELO}
261
echo "!!! The above error/warning messages can be ignored !!!"
263
if [ -n "${MAKEDEV}" ]
266
mv chroot/dev.tmp chroot/dev
269
mv chroot/binary.img ./
272
Save_cache cache/packages_binary
277
# Creating stage file
278
Create_stagefile .stage/binary_usb-hdd