| 1 | #!/bin/bash |
| 2 | # Author: Steven Shiau <steven _at_ clonezilla org> |
| 3 | # License: GPL |
| 4 | # Description: DRBL utitilty to create files for PXELINUX clients. |
| 5 | # Load DRBL setting and functions |
| 6 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 7 | |
| 8 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 9 | |
| 10 | # Settings |
| 11 | # By default we put all the files for clients. |
| 12 | # If put pxelinux-related files (*.0, *.c32, *.efi...) only, set as "true" |
| 13 | put_pxelinux_related_only="false" |
| 14 | |
| 15 | USAGE() { |
| 16 | echo "Usage: $0 [OPTION]" |
| 17 | echo "OPTION" |
| 18 | language_help_prompt_by_idx_no |
| 19 | echo "-o, --console-output OPT: Set the console output parameters." |
| 20 | echo "-i, --pxe-serial-output OPT: Set the PXE menu to work with serial console output." |
| 21 | echo "-p, --only-pxelinux-related: Only put the PXELINUX related files. Skip the memtest, freedos, and not to create the PXELINUX boot menu file." |
| 22 | } |
| 23 | # |
| 24 | put_drbl_background_img() { |
| 25 | # the background img in pxelinux |
| 26 | if [ -f "$pxelinux_bg_img" ]; then |
| 27 | cp -af $pxelinux_bg_img $pxecfg_pd |
| 28 | else |
| 29 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 30 | echo "$msg_Warning! $pxelinux_bg_img $msg_NOT_found!!! $msg_PXE_NOT_work" |
| 31 | echo "$msg_press_enter_to_continue" |
| 32 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 33 | read |
| 34 | fi |
| 35 | } |
| 36 | # |
| 37 | put_pxelinux_multi_arch_files() { |
| 38 | # For those files will be copied to $pxecfg_pd/{bios,efi32,efi64} |
| 39 | for iarch in bios efi32 efi64; do |
| 40 | if [ -d "$pxelinux_binsrc_dir/$iarch" ]; then |
| 41 | cp -af $pxelinux_binsrc_dir/$iarch $pxecfg_pd/ |
| 42 | fi |
| 43 | done |
| 44 | # Move the files to appropriate path. |
| 45 | # pxelinux.0, gpxelinux.0, and lpxelinux.0 |
| 46 | mv $pxecfg_pd/bios/*pxelinux.0 $pxecfg_pd/ |
| 47 | if [ -e "$pxecfg_pd/bios/ldlinux.c32" ]; then |
| 48 | mv $pxecfg_pd/bios/ldlinux.c32 $pxecfg_pd/ldlinux.c32 |
| 49 | fi |
| 50 | if [ -e "$pxecfg_pd/efi32/ldlinux.e32" ]; then |
| 51 | mv $pxecfg_pd/efi32/ldlinux.e32 $pxecfg_pd/ldlinux.e32 |
| 52 | fi |
| 53 | if [ -e "$pxecfg_pd/efi32/syslinux.efi" ]; then |
| 54 | mv $pxecfg_pd/efi32/syslinux.efi $pxecfg_pd/bootia32.efi |
| 55 | echo "File copied from syslinux efi32/syslinux.efi" > $pxecfg_pd/bootia32.efi.info |
| 56 | fi |
| 57 | if [ -e "$pxecfg_pd/efi64/ldlinux.e64" ]; then |
| 58 | mv $pxecfg_pd/efi64/ldlinux.e64 $pxecfg_pd/ldlinux.e64 |
| 59 | fi |
| 60 | if [ -e "$pxecfg_pd/efi64/syslinux.efi" ]; then |
| 61 | mv $pxecfg_pd/efi64/syslinux.efi $pxecfg_pd/bootx64.efi |
| 62 | echo "File copied from syslinux efi64/syslinux.efi" > $pxecfg_pd/bootx64.efi.info |
| 63 | fi |
| 64 | } |
| 65 | # |
| 66 | put_pxelinux_memdisk() { |
| 67 | # memdisk, only for $pxecfg_pd/bios/ |
| 68 | if [ -f "$pxelinux_memdisk_file" ]; then |
| 69 | cp -af $pxelinux_memdisk_file $pxecfg_pd/ |
| 70 | else |
| 71 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 72 | echo "$msg_Warning! $pxelinux_memdisk_file $msg_NOT_found!!! $msg_PXE_NOT_work" |
| 73 | echo "$msg_press_enter_to_continue" |
| 74 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 75 | read |
| 76 | fi |
| 77 | } |
| 78 | # |
| 79 | link_pxelinux_bios_arch_files() { |
| 80 | # If only $pxecfg_pd/bios/, no $pxecfg_pd/{efi32,efi64}, we'd better to link files from $pxecfg_pd/bios/ to $pxecfg_pd/, otherwise for CentOS 5 with syslinux 4.x, the "PATH" option is not supported. |
| 81 | if [ -d $pxecfg_pd/bios -a \ |
| 82 | ! -d $pxecfg_pd/efi32 -a \ |
| 83 | ! -d $pxecfg_pd/efi64 ]; then |
| 84 | for i in $pxecfg_pd/bios/*; do |
| 85 | [ ! -e "$i" ] && continue |
| 86 | fn="$(basename $i)" |
| 87 | ( |
| 88 | ln -t $pxecfg_pd -fs bios/$fn |
| 89 | ) |
| 90 | done |
| 91 | fi |
| 92 | } |
| 93 | # |
| 94 | put_memtest86_img() { |
| 95 | # memtest86+ |
| 96 | # make a version tag in $pxecfg_pd |
| 97 | # Only for x86 |
| 98 | if [ "$(uname -m)" != "x86_64" ]; then |
| 99 | echo "Not x86-64 system. Skip putting memtest86." |
| 100 | return 3 |
| 101 | fi |
| 102 | echo "Copying memtest86+ to $pxecfg_pd..." |
| 103 | if [ -n "$(ls -l $memtest86_dir/mt86+x* 2>/dev/null)" ]; then |
| 104 | cp -af $memtest86_dir/mt86+x* $pxecfg_pd |
| 105 | cp -af $memtest86_dir/VERSION $pxecfg_pd/MEMTEST86+_VERSION |
| 106 | else |
| 107 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 108 | echo "$msg_Warning! $memtest86_dir/mt86+x* $msg_NOT_found!!!" |
| 109 | echo "$msg_press_enter_to_continue" |
| 110 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 111 | read |
| 112 | fi |
| 113 | } |
| 114 | # |
| 115 | put_etherboot_and_sis900_pxe() { |
| 116 | # This function is deprecated since we do not maintain drbl-etherboot package anymore. |
| 117 | # For etherboot PXE image (Especially necessary for sis900 NIC) |
| 118 | # clean the old ones |
| 119 | rm -f $pxecfg_pd/eb-*-etherboot-pci.zpxe $pxecfg_pd/sis900.zpxe |
| 120 | # get the all-in-one etherboot zpxe and sis900 zpxe filename, we use sort and head to choose only one. |
| 121 | etherboot_pxe="$($query_pkglist_cmd drbl-etherboot 2>/dev/null | grep -E "eb-.*-etherboot-pci.zpxe$")" |
| 122 | [ -e "$etherboot_pxe" ] && cp -af $etherboot_pxe $pxecfg_pd/ |
| 123 | |
| 124 | sis900_pxe="$($query_pkglist_cmd drbl-etherboot 2>/dev/null | grep -E "sis900.zpxe$")" |
| 125 | [ -e "$sis900_pxe" ] && cp -af $sis900_pxe $pxecfg_pd/ |
| 126 | } |
| 127 | # |
| 128 | put_free_dos_img() { |
| 129 | # create the freedos image, which a clean one. |
| 130 | # if user wants to insert files, use |
| 131 | # the script insert-file-fdos.sh |
| 132 | # [ -f kernel.sys ] && rm -f kernel.sys |
| 133 | if [ -f "$fdos_img_src" ]; then |
| 134 | # 2005/4/4 since etherboot 5.4.0 is released, no more NBI. |
| 135 | # img_mt=`mktemp -d fdos_img.XXXXXX` |
| 136 | # mount -t vfat -o loop $fdos_img_src $img_mt |
| 137 | # cp -f $img_mt/kernel.sys . |
| 138 | # umount $img_mt |
| 139 | # mknbi-fdos --output=/tftpboot/nbi_img/$fdos_nbi_output kernel.sys $fdos_img_src |
| 140 | echo "Copying FreeDOS files to $pxecfg_pd/... " |
| 141 | cp -f $fdos_img_src $pxecfg_pd/$fdos_img_output |
| 142 | # [ -d "$img_mt" ] && rm -rf $img_mt |
| 143 | # clean the unnecessary file |
| 144 | # [ -f kernel.sys ] && rm -f kernel.sys |
| 145 | else |
| 146 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 147 | echo "$msg_Warning! $fdos_img_src $msg_NOT_found!!! $msg_FreeDOS_NOT_work" |
| 148 | echo "$msg_press_enter_to_continue" |
| 149 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 150 | fi |
| 151 | } |
| 152 | # |
| 153 | gen_pxe_boot_menu() { |
| 154 | # create the pxelinux default |
| 155 | if [ -n "$CONSOLE_OUTPUT" ]; then |
| 156 | console_opt1="--console" |
| 157 | console_opt2="$CONSOLE_OUTPUT" |
| 158 | fi |
| 159 | if [ -n "$PXE_SERIAL_OUTPUT" ]; then |
| 160 | pxe_serial_opt1="--serial" |
| 161 | pxe_serial_opt2="$PXE_SERIAL_OUTPUT" |
| 162 | fi |
| 163 | generate-pxe-menu $console_opt1 "$console_opt2" $pxe_serial_opt1 "$pxe_serial_opt2" |
| 164 | } |
| 165 | |
| 166 | # Parse command-line options |
| 167 | while [ $# -gt 0 ]; do |
| 168 | case "$1" in |
| 169 | -l|--language) |
| 170 | shift |
| 171 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 172 | # skip the -xx option, in case |
| 173 | specified_lang="$1" |
| 174 | shift |
| 175 | fi |
| 176 | [ -z "$specified_lang" ] && USAGE && exit 1 |
| 177 | ;; |
| 178 | -o|--console-output) |
| 179 | shift |
| 180 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 181 | # skip the -xx option, in case |
| 182 | CONSOLE_OUTPUT="$1" |
| 183 | shift |
| 184 | fi |
| 185 | [ -z "$CONSOLE_OUTPUT" ] && USAGE && exit 1 |
| 186 | ;; |
| 187 | -i|--pxe-serial-output) |
| 188 | shift |
| 189 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
| 190 | # skip the -xx option, in case |
| 191 | PXE_SERIAL_OUTPUT="$1" |
| 192 | shift |
| 193 | fi |
| 194 | [ -z "$PXE_SERIAL_OUTPUT" ] && USAGE && exit 1 |
| 195 | ;; |
| 196 | -p|--only-pxelinux-related) |
| 197 | shift |
| 198 | put_pxelinux_related_only="true" |
| 199 | ;; |
| 200 | -*) echo "${0}: ${1}: invalid option" >&2 |
| 201 | USAGE >& 2 |
| 202 | exit 2 ;; |
| 203 | *) break ;; |
| 204 | esac |
| 205 | done |
| 206 | |
| 207 | # |
| 208 | check_if_root |
| 209 | |
| 210 | # |
| 211 | ask_and_load_lang_set $specified_lang |
| 212 | |
| 213 | echo "Copying pxelinux.0, gpxelinux.0, menu.c32, vesamenu.c32, chain.c32, mboot.c32, sanboot.c32 and memdisk to $pxecfg_pd..." |
| 214 | |
| 215 | [ ! -d $pxecfg_pd/pxelinux.cfg ] && mkdir -p $pxecfg_pd/pxelinux.cfg |
| 216 | |
| 217 | # make a version tag in $pxecfg_pd |
| 218 | cp -af $pxelinux_binsrc_dir/VERSION $pxecfg_pd/PXELINUX_VERSION |
| 219 | |
| 220 | # These files (pxelinux.0, gpxelinux.0, menu.c32, vesamenu.c32, chain.c32, memdisk...) are very important. |
| 221 | # Hence we process here separately. |
| 222 | |
| 223 | if [ "$put_pxelinux_related_only" = "true" ]; then |
| 224 | put_pxelinux_multi_arch_files |
| 225 | link_pxelinux_bios_arch_files |
| 226 | put_pxelinux_memdisk |
| 227 | else |
| 228 | put_drbl_background_img |
| 229 | put_memtest86_img |
| 230 | put_etherboot_and_sis900_pxe |
| 231 | put_free_dos_img |
| 232 | # |
| 233 | put_pxelinux_multi_arch_files |
| 234 | link_pxelinux_bios_arch_files |
| 235 | put_pxelinux_memdisk |
| 236 | # |
| 237 | gen_pxe_boot_menu |
| 238 | fi |
| 239 | |
| 240 | ### Deal with GRUB EFI NB ### |
| 241 | # //NOTE// This will overwrite the bootx64.efi and bootia32.efi |
| 242 | # from syslinux in the previous steps. i.e. now we force to use |
| 243 | # that from grub2 because it's more mature than syslinux 6.03. |
| 244 | drbl-gen-grub-efi-nb |