aboutsummaryrefslogtreecommitdiff
path: root/kolla/docker/ironic/ironic-pxe/extend_start.sh
blob: 8e4d633076d4ac0ead70f9d1fa2dd73b8d88b7d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash


# For x86 legacy BIOS boot mode
function prepare_pxe_pxelinux {
    if [[ "${KOLLA_BASE_DISTRO}" =~ debian|ubuntu ]]; then
        cp /usr/lib/PXELINUX/pxelinux.0 \
           /usr/lib/syslinux/modules/bios/{chain.c32,ldlinux.c32} \
           ${TFTPBOOT_PATH}/
    elif [[ "${KOLLA_BASE_DISTRO}" =~ centos|rocky ]]; then
        if [[ "${TFTPBOOT_PATH}" != /tftpboot ]]; then
            cp /tftpboot/{pxelinux.0,chain.c32,ldlinux.c32} \
               ${TFTPBOOT_PATH}/
        fi
    fi
}

# For UEFI boot mode
function prepare_pxe_grub {
    if [[ "${KOLLA_BASE_DISTRO}" =~ debian|ubuntu  ]]; then
        shim_src_file="/usr/lib/shim/shim*64.efi.signed"
        grub_src_file="/usr/lib/grub/*-efi-signed/grubnet*64.efi.signed"
    elif [[ "${KOLLA_BASE_DISTRO}" =~ centos|rocky ]]; then
        shim_src_file="/boot/efi/EFI/${KOLLA_BASE_DISTRO}/shim*64.efi"
        grub_src_file="/boot/efi/EFI/${KOLLA_BASE_DISTRO}/grub*64.efi"
    fi

    if [[ "${KOLLA_BASE_ARCH}" == "x86_64" ]]; then
        shim_dst_file="bootx64.efi"
        grub_dst_file="grubx64.efi"
    elif [[ "${KOLLA_BASE_ARCH}" == "aarch64" ]]; then
        shim_dst_file="bootaa64.efi"
        grub_dst_file="grubaa64.efi"
    fi

    cp $shim_src_file ${TFTPBOOT_PATH}/$shim_dst_file
    cp $grub_src_file ${TFTPBOOT_PATH}/$grub_dst_file
}

function prepare_ipxe {
    # NOTE(mgoddard): Ironic uses snponly.efi as the default for
    # uefi_ipxe_bootfile_name since Xena. In Wallaby and earlier releases it
    # was ipxe.efi. Ensure that both exist, using symlinks where the files are
    # named differently to allow the original names to be used in ironic.conf.
    if [[ "${KOLLA_BASE_DISTRO}" =~ debian|ubuntu ]]; then
        # NOTE(m-anson): ipxe-arm64.efi is not symlinked from /boot to
        # /usr/lib/ipxe by the Ubuntu ipxe package, so fix that here.
        if [[ -e /boot/ipxe-arm64.efi ]]; then
            ln -sf /boot/ipxe-arm64.efi /usr/lib/ipxe/
        fi
        cp /usr/lib/ipxe/{undionly.kpxe,ipxe*.efi,snponly.efi} ${TFTPBOOT_PATH}/
    elif [[ "${KOLLA_BASE_DISTRO}" =~ centos|rocky ]]; then
        cp /usr/share/ipxe/{undionly.kpxe,ipxe-snponly-x86_64.efi} ${TFTPBOOT_PATH}/
        cp /usr/share/ipxe/arm64-efi/snponly.efi ${TFTPBOOT_PATH}/ipxe-snponly-aarch64.efi
        ln -sf ${TFTPBOOT_PATH}/ipxe-snponly-${KOLLA_BASE_ARCH}.efi ${TFTPBOOT_PATH}/snponly.efi
    fi
}

function prepare_esp_image {
    # NOTE(bbezak): based on https://docs.openstack.org/ironic/2024.2/install/configure-esp.html
    # ESP image needs to be provided for UEFI boot with virtual media:
    # https://docs.openstack.org/ironic/2024.2/admin/drivers/redfish.html#virtual-media-boot
    if [[ "${KOLLA_BASE_DISTRO}" =~ debian|ubuntu ]]; then
        shim_src_file="/usr/lib/shim/shim*64.efi.signed"
        grub_src_file="/usr/lib/grub/*-efi-signed/grubnet*64.efi.signed"
    elif [[ "${KOLLA_BASE_DISTRO}" =~ centos|rocky ]]; then
        shim_src_file="/boot/efi/EFI/${KOLLA_BASE_DISTRO}/shim*64.efi"
        grub_src_file="/boot/efi/EFI/${KOLLA_BASE_DISTRO}/grub*64.efi"
    fi

    if [[ "${KOLLA_BASE_ARCH}" == "x86_64" ]]; then
        shim_dst_file="bootx64.efi"
        grub_dst_file="grubx64.efi"
    elif [[ "${KOLLA_BASE_ARCH}" == "aarch64" ]]; then
        shim_dst_file="bootaa64.efi"
        grub_dst_file="grubaa64.efi"
    fi

    DEST=${HTTPBOOT_PATH}/esp.img
    dd if=/dev/zero of=$DEST bs=4096 count=2048
    mkfs.msdos -F 12 -n ESP_IMAGE $DEST
    mmd -i $DEST EFI EFI/BOOT
    mcopy -i $DEST -v $shim_src_file ::EFI/BOOT/$shim_dst_file
    mcopy -i $DEST -v $grub_src_file ::EFI/BOOT/$grub_dst_file
    mdir -i $DEST ::EFI/BOOT
}

# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
# of the KOLLA_BOOTSTRAP variable being set, including empty.
if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
    mkdir -p ${TFTPBOOT_PATH} ${HTTPBOOT_PATH}
    chown ironic: ${TFTPBOOT_PATH} ${HTTPBOOT_PATH}
    prepare_pxe_pxelinux
    prepare_pxe_grub
    prepare_ipxe
    prepare_esp_image
    exit 0
fi

# Template out a TFTP map file, using the TFTPBOOT_PATH variable.
envsubst < /map-file-template > /map-file