util-iso-boot.sh 3.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash
#
# This program 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; version 2 of the License.
#
# This program 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.

udeved's avatar
udeved committed
12
prepare_initcpio(){
udeved's avatar
udeved committed
13
    msg2 "Copying initcpio ..."
14 15 16
    cp /etc/initcpio/hooks/miso* $1/etc/initcpio/hooks
    cp /etc/initcpio/install/miso* $1/etc/initcpio/install
    cp /etc/initcpio/miso_shutdown $1/etc/initcpio
17 18
}

19
prepare_initramfs(){
artoo's avatar
artoo committed
20 21
    cp ${DATADIR}/mkinitcpio.conf $1/etc/mkinitcpio-${iso_name}.conf
    local _kernver=$(cat $1/usr/lib/modules/*/version)
udeved's avatar
udeved committed
22 23 24 25
    if [[ -n ${gpgkey} ]]; then
        su ${OWNER} -c "gpg --export ${gpgkey} >${USERCONFDIR}/gpgkey"
        exec 17<>${USERCONFDIR}/gpgkey
    fi
artoo's avatar
artoo committed
26
    MISO_GNUPG_FD=${gpgkey:+17} chroot-run $1 \
udeved's avatar
udeved committed
27 28
        /usr/bin/mkinitcpio -k ${_kernver} \
        -c /etc/mkinitcpio-${iso_name}.conf \
udeved's avatar
udeved committed
29
        -g /boot/initramfs.img
udeved's avatar
udeved committed
30 31 32 33

    if [[ -n ${gpgkey} ]]; then
        exec 17<&-
    fi
34 35 36
    if [[ -f ${USERCONFDIR}/gpgkey ]]; then
        rm ${USERCONFDIR}/gpgkey
    fi
37 38
}

39
prepare_boot_extras(){
40
    cp $1/boot/amd-ucode.img $2/amd_ucode.img
udeved's avatar
udeved committed
41
    cp $1/boot/intel-ucode.img $2/intel_ucode.img
42
    cp $1/usr/share/licenses/amd-ucode/LICENSE $2/amd_ucode.LICENSE
udeved's avatar
udeved committed
43
    cp $1/usr/share/licenses/intel-ucode/LICENSE $2/intel_ucode.LICENSE
udeved's avatar
udeved committed
44 45
    cp $1/boot/memtest86+/memtest.bin $2/memtest
    cp $1/usr/share/licenses/common/GPL2/license.txt $2/memtest.COPYING
46 47
}

artoo's avatar
artoo committed
48
prepare_grub(){
49
    local platform=i386-pc img='core.img' grub=$2/boot/grub efi=$2/efi/boot \
50 51
        data_live=$1/usr/share/grub lib=usr/lib/grub prefix=/boot/grub data=/usr/share/grub \
        path="${work_dir}/rootfs"
52

53
    prepare_dir ${grub}/${platform}
54

artoo's avatar
artoo committed
55
    cp ${data_live}/cfg/*.cfg ${grub}
56

57
    cp ${path}/${lib}/${platform}/* ${grub}/${platform}
58

59
    msg2 "Building %s ..." "${img}"
60

61
    grub-mkimage -d ${grub}/${platform} -o ${grub}/${platform}/${img} -O ${platform} -p ${prefix} biosdisk iso9660
62

63
    cat ${grub}/${platform}/cdboot.img ${grub}/${platform}/${img} > ${grub}/${platform}/eltorito.img
64 65 66

    case ${target_arch} in
        'i686')
67 68
            platform=i386-efi
            img=bootia32.efi
artoo's avatar
artoo committed
69 70
        ;;
        'x86_64')
71 72
            platform=x86_64-efi
            img=bootx64.efi
artoo's avatar
artoo committed
73 74
        ;;
    esac
75

artoo's avatar
artoo committed
76
    prepare_dir ${efi}
77
    prepare_dir ${grub}/${platform}
78

79
    cp ${path}/${lib}/${platform}/* ${grub}/${platform}
80

81
    msg2 "Building %s ..." "${img}"
82

83
    grub-mkimage -d ${grub}/${platform} -o ${efi}/${img} -O ${platform} -p ${prefix} iso9660
84

artoo's avatar
artoo committed
85
    prepare_dir ${grub}/themes
artoo's avatar
artoo committed
86
    cp -r ${data_live}/themes/${iso_name}-live ${grub}/themes/
artoo's avatar
artoo committed
87
    cp ${data}/unicode.pf2 ${grub}
artoo's avatar
artoo committed
88
    cp -r ${data_live}/{locales,tz} ${grub}
89

90 91 92
    msg2 "Set menu_show_once=1 in '${grub}/grubenv'"
    grub-editenv ${grub}/grubenv set menu_show_once=1

artoo's avatar
artoo committed
93
    local size=4M mnt="${mnt_dir}/efiboot" efi_img="$2/efi.img"
artoo's avatar
artoo committed
94
    msg2 "Creating fat image of %s ..." "${size}"
95 96 97
    truncate -s ${size} "${efi_img}"
    mkfs.fat -n MISO_EFI "${efi_img}" &>/dev/null
    prepare_dir "${mnt}"
98
    mount_img "${efi_img}" "${mnt}"
artoo's avatar
artoo committed
99
    prepare_dir ${mnt}/efi/boot
100
    msg2 "Building %s ..." "${img}"
101
    grub-mkimage -d ${grub}/${platform} -o ${mnt}/efi/boot/${img} -O ${platform} -p ${prefix} iso9660
artoo's avatar
artoo committed
102
    umount_img "${mnt}"
103
}