Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archiso/hooks/archiso_pxe_nbd
blob: 07e6fee4b0678a5a34cb78286e34af2612221d1a (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
# vim: set ft=sh:

run_hook() {
    if [[ -n "${ip}" ]]; then
        [[ -z "${archiso_nbd_name}" ]] && archiso_nbd_name="archiso"
        [[ -z "${archiso_nbd_srv}" ]] && archiso_nbd_srv="${pxeserver}"

        mount_handler="archiso_pxe_nbd_mount_handler"
    fi
}

archiso_pxe_nbd_mount_handler () {
    newroot="${1}"

    # Module autoloading like with loop devices does not work, doing manually...
    modprobe nbd 2> /dev/null
    msg ":: Waiting for boot device..."
    while ! poll_device /dev/nbd0 30; do
        echo "ERROR: boot device didn't show up after 30 seconds..."
        echo "   Falling back to interactive prompt"
        echo "   You can try to fix the problem manually, log out when you are finished"
        launch_interactive_shell
    done

    msg ":: Setup NBD from ${archiso_nbd_srv} at /dev/nbd0"
    if [[ "${copytoram}" = "y" ]]; then
        nbd-client ${archiso_nbd_srv} -N ${archiso_nbd_name} /dev/nbd0
    else
        nbd-client ${archiso_nbd_srv} -N ${archiso_nbd_name} /dev/nbd0 -persist
    fi

    archisodevice=/dev/nbd0

    archiso_mount_handler ${newroot}

    if [[ "${copytoram}" = "y" ]]; then
        msg ":: Disconnect NBD from ${archiso_nbd_srv} at /dev/nbd0"
        nbd-client -d /dev/nbd0
    else
        mkdir -p /run/archiso
        pidof nbd-client > /run/archiso/nbd_client.pid
        cp /archiso_pxe_nbd ${newroot}/etc/rc.d/functions.d/
    fi
}