ubuntu自动安装系统

Userdata #cloud-config autoinstall: apt: geoip: true preserve_sources_list: false primary: - arches: [amd64] uri: #设置为你自己的apt源 - arches: [default] uri: #设置自己的默认apt源 identity:

Userdata

#cloud-config
autoinstall:
  apt:
    geoip: true
    preserve_sources_list: false
    primary:
    - arches: [amd64]
      uri: #设置为你自己的apt源
    - arches: [default]
      uri: #设置自己的默认apt源
  identity: {hostname: 替换为自己要设置的主机名, password: 设置用户密码,可以在其他的ubuntu机器上设置密码后复制/etc/shadow里的加密内容, username: 设置用户名}
#此处为键盘设置
  keyboard: {layout: us, toggle: null, variant: ''}
#设置时区及语言格式什么的
  user-data:
    timezone: Asia/Shanghai
  locale: zh_CN.UTF-8 
#设置网络,可参照·netpaln的设置
  network:
    ethernets:
      eth0: {dhcp4: true}
      eth1: {dhcp4: true}
      eth2: {dhcp4: true}
      eth3: {dhcp4: true}
      eth4: {dhcp4: true}
      eth5: {dhcp4: true}
      eth6: {dhcp4: true}
      eth7: {dhcp4: true}
    version: 2
#是否安装ssh,建议安装
  ssh:
    allow-pw: true
    authorized-keys: []
    install-server: true
#配置你的硬盘,此处为设置了vg的
  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-sda1}
    - {device: disk-sda, size: 2147483648, wipe: superblock, flag: linux, number: 2,
      preserve: false, grub_device: false, type: partition, id: partition-sda2}
    - {fstype: ext4, volume: partition-sda2, preserve: false, type: format, id: format-0}
    - {device: disk-sda, size: -1, wipe: superblock, flag: linux, number: 3,
      preserve: false, grub_device: false, type: partition, id: partition-sda3}
    - name: VolGroup00
      devices: [partition-sda3]
      preserve: false
      type: lvm_volgroup
      id: lvm_volgroup-0
    - {name: LogVol00, volgroup: lvm_volgroup-0, size: 107374182400B, preserve: false, type: lvm_partition,
      id: lvm_partition-0}
    - {fstype: ext4, volume: lvm_partition-0, preserve: false, type: format, id: format-1}
    - {device: format-1, path: /, type: mount, id: mount-1}
    - {name: swap, volgroup: lvm_volgroup-0, size: 4294967296B, preserve: false, type: lvm_partition,
      id: lvm_partition-1}
    - {fstype: swap, volume: lvm_partition-1, preserve: false, type: format, id: format-2}
    - {device: format-2, path: '', type: mount, id: mount-2}
    - {name: LogVol02, volgroup: lvm_volgroup-0, size: 1073741824B, preserve: false, type: lvm_partition,
      id: lvm_partition-2}
    - {fstype: ext4, volume: lvm_partition-2, preserve: false, type: format, id: format-3}
    - {device: format-3, path: /tmp, type: mount, id: mount-3}
    - {name: LogVol01, volgroup: lvm_volgroup-0, size: 107374182400B, preserve: false, type: lvm_partition,
      id: lvm_partition-3}
    - {fstype: ext4, volume: lvm_partition-3, preserve: false, type: format, id: format-4}
    - {device: format-4, path: /var, type: mount, id: mount-4}
    - {name: LogVol03, volgroup: lvm_volgroup-0, size: -1, preserve: false, type: lvm_partition,
      id: lvm_partition-4}
    - {fstype: ext4, volume: lvm_partition-4, preserve: false, type: format, id: format-5}
    - {device: format-5, path: /da1, type: mount, id: mount-5}
    - {device: format-0, path: /boot, type: mount, id: mount-0}
    swap: {swap: 0}
  version: 1
#此处为安装后执行的命令
  late-commands:
    - curtin in-target --target=/target -- update-grub2
    - curtin in-target --target=/target -- apt-get -y update
    - curtin in-target --target=/target -- apt-get -y install freeipa-client resolvconf

最后的late-commands,执行时需要注意路径,因为此时的系统安装位置为/target下,例如sed一个文件的内容,该文件在root目录下需要执行为sed -i 's/内容1/内容2/' /target/root/文件名

参考文章:

Automated server install reference | Ubuntu

https://askubuntu.com/questions/1238070/deploy-ubuntu-20-04-on-bare-metal-or-virtualbox-vm-by-pxelinux-cloud-init-doesn
Storage — curtin 21.3 documentation
 

知秋君
上一篇 2024-07-10 10:36
下一篇 2024-07-10 10:02

相关推荐