在rocklinxu里使用pxe自动部署ubunte
开始前提
本机地址 8.100
需要一台rocklinux虚拟机
需要软件和光盘
实验开始
1.安装软件
yum -y install epel-release
yum -y install dnsmasq
yum -y install httpd
yum install vim-enhanced
2.上传镜像,配置文件
vim /etc/dnsmasq.d/pxe.conf
interface=ens160 # 106行,写自己的网卡名字
bind-interfaces # 强制绑定到指定接口 132行
port=5353 # 191行,去掉注释
dhcp-range=192.168.8.50,192.168.8.150,12h # DHCP地址范围和租约时间 173行
dhcp-boot=pxelinux.0 # 指定PXE引导文件 452行
enable-tftp # 启用TFTP服务 509行
tftp-root=/srv/tftp # TFTP根目录 512行,修改成自己的目录
log-facility=/var/log/dnsmasq.log # 日志路径,这个没有自己添加,位置随便
保存退出
Systemctl stop firewalld
setenforce 0
mkdir -p /srv/tftp
systemctl restart dnsmasq
查看是否启动
Ss -unlp 看看 67 69是否启动
cd /var/www/html/
mkdir autoinstall iso
touch autoinstall/meta-data
touch autoinstall/user-data
Chmod -R 777 /var/www/html
Cd iso
把下面这个镜像上传到这个目录 /var/www/html/iso
编辑文件(这个有的可能有有的可以没有,不影响,直接覆盖,没有的创建)
Vim autoinstall/user-data
#cloud-config
autoinstall:
version: 1
# 设置语言
locale: en_US.UTF-8
# 设置时区
timezone: Asia/Shanghai
keyboard:
layout: us
# 安装ubuntu服务器版,最小化选择 ubuntu-mini
source:
id: ubuntu-server
search_drivers: false
# 网络配置,根据具体接口名称修改。
network:
version: 2
ethernets:
ens33: {dhcp4: true}
# 是否安装第三方驱动
drivers:
install: false
# 内核安装,linux-generic 通用内核
kernel:
package: linux-generic
# 设置存储库,这里使用阿里云
apt:
fallback: offline-install
mirror-selection:
primary:
- arches: [amd64]
uri: http://mirrors.aliyun.com/ubuntu/
- arches: [arm64]
uri: http://mirrors.aliyun.com/ubuntu-ports
preserve_sources_list: false
# 配置存储,分区
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: 1M, flag: bios_grub, number: 1, preserve: false,type: partition, id: partition-0}
- {device: disk-sda, size: 300M, wipe: superblock, flag: '', number: 2,preserve: false, type: partition, id: partition-1}
- {device: disk-sda, size: -1, wipe: superblock, flag: '', number: 3, preserve: false, type: partition, id: partition-2}
- {fstype: ext4, volume: partition-1, preserve: false, type: format, id: format-0}
- {fstype: ext4, volume: partition-2, preserve: false, type: format, id: format-1}
- {device: format-0, path: /boot, type: mount, id: mount-0}
- {device: format-1, path: /, type: mount, id: mount-1}
# 配置账号信息
identity:
hostname: ubuntu #可以修改创建自己的用户
username: ubuntu
password: $6$t0CWYjTG8Nyq8pNv$2Gws/1V7ImPm/Pc8i6.KZU.epvF.wAyHuwrgbTj.pCD/smAgELHCfNYcdx6r/MKQkZgQyjMXRyYntgFRqxPUY. # 密码用openssl passwd -1生成自己
# ssg 配置
ssh:
allow-pw: true
install-server: true
# 软件安装
packages:
- vim
- git
# 重启前要运行的命令,curtin in-target --target=/target -- $shell_commandcurtin 格式
late-commands:
- curtin in-target --target=/target -- apt-get -y update
启动http
Systemctl start httpd
打开浏览器访问是否可以访问
- 挂载镜像
mount -o loop /var/www/html/iso/ubuntu-24.04.2-live-server-amd64.iso /mnt
df -hT --检查
cp /mnt/casper/{vmlinuz,initrd} /srv/tftp/
ls /src/tftp 现在目录下有2个文件
导入引导文件到root下
解压复制到root下
Cd
tar -zxvf ubuntu-24.04.2-netboot-amd64.tar.gz
cp amd64/pxelinux.0 /srv/tftp/
检查一下
ls /srv/tftp/ --现在目录下应该有3个
- 创建引导配置文件
cd /srv/tftp/
mkdir -p pxelinux.cfg
编辑文件(里面是空的,直接粘贴)
vim /srv/tftp/pxelinux.cfg/default
DEFAULT menu.c32
MENU TITLE PXE Boot Menu
PROMPT 0
TIMEOUT 30
LABEL Ubuntu 24.04 BIOS Install
MENU LABEL Install Ubuntu 24.04 (BIOS)
KERNEL vmlinuz
INITRD initrd
APPEND root=/dev/ram0 ramdisk_size=1024 ip=dhcp url=http://192.168.8.100/iso/ubuntu-24.04.2-live-server-amd64.iso autoinstall ds=nocloud-net;s=http://192.168.8.100/autoinstall/ cloud-config-url=/dev/null
- 拷贝sylinux引导程序的关键文件
cp /usr/share/syslinux/ldlinux.c32 /srv/tftp/
cp /usr/share/syslinux/libutil.c32 /srv/tftp/
cp /usr/share/syslinux/menu.c32 /srv/tftp/
ls /srv/tftp --现在有7个
6.安装测试,内存为4G,关闭3D图形