forked from bin456789/reinstall
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ubuntu.yaml
80 lines (72 loc) · 2.57 KB
/
ubuntu.yaml
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
#cloud-config
# 顺序 early-commands > 安装系统 > late-commands > 重启进入系统 > cloud-init: runcmd > cloud-init: 其他
autoinstall:
version: 1
apt:
fallback: offline-install
source:
id: ubuntu-server-minimal
search_drivers: false
kernel:
package: linux-generic
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
prefix=extra
for var in $(grep -o "\b$prefix\.[^ ]*" /proc/cmdline | xargs); do
eval "$(echo $var | sed -E "s/$prefix\.([^=]*)=(.*)/\1='\2'/")"
done
# 生成分区信息
curl -L $confhome/ubuntu-storage-early.sh | bash -s
# 内核风味
# https://bugs.launchpad.net/subiquity/+bug/1989353
sed -i "s/generic/$kernel/" /run/kernel-meta-package
sed -i "/package:/s/generic/$kernel/" /autoinstall.yaml
# 禁用 DNS 强制离线安装内核和跳过最后的更新
# 但安装器会配置时区和写入最近的mirror到/etc/apt/sources.list 所以要提前解析
# dig会显示cname结果,cname会以.结尾,grep -v '\.$' 表示去除 cname 结果
# echo $(dig +short geoip.ubuntu.com | grep -v '\.$' | head -1) geoip.ubuntu.com >>/etc/hosts
# sed -i -E 's/(^nameserver )/#\1/' /etc/resolv.conf
late-commands:
- |
# root ssh 登录
echo "PermitRootLogin yes" >/target/etc/ssh/sshd_config.d/01-permitrootlogin.conf
# 还原 DNS
# sed -i -E 's/^#(nameserver )/\1/' /etc/resolv.conf
# 提取 extra.confhome
prefix=extra
for var in $(grep -o "\b$prefix\.[^ ]*" /proc/cmdline | xargs); do
eval "$(echo $var | sed -E "s/$prefix\.([^=]*)=(.*)/\1='\2'/")"
done
# 下载合并分区脚本
cd /target
curl -O $confhome/resize.sh
# 升级 cloud-init
# curtin in-target --target=/target -- apt update
# curtin in-target --target=/target -- apt install --only-upgrade cloud-init
user-data:
runcmd:
- |
# 合并分区
bash /resize.sh
disable_root: false
users:
- name: root
lock_passwd: false
chpasswd:
expire: false
# 20.04 arm 需要
list: |
root:123@@@
users:
- name: root
password: 123@@@
type: text