我正在尝试配置该网络,它能正常工作,但当我登录操作系统时却不行。第二,我如何配置随机主机名?
感谢 :)
#cloud-config
autoinstall:
version: 1
apt:
disable_components: []
geoip: true
preserve_sources_list: false
primary:
- arches:
- amd64
- i386
uri: http://archive.ubuntu.com/ubuntu
- arches:
- default
uri: http://ports.ubuntu.com/ubuntu-ports
identity:
hostname: ${hostname}
password: $6$tN8UBrsU5N4Tcqcz$ewAe9SRZlS2q6yxYtvyJ0u.Lu4l6pgSf5uiHpMFKjlOVTjBfuBb4QIQekfaToA1DtKAUCjoiiAEyc5VYj26uS1
realname: scadmin
username: scadmin
kernel:
package: linux-generic
keyboard:
layout: us
toggle: null
variant: ''
locale: en_US.UTF-8
network:
version: 2
renderer: networkd
ethernets:
ens160:
dhcp4: true
dhcp-identifier: mac
ssh:
allow-pw: true
authorized-keys: []
install-server: true
storage:
config:
- ptable: gpt
path: /dev/sda
wipe: superblock-recursive
preserve: false
name: ''
grub_device: true
type: disk
id: disk-sda
- device: disk-sda
size: 1048576
flag: bios_grub
number: 1
preserve: false
grub_device: false
type: partition
id: partition-0
- device: disk-sda
size: 30064771072
wipe: superblock
flag: ''
number: 2
preserve: false
grub_device: false
type: partition
id: partition-1
- name: vg0
devices:
- partition-1
preserve: false
type: lvm_volgroup
id: lvm_volgroup-0
- device: disk-sda
size: 2144337920
wipe: superblock
flag: ''
number: 3
preserve: false
grub_device: false
type: partition
id: partition-3
- fstype: ext4
volume: partition-3
preserve: false
type: format
id: format-0
- name: lv-swap
volgroup: lvm_volgroup-0
size: 4294967296B
wipe: superblock
preserve: false
type: lvm_partition
id: lvm_partition-0
- name: lv-root
volgroup: lvm_volgroup-0
size: 25765609472B
wipe: superblock
preserve: false
type: lvm_partition
id: lvm_partition-1
- fstype: ext4
volume: lvm_partition-1
preserve: false
type: format
id: format-3
- path: /
device: format-3
type: mount
id: mount-3
- fstype: swap
volume: lvm_partition-0
preserve: false
type: format
id: format-4
- path: ''
device: format-4
type: mount
id: mount-4
- path: /boot
device: format-0
type: mount
id: mount-0
updates: security
packages:
- open-vm-tools
late-commands:
- HOSTNAMEC="$(date +%N | md5sum | cut -f 1 -d " " | head -c 6 )" hostnamectl set-hostname "$HOSTNAMEC"
答案1
我正在尝试配置这个网络,它可以正常工作,但是当我登录到操作系统时却不行。
这些信息还不够。
如何配置随机主机名?
可以通过多种方式实现。以下是一些部分user-data
配置,演示了一些解决方案。
这是一个early-commands
解决方案,它将更新安装程序本身使用的配置。好处是主机将使用随机名称安装,并且稍后不需要由其他进程更改。
#cloud-config
autoinstall:
identity:
hostname: REPLACEHOSTNAME
password: REDACTED
realname: myuser
username: myuser
early-commands:
- sed -i -e "s/REPLACEHOSTNAME/$(openssl rand -hex 3)/" /autoinstall.yaml
这是一个cloud-init
配置设置主机名的解决方案cloud-init
。好处是cloud-init
还可以执行诸如设置 fqdn 和更新文件之类的操作/etc/hosts
。
#cloud-config
autoinstall:
identity:
hostname: my-hostname
password: REDACTED
realname: myuser
username: myuser
late-commands:
- |
cat <<EOF > /target/etc/cloud/cloud.cfg.d/80_my.cfg
hostname: $(openssl rand -hex 3)
manage_etc_hosts: true
preserve_hostname: false
EOF
/etc/hostname
这是在已安装的系统上进行更改的简单解决方案。
#cloud-config
autoinstall:
identity:
hostname: my-hostname
password: REDACTED
realname: myuser
username: myuser
late-commands:
- echo $(openssl rand -hex 3) > /target/etc/hostname
笔记
我使用 Ubuntu 22.04 进行了测试(subiquity 22.04.2
)