通过查阅资料发现,网上的ubuntu自动化安装教程,多以pxe的方式安装,现分享一种基于iPXE的安装教程,欢迎交流!
1.新建VM虚拟机
首先新建一台VMware,我使用的是centos7.9的操作系统,并配置能连接外网。这一步具体操作请自行查询资料。
2.配置虚拟机为IPXE服务器
2.1安装必要的服务
[root@localhost ~]
2.2 配置http服务
2.2.1 上传ubuntu22.04的iso镜像
将ubuntu22.04的iso镜像传到虚拟机中(使用xftp、共享文件都行,看你喜欢)。这里先暂时放在root目录(ps:放在哪里都可以)。
2.2.2 在http目录下创建iso目录, 并将iso拷贝至iso目录
cd /var/www/html/
mkdir iso
cp /root/ubuntu-22.04-live-server-amd64.iso /var/www/html/iso
2.2.3挂载iso, 提取initrd和 vmlinuz
mkdir /opt/disk
mount -o loop /root/ubuntu-22.04-live-server-amd64.iso /opt/disk/
将initrd和 vmlinuz拷贝至 刚才创建的iso目录
cp /opt/disk/casper/initrd /var/www/html/iso
cp /opt/disk/casper/vmlinuz /var/www/html/iso
2.2.4 创建 user-data和meta-data
mkdir -p /var/www/html/ks/ubuntu
touch meta-data #meta-data 是空文件,但是必须要有
![[]](https://img-blog.csdnimg.cn/f360abaed610458e9b1c51db7e3ed0b9.png)
创建一个user-data,文件内容如下:
ps: 也可以参照https://ubuntu.com/server/docs/install/autoinstall-reference自行创建,最方便的方式是先通过图形化界面安装一次系统,然后系统中/var/log/install/auto-user-data 拷贝出来使用。注意在修改时严格遵守yaml语法。
autoinstall:
drivers:
install: false
identity:
hostname: ZHH
password: $6$5.4Db4xd76bu0i3v$ujjOoIhX2cs.TBA8XFi/TZ/mrNaNA9CdClWpVpOUeFhqIINuq8w4cpp9BUDAVIN88h7oPoYDCofRt9zs0zPWo1
realname: ZHH
username: zhh
keyboard:
layout: us
toggle: null
variant: ''
locale: en_US.UTF-8
ssh:
allow-pw: true
authorized-keys: []
install-server: true
storage:
config:
- ptable: gpt
wipe: superblock-recursive
preserve: false
name: ''
grub_device: true
type: disk
id: disk-sda
match:
size: largest
- device: disk-sda
size: 1048576
flag: bios_grub
number: 1
preserve: false
grub_device: false
type: partition
id: partition-0
- device: disk-sda
size: 8589934592
wipe: superblock
flag: swap
number: 2
preserve: false
grub_device: false
type: partition
id: partition-1
- fstype: swap
volume: partition-1
preserve: false
type: format
id: format-0
- path: ''
device: format-0
type: mount
id: mount-0
- device: disk-sda
size: 1073741824
wipe: superblock
flag: ''
number: 3
preserve: false
grub_device: false
type: partition
id: partition-2
- fstype: xfs
volume: partition-2
preserve: false
type: format
id: format-1
- device: disk-sda
size: 8589934592
wipe: superblock
flag: ''
number: 4
preserve: false
grub_device: false
type: partition
id: partition-3
- fstype: xfs
volume: partition-3
preserve: false
type: format
id: format-2
- device: disk-sda
size: 21474836480
wipe: superblock
flag: ''
number: 5
preserve: false
grub_device: false
type: partition
id: partition-4
- fstype: xfs
volume: partition-4
preserve: false
type: format
id: format-3
- path: /
device: format-3
type: mount
id: mount-3
- device: disk-sda
size: -1
wipe: superblock
flag: ''
number: 6
preserve: false
grub_device: false
type: partition
id: partition-5
- fstype: xfs
volume: partition-5
preserve: false
type: format
id: format-4
- path: /data
device: format-4
type: mount
id: mount-4
- path: /boot
device: format-1
type: mount
id: mount-1
- path: /var
device: format-2
type: mount
id: mount-2
swap:
swap: 0
updates: security
version: 1
2.3 配置tftp服务
2.3.1下载并编译ipxe固件
ps: 编译所需的依赖请自行安装
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost src]
[root@localhost src]
执行完之后,在bin中会有一个undionly.kpxe文件,在bin-x86_64-efi会有ipxe.efi,之后会用到这两个文件。
![[]](https://img-blog.csdnimg.cn/084d2f125b794f82bf06f55acdde1343.png)
![[]](https://img-blog.csdnimg.cn/bfddf5556c9a458eb43c27e0e2c0f351.png)
2.3.2 修改 tftp配置
[root@localhost ~]
2.3.3复制ipxe固件至tftp根目录
[root@localhost ~]
[root@localhost ~]
2.3.4 配置启动脚本
vi /var/lib/tftpboot/ubuntu2204.cfg
内容如下:
#!ipxe
set product-name ubuntu2204
set os-name ubuntu2204
set menu-timeout 10000
set submenu-timeout ${menu-timeout}
set menu-default exit
:start
menu boot from iPXE server
item --gap -- --------------------------------------------
item --gap -- serial:${serial}
item --gap -- mac:${mac}
item --gap -- ip:${ip}
item --gap -- netmask:${netmask}
item --gap -- gateway:${gateway}
item --gap -- dns:${dns}
item
item --gap -- --------------------------------------------
item install-os ${product-name}
choose --timeout ${menu-timeout} --default ${menu-default} selected || goto cancel
goto ${selected}
:install-os
set server http://ipxe.server/
initrd ${server}iso/initrd
kernel ${server}iso/vmlinuz initrd=initrd ip=dhcp url=${server}iso/ubuntu-22.04.1-live-server-amd64.iso autoinstall ds=nocloud-net;s=${server}/ks/ubuntu/ root=/dev/ram0 cloud-config-url=/dev/null console=ttyS0,115200n8
boot
如果没有串口,就将’console=ttyS0,115200n8 ‘删除
2.4 配置DNS服务
[root@localhost ~]
2.5 配置dhcp服务
创建dhcp配置文件
[root@localhost ~]
[root@localhost ~]
编辑如下内容
option client-architecture code 93 = unsigned integer 16;
subnet 10.10.0.0 netmask 255.255.255.224 {
range 10.10.0.10 10.10.0.20;
next-server 10.10.0.2;
if exists user-class and option user-class = "iPXE" {
filename "ubuntu2204.cfg";
} elsif option client-architecture = 00:00 {
filename "undionly.kpxe";
} else {
filename "ipxe.efi";
}
}
并在dhcp配置文件中,指定DNS服务器
2.6 修改虚拟机ip
[root@localhost ~]
[root@localhost ~]
![[]](https://img-blog.csdnimg.cn/7831e1b906e54f19b650edf2c86ec3fc.png)
2.7 修改虚拟机为桥接模式,配置物理网卡
选择虚拟机为桥接模式
![[]](https://img-blog.csdnimg.cn/e4d26b3a4399435a85f1c3fd14acdf91.png)
打开虚拟网络编辑器
点击更改设置
![[]](https://img-blog.csdnimg.cn/1cc31e7188fa485a86f1658c4d95e7f8.png)
修改桥接的网口
![[]](https://img-blog.csdnimg.cn/e7c982b4a2774aea84514cdb0d093bdb.png)
2.8 关闭防火墙,重复服务
关闭防火墙 和 强访
[root@localhost ~]
[root@localhost ~]
开启dhcp,http,dns,tftp 服务
[root@localhost ~]# systemctl start dhcpd tftp httpd dnsmasq
至此ipxe服务器已经搭建完成了。 附上所有的参考资料: https://ubuntu.com/server/docs/install/autoinstall-reference
https://forum.level1techs.com/t/linux-installation-using-i-pxe/186721
https://ipxe.org/docs
https://blog.csdn.net/supahero/article/details/115829836
https://blog.csdn.net/weixin_46243964/article/details/119650128? spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-8-119650128-blog-117298899.pc_relevant_3mothn_strategy_and_data_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-8-119650128-blog-117298899.pc_relevant_3mothn_strategy_and_data_recovery&utm_relevant_index=12
https://github.com/ipxe/ipxe/discussions/709
https://curtin.readthedocs.io/en/latest/topics/storage.html
https://www.molnar-peter.hu/en/ubuntu-jammy-netinstall-pxe.html
linux就该这么学 第19章
|