当前位置: 首页 > news >正文

在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 123456

sudo nano ~/custom-iso/user-data

#cloud-config
autoinstall:
  version: 1
  refresh-installer:
    update: yes
  locale: en_US.UTF-8
  keyboard:
    layout: us
  identity:
    hostname: auto-ubuntu
    username: x58
    password: "$6$THVVReBQdldHeQxy$E2Mn0vZjjAh058Bc60dUTGcj9NvONFlfq5YQzqV9Phq9pOCd1PiD7gp2YhMIjW6JKxtGb7h2sAusD.xCM9hLw1"
  storage:
    layout:
      name: direct
  network:
    version: 2
    ethernets:
      en*:  # 通配符匹配所有以太网接口
        dhcp4: no
        addresses:
          - 192.168.1.123/24
        routes:
          - to: default
            via: 192.168.1.1
        nameservers:
          addresses: [8.8.8.8, 114.114.114.114]
  ssh:
    install-server: yes
    allow-pw: yes
  packages:
    - 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 <<EOF
      Section "Device"
          Identifier  "DummyDevice"
          Driver      "dummy"
          Option      "ConstantDPI" "true"
          Option      "IgnoreEDID" "true"
          Option      "NoDDC" "true"
      EndSection

      Section "Monitor"
          Identifier  "DummyMonitor"
          HorizSync   31.5-48.5
          VertRefresh 50-70
          Modeline "1920x1080" 148.50 1920 2448 2492 2640 1080 1084 1089 1125 +HSync +VSync
      EndSection

      Section "Screen"
          Identifier  "DummyScreen"
          Device      "DummyDevice"
          Monitor     "DummyMonitor"
          DefaultDepth 24
          SubSection "Display"
              Depth 24
              Modes "1920x1080"
          EndSubSection
      EndSection
      EOF
    
    # 设置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 打包新ISO

cd ~/custom-iso

sudo 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
 

相关文章:

  • C++数组,链表,二叉树的内存排列是什么样的,结构体占多大内存如何计算,类占多大内存如何计算,空类的空间是多少,为什么?
  • Linux进程概念(二)
  • 若依vue前端queryParams搜索下拉框无法重置或者重置值有问题
  • SpringBoot(一)--搭建架构5种方法
  • 基于控制障碍函数(Control Barrier Function)的二次规划(QP)控制
  • Good Bye 2013 F. New Year Tree 倍增、思维
  • 原函数存在定理
  • 一个基于C语言的猜数字小游戏
  • 【打卡day3】字符串类
  • clickhouse查询效率低
  • C++之list
  • SpringBoot POST和GET请求
  • 【算法】大数据查重
  • 庞加莱映射的性质
  • vs code 设置字体颜色
  • 深入了解蓝牙广播与扫描响应
  • Codeforces Round 258 (Div. 2) E. Devu and Flowers 生成函数
  • 四、云原生应用监控-Etcd
  • IMX6ULL的最简单的LED驱动程序
  • 南开提出1Prompt1Story,无需训练,可通过单个连接提示实现一致的文本到图像生成。
  • 搜狐一季度营收1.36亿美元,净亏损同比收窄超两成
  • 和平会谈两天后,俄对乌发动冲突爆发以来最大规模无人机袭击
  • 特朗普:将于19日分别与普京和泽连斯基通话
  • 芬兰西南部两架直升机相撞坠毁,第一批救援队已抵达现场
  • 朝鲜称将在各领域采取反制措施,应对美国敌对挑衅
  • 马上评|家长抱婴儿值护学岗,如何避免“被自愿”?