#!/bin/bash ################################################################################ # This file is part of OpenELEC - http://www.openelec.tv # Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv) # # OpenELEC is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # OpenELEC is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenELEC. If not, see . ################################################################################ . config/options $1 $SCRIPTS/build syslinux:host # set variables UUID_SYSTEM=$(uuidgen) UUID_STORAGE=$(uuidgen) OE_TMP=$(mktemp -d) LOOP=$(losetup -f) SYSTEM_SIZE=256 STORAGE_SIZE=32 # STORAGE_SIZE must be >= 32 ! DISK_SIZE=$(( $SYSTEM_SIZE + $STORAGE_SIZE )) DISK="$TARGET_IMG/$IMAGE_NAME.img" # functions cleanup() { echo "image: cleanup..." sudo umount "$OE_TMP" &>/dev/null || : sudo losetup -d "$LOOP" [ -f "$OE_TMP/ldlinux.sys" ] && sudo chattr -i "$OE_TMP/ldlinux.sys" || : sudo rm -rf "$OE_TMP" exit } trap cleanup SIGINT # ensure loopX not in use sudo umount "$OE_TMP" &>/dev/null || : sudo umount "$LOOP" &>/dev/null >/dev/null || : sudo losetup -d "$LOOP" &>/dev/null >/dev/null || : # create an image echo "image: creating image: $DISK..." dd if=/dev/zero of="$DISK" bs=1M count="$DISK_SIZE" sync # write a disklabel echo "image: creating partition table on $DISK..." sudo losetup "$LOOP" "$DISK" sudo parted -s "$LOOP" mklabel msdos sync # create part1 echo "image: creating part1 on $DISK..." SYSTEM_PART_END=$(( $SYSTEM_SIZE * 1024 * 1024 / 512 + 64 )) sudo parted -s "$LOOP" -a min unit s mkpart primary ext4 64 $SYSTEM_PART_END sudo parted -s "$LOOP" set 1 boot on # create part2 echo "image: creating part2 on $DISK..." STORAGE_PART_START=$(( $SYSTEM_PART_END + 1 )) sudo parted -s "$LOOP" -a min unit s mkpart primary ext4 $STORAGE_PART_START 100% sync # write mbr echo "image: writing mbr..." MBR="$ROOT/$TOOLCHAIN/share/syslinux/mbr.bin" if [ -n "$MBR" ]; then sudo dd bs=440 count=1 conv=notrunc if="$MBR" of="$LOOP" fi sync # create filesystem on part1 sudo losetup -d "$LOOP" echo "image: creating filesystem on part1..." OFFSET=$(( 64 * 512 )) SIZELIMIT=$(( $SYSTEM_SIZE * 1024 * 1024 )) sudo losetup -o $OFFSET --sizelimit $SIZELIMIT "$LOOP" "$DISK" sudo mke2fs -q -t ext4 -m 0 "$LOOP" sudo tune2fs -U $UUID_SYSTEM "$LOOP" sudo e2fsck -n "$LOOP" sync # mount partition echo "image: mounting part1 on $OE_TMP..." sudo mount "$LOOP" "$OE_TMP" # create bootloader configuration echo "image: creating bootloader configuration..." # cat >"$OE_TMP"/syslinux.cfg << EOF cat << EOF | sudo tee "$OE_TMP"/syslinux.cfg UI vesamenu.c32 PROMPT 0 MENU TITLE Boot Menu MENU BACKGROUND splash.png TIMEOUT 50 DEFAULT live MENU WIDTH 70 MENU MARGIN 15 MENU ROWS 2 MENU HSHIFT 4 MENU VSHIFT 13 MENU TIMEOUTROW 10 MENU TABMSGROW 8 MENU CMDLINEROW 8 MENU HELPMSGROW 13 MENU HELPMSGENDROW 26 MENU CLEAR MENU COLOR border 30;44 #40ffffff #00000000 std MENU COLOR title 1;36;44 #ff8bbfe3 #00000000 std MENU COLOR sel 7;37;40 #80f0f0f0 #ff606060 all MENU COLOR unsel 37;44 #50ffffff #00000000 std MENU COLOR help 37;40 #c0ffffff #a0000000 std MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std MENU COLOR msg07 37;40 #90ffffff #a0000000 std MENU COLOR tabmsg 31;40 #ff868787 #00000000 std LABEL installer MENU LABEL Run $DISTRONAME Installer KERNEL /KERNEL APPEND boot=UUID=$UUID_SYSTEM installer quiet tty vga=current LABEL live MENU LABEL Run $DISTRONAME Live KERNEL /KERNEL APPEND boot=UUID=$UUID_SYSTEM disk=UUID=$UUID_STORAGE quiet vga=current EOF # install extlinux echo "image: installing extlinux to part1..." sudo $ROOT/$TOOLCHAIN/bin/extlinux --heads=4 --sector=32 -i "$OE_TMP" # copy files echo "image: copying files to part1..." sudo cp $TARGET_IMG/$IMAGE_NAME.kernel "$OE_TMP/KERNEL" sudo cp $TARGET_IMG/$IMAGE_NAME.system "$OE_TMP/SYSTEM" sudo cp $RELEASE_DIR/splash.png "$OE_TMP" sudo cp $ROOT/$TOOLCHAIN/share/syslinux/vesamenu.c32 "$OE_TMP" sudo cp $ROOT/$TOOLCHAIN/share/syslinux/libcom32.c32 "$OE_TMP" sudo cp $ROOT/$TOOLCHAIN/share/syslinux/libutil.c32 "$OE_TMP" # unmount part1 echo "image: unmounting part1..." sync sudo umount "$LOOP" # create filesystem on part2 sudo losetup -d "$LOOP" echo "image: creating filesystem on part2..." OFFSET=$(( $STORAGE_PART_START * 512 )) sudo losetup -o $OFFSET "$LOOP" "$DISK" sudo mke2fs -q -t ext4 -m 0 "$LOOP" sudo tune2fs -U $UUID_STORAGE "$LOOP" sudo e2fsck -n "$LOOP" sync echo "image: mounting part2 on $OE_TMP..." sudo mount "$LOOP" "$OE_TMP" sudo touch "$OE_TMP/.please_resize_me" # unmount part2 echo "image: unmounting part2..." sync sudo umount "$LOOP" # gzip echo "image: compressing..." gzip $DISK # cleanup cleanup