企业级U盘自动安装Ubuntu-Server操作系统方案

1.背景:

在企业IT环境中,大规模部署Ubuntu Server操作系统时,传统的光盘安装或手动安装方式效率低下且容易出错。本方案提供一种基于U盘的自动化安装方法,支持Ubuntu Server 20.04 LTS、22.04 LTS和24.04 LTS版本,实现快速、标准化部署。

2.技术实现

2.1 工具工作
  • ubuntu iso镜像
  • 16GB或以上容量U盘(推荐USB 3.0及以上)
  • UltraISO_9.6.5.3237软碟通
2.2 user-data 和meta-data文件准备

创建autoinstall目录,在目录中创建user-data和meta-data文件:
user-data文件:

#cloud-config
autoinstall:
  version: 1
  identity:
    hostname: ailink
    username: ailink
    password: $6$EpqNuY8xcnqK5mhM$lzjVR3HMCiM3zAK6IHmfTVPNBmT5u.F1Xlh2.xOKOHtT9RMUAH1xvbEZcN8QKdZwtox3B47RROVN1FzLcyPkS1
  user-data:
    chpasswd:
      expire: false
      list:
        - root:$6$EpqNuY8xcnqK5mhM$lzjVR3HMCiM3zAK6IHmfTVPNBmT5u.F1Xlh2.xOKOHtT9RMUAH1xvbEZcN8QKdZwtox3B47RROVN1FzLcyPkS1
    ssh_pwauth: true
  keyboard:
    layout: us
  locale: en_US.UTF-8
  timezone: Asia/Shanghai
  storage:
    grub:
      reorder_uefi: false
    swap:
      size: 2147483648
    config:
      - {ptable: gpt, path: /dev/sda, wipe: superblock-recursive, preserve: false, name: '', grub_device: false, type: disk, id: disk-sda}

      # /boot/efi partition (2G)
      - {device: disk-sda, size: 2147483648, wipe: superblock, flag: boot, number: 1, preserve: false, grub_device: true, type: partition, id: partition-sda1}
      - {fstype: fat32, volume: partition-sda1, preserve: false, type: format, id: format-efi}

      # /boot partition (2G)
      - {device: disk-sda, size: 2147483648, wipe: superblock, flag: linux, number: 2, preserve: false, type: partition, id: partition-sda2}
      - {fstype: ext4, volume: partition-sda2, preserve: false, type: format, id: format-boot}

      # /var partition (100G)
      - {device: disk-sda, size: 107374182400, wipe: superblock, flag: linux, number: 3, preserve: false, type: partition, id: partition-sda3}
      - {fstype: ext4, volume: partition-sda3, preserve: false, type: format, id: format-var}

      # /tmp partition (30G)
      - {device: disk-sda, size: 32212254720, wipe: superblock, flag: linux, number: 4, preserve: false, type: partition, id: partition-sda4}
      - {fstype: ext4, volume: partition-sda4, preserve: false, type: format, id: format-tmp}

      # Root partition (remaining space)
      - {device: disk-sda, size: -1, flag: linux, number: 5, preserve: false, type: partition, id: partition-sda5}
      - {fstype: ext4, volume: partition-sda5, preserve: false, type: format, id: format-root}

      # Mount points
      - {device: format-root, path: /, type: mount, id: mount-root}
      - {device: format-boot, path: /boot, type: mount, id: mount-boot}
      - {device: format-efi, path: /boot/efi, type: mount, id: mount-efi}
      - {device: format-var, path: /var, type: mount, id: mount-var}
      - {device: format-tmp, path: /tmp, type: mount, id: mount-tmp}
  ssh:
    install-server: true
    allow-pw: true
  late-commands:
    - curtin in-target --target=/target -- sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
  updates: security

meta-data文件:

touch meta-data   #空文件即可
2.3 grub.cgf引导配置文件准备

说明:
ubuntu20.04和ubuntu22.04/ubuntu24.04引导配置文件略有差别:
ubuntu20.04系统操作:

修改isolinux/txt.cfg
kernel /casper/vmlinuz
append   initrd=/casper/initrd quiet autoinstall ds='nocloud-net;s=/cdrom/autoinstall/' fsck.mode=skip ---
修改boot/grub/grub.cfg
linux	/casper/vmlinuz   quiet autoinstall ds='nocloud-net;s=/cdrom/' fsck.mode=skip ---
initrd	/casper/initrd

ubutun22.04/ubuntu24.04系统操作:

修改boot/grub/grub.cfg
linux	/casper/vmlinuz  autoinstall ds='nocloud-net;s=/cdrom/autoinstall/'  ---
initrd	/casper/initrd
2.4 制作自动安装系统iso
  • 将准备iso刻录修改工具 UltraISO,点击文件-打开,如图:
    在这里插入图片描述

  • 将autoinstall目录放到iso的跟目录中,将本地目录中的文件拖到iso中,如图:
    在这里插入图片描述

  • grub.cfg文件放到iso的目录/boot/grub/目录中,如图:
    在这里插入图片描述

  • 另存为ubuntu24.04-auto.iso,如图:
    在这里插入图片描述

2.5 U盘制作

如图:
在这里插入图片描述
点击-写入:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值