Debian/Ubuntu 通过 early/run 命令设置预置镜像变量

man*_*nga 7 ubuntu debian preseed

我需要知道如何通过 di early/command 或 di preseed/run 将其添加到 preseed 中,以便preseed.cfg/proc/cmdline参数中设置我的镜像。

如果我做:

d-i preseed/run string ws/ubuntu.sh

#!/bin/sh
     for x in `cat /proc/cmdline`; do
             case $x in RPHOST*)
                     eval $x

                     d-i mirror/http/hostname string ${RPHOST}
                     d-i mirror/http/mirror string ${RPHOST}
                     d-i apt-setup/security_host string ${RPHOST}
                     ;;
             esac; 
done
Run Code Online (Sandbox Code Playgroud)

它失败。

它在 CentOS 启动%pre部分运行良好,但我不知道如何通过 debian/ubuntu 预置来实现。

man*_*nga 6

在对 debconf 进行了一些研究后,我想出了这个解决方案:

在您的 preseed.cfg 中,您通过以下方式调用脚本:

d-i preseed/run string ws/ubuntu.sh    // subdir from preseed file location
Run Code Online (Sandbox Code Playgroud)

ubuntu.sh 的内容:

#!/bin/sh
echo "Start ubuntu.sh runscript" >> /var/log/syslog
for x in `cat /proc/cmdline`; do
        case $x in RPHOST*)
                eval $x
                HOST=$RPHOST
                echo "d-i mirror/http/hostname string ${HOST}" > /tmp/mirror.cfg
                echo "d-i mirror/http/mirror string ${HOST}" >> /tmp/mirror.cfg
                echo "d-i apt-setup/security_host string ${HOST}" >> /tmp/mirror.cfg
                ;;
        esac;
done
// add´s values to /var/lib/cdebconf/question.dat
debconf-set-selections /tmp/mirror.cfg
Run Code Online (Sandbox Code Playgroud)

在 12.04.2 LTS 上运行良好!