reinstall/ubuntu.yaml

98 lines
3.1 KiB
YAML
Raw Normal View History

2023-05-03 22:22:21 +08:00
#cloud-config
# 顺序 early-commands > 安装系统 > late-commands > 重启进入系统 > cloud-init: runcmd > cloud-init: 其他
autoinstall:
version: 1
apt:
fallback: offline-install
2023-05-03 22:22:21 +08:00
source:
2024-09-06 23:00:33 +08:00
id: "@SOURCE_ID@"
2023-08-28 19:33:53 +08:00
kernel:
package: linux-generic
2023-05-03 22:22:21 +08:00
timezone: Asia/Shanghai
ssh:
allow-pw: true
authorized-keys: []
install-server: true
early-commands:
- |
# 解决 20.04 不能识别硬盘
# https://askubuntu.com/questions/1302392/ubuntu-server-20-04-setup-stuck-at-block-probing-did-not-discover-any-disks
mount | grep /isodevice && { losetup -d /dev/loop0; umount -l /isodevice; } || true
# 提取 extra_confhome extra_kernel
2023-05-13 00:14:46 +08:00
prefix=extra
for var in $(grep -o "\b${prefix}_[^ ]*" /proc/cmdline | xargs); do
eval "$(echo $var | sed -E "s/${prefix}_([^=]*)=(.*)/\1='\2'/")"
2023-05-13 00:14:46 +08:00
done
2023-05-03 22:22:21 +08:00
# 生成分区信息
xda=$(curl -L "$confhome/get-xda.sh" | sh -s)
export xda
curl -L "$confhome/ubuntu-storage-early.sh" | sh -s
2023-05-03 22:22:21 +08:00
2024-09-06 23:00:33 +08:00
# 要安装的版本
# 有的镜像只有一个版本,没有 install-sources.yaml
# 因此提取不到 $source_id此时 $source_id 参数为空
if [ -n "$source_id" ]; then
sed -i "s/@SOURCE_ID@/$source_id/" /autoinstall.yaml
else
sed -i "/@SOURCE_ID@/d" /autoinstall.yaml
fi
2023-08-28 19:33:53 +08:00
# 内核风味
# https://bugs.launchpad.net/subiquity/+bug/1989353
sed -i "s/generic/$kernel/" /run/kernel-meta-package
sed -i "/package:/s/generic/$kernel/" /autoinstall.yaml
2024-09-06 23:00:33 +08:00
# 跳过最后的更新
cp /usr/sbin/chroot /usr/sbin/chroot.bin
cat >/usr/sbin/chroot <<EOF
#!/bin/sh
[ "\$2" = "unattended-upgrades" ] || /usr/sbin/chroot.bin "\$@"
EOF
2023-05-03 22:22:21 +08:00
# 禁用 DNS 强制离线安装内核和跳过最后的更新
# 但安装器会配置时区和写入最近的mirror到/etc/apt/sources.list 所以要提前解析
2023-07-15 23:39:45 +08:00
# dig会显示cname结果cname会以.结尾grep -v '\.$' 表示去除 cname 结果
2023-08-28 19:33:53 +08:00
# echo $(dig +short geoip.ubuntu.com | grep -v '\.$' | head -1) geoip.ubuntu.com >>/etc/hosts
# sed -i -E 's/(^nameserver )/#\1/' /etc/resolv.conf
2023-05-03 22:22:21 +08:00
late-commands:
- |
# root ssh 登录
echo "PermitRootLogin yes" >/target/etc/ssh/sshd_config.d/01-permitrootlogin.conf
# 还原 DNS
2023-08-28 19:33:53 +08:00
# sed -i -E 's/^#(nameserver )/\1/' /etc/resolv.conf
2023-05-03 22:22:21 +08:00
# 提取 extra_confhome
2023-05-13 00:14:46 +08:00
prefix=extra
for var in $(grep -o "\b${prefix}_[^ ]*" /proc/cmdline | xargs); do
eval "$(echo $var | sed -E "s/${prefix}_([^=]*)=(.*)/\1='\2'/")"
2023-05-13 00:14:46 +08:00
done
2023-05-03 22:22:21 +08:00
# 下载合并分区脚本
cd /target
2024-02-02 00:49:24 +08:00
curl -LO $confhome/resize.sh
2023-05-03 22:22:21 +08:00
# 升级 cloud-init
# curtin in-target --target=/target -- apt update
2023-05-13 00:14:46 +08:00
# curtin in-target --target=/target -- apt install --only-upgrade cloud-init
2023-05-03 22:22:21 +08:00
user-data:
runcmd:
- |
# 合并分区
bash /resize.sh
disable_root: false
users:
- name: root
lock_passwd: false
chpasswd:
expire: false
# 20.04 arm 需要
list: |
2023-05-04 22:00:59 +08:00
root:123@@@
2023-05-03 22:22:21 +08:00
users:
- name: root
2023-05-04 22:00:59 +08:00
password: 123@@@
2023-05-03 22:22:21 +08:00
type: text