欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 艺术 > 在ubuntu 24 命令行 下,制作无人值守ubuntu-24.04.2-desktop 桌面版安装U盘

在ubuntu 24 命令行 下,制作无人值守ubuntu-24.04.2-desktop 桌面版安装U盘

2025/3/13 21:35:19 来源:https://blog.csdn.net/jiangkp/article/details/146132359  浏览:    关键词:在ubuntu 24 命令行 下,制作无人值守ubuntu-24.04.2-desktop 桌面版安装U盘

1、说明

在线教育平台需要的电脑配置较高,如果直接买阿里云的配置,有点小贵,自己搞了一套专门运行,二手便宜,但是没有核显也没有显卡,比较麻烦,想做一个无人值守的ubuntu系统,这次完全在deepseek的指导下进行

二、制作过程 

1、准备工作

# 安装必要工具
sudo apt update && sudo apt install -y wget xorriso isolinux syslinux-utils# 下载Ubuntu 24.04.2桌面版ISO(替换为实际URL)
wget https://releases.ubuntu.com/24.04.2/ubuntu-24.04.2-desktop-amd64.iso

2. 挂载ISO并提取文件

# 我挂载了u盘
sudo mkdir /mnt/upan            #新建目录
sudo mount /dev/sdb1 /mnt/upan    #挂载磁盘 /mntu
# 创建挂载点和提取目录
sudo mkdir -p /mnt/iso
sudo mkdir ~/custom-iso# 挂载ISO文件
sudo mount -o loop ubuntu-24.04.2-desktop-amd64.iso /mnt/iso# 复制文件到临时目录(保留权限)
rsync -av /mnt/iso/ ~/custom-iso/# 卸载原始ISO
sudo umount /mnt/iso

3. 创建Autoinstall配置文件

# 在 ~/custom-iso 目录下创建 user-data 文件: 
# 本次配置添加了静态ip,ssh,远程桌面、虚拟显示器
# 密码用mkpasswd -m sha-512
#例如 x58@x58:/mntu$ mkpasswd -m sha-512 123456sudo nano ~/custom-iso/user-data#cloud-config
autoinstall:version: 1refresh-installer:update: yeslocale: en_US.UTF-8keyboard:layout: usidentity:hostname: auto-ubuntuusername: x58password: "$6$THVVReBQdldHeQxy$E2Mn0vZjjAh058Bc60dUTGcj9NvONFlfq5YQzqV9Phq9pOCd1PiD7gp2YhMIjW6JKxtGb7h2sAusD.xCM9hLw1"storage:layout:name: directnetwork:version: 2ethernets:en*:  # 通配符匹配所有以太网接口dhcp4: noaddresses:- 192.168.1.123/24routes:- to: defaultvia: 192.168.1.1nameservers:addresses: [8.8.8.8, 114.114.114.114]ssh:install-server: yesallow-pw: yespackages:- openssh-server- xrdp- ufw- xserver-xorg-video-dummy  # 虚拟显示器驱动- xorgxrdp  # xrdp与Xorg集成late-commands:# 配置用户sudo权限- echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ubuntu-nopasswd# 配置防火墙规则- curtin in-target --target /target -- ufw allow 22/tcp- curtin in-target --target /target -- ufw allow 3389/tcp- curtin in-target --target /target -- ufw --force enable# 强制使用Xorg(禁用Wayland)- sed -i 's/#WaylandEnable=false/WaylandEnable=false/g' /target/etc/gdm3/custom.conf# 创建虚拟显示器配置文件- |cat > /target/etc/X11/xorg.conf.d/10-virtual-display.conf <<EOFSection "Device"Identifier  "DummyDevice"Driver      "dummy"Option      "ConstantDPI" "true"Option      "IgnoreEDID" "true"Option      "NoDDC" "true"EndSectionSection "Monitor"Identifier  "DummyMonitor"HorizSync   31.5-48.5VertRefresh 50-70Modeline "1920x1080" 148.50 1920 2448 2492 2640 1080 1084 1089 1125 +HSync +VSyncEndSectionSection "Screen"Identifier  "DummyScreen"Device      "DummyDevice"Monitor     "DummyMonitor"DefaultDepth 24SubSection "Display"Depth 24Modes "1920x1080"EndSubSectionEndSectionEOF# 设置xrdp使用虚拟显示器- sed -i 's/use_vsock=false/use_vsock=false\ndefault_display=:20/g' /target/etc/xrdp/xrdp.ini# 确保服务自启- curtin in-target --target /target -- systemctl enable xrdp

4. 修改引导配置

# 编辑GRUB配置文件以启用自动安装:
sudo nano ~/custom-iso/boot/grub/grub.cfg# 在第一个 linux 行末尾添加参数:
linux   /casper/vmlinuz quiet autoinstall ds=nocloud\;s=/cdrom/ ---

5. 重新生成ISO文件

#使用 xorriso 打包新ISOcd ~/custom-isosudo xorriso -as mkisofs \-r -V "UBUNTU_2404_AUTO" \-o ~/ubuntu_2404_auto.iso \--grub2-mbr /usr/lib/grub/i386-pc/boot_hybrid.img \-partition_offset 16 \--mbr-force-bootable \-append_partition 2 0xEF ~/custom-iso/EFI/boot/bootx64.efi \-appended_part_as_gpt \-c boot.catalog \-b boot/grub/i386-pc/eltorito.img \-no-emul-boot -boot-load-size 4 -boot-info-table \--grub2-boot-info \-eltorito-alt-boot \-e '--interval:appended_partition_2:all::' \-no-emul-boot \-isohybrid-gpt-basdat \.

6、验证

# 查看ISO的EFI分区信息
fdisk -l ~/ubuntu_2404_auto.iso
# 应有 "EFI System" 分区标记

修正后的命令将生成支持以下特性的ISO:

  • ✅ 无人值守安装(包含用户名、密码、静态IP)

  • ✅ 自动安装openssh、xrdp、虚拟显示器驱动

  • ✅ 禁用Wayland,强制使用Xorg

  • ✅ 兼容UEFI/BIOS双引导设备

三、写入u盘做启动盘 

sudo dd if=~/ubuntu_2404_auto.iso of=/dev/sdX bs=4M status=progress oflag=sync

x58@x58:~$ sudo dd if=~/ubuntu_2404_auto.iso of=/dev/sdc bs=4M status=progress oflag=sync
6337593344 字节 (6.3 GB, 5.9 GiB) 已复制,635 s,10.0 MB/s
输入了 1511+1 块记录
输出了 1511+1 块记录
6338052096 字节 (6.3 GB, 5.9 GiB) 已复制,636.118 s,10.0 MB/s
 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词