Ubuntu 定制 Linux 系统的主流路径与步骤
一、目标与路径选择
二、镜像级定制流程(ISO 解包与重打包)
sudo apt-get install -y squashfs-tools xorrisomount ubuntu-22.04-desktop-amd64.iso /mnt/iso && cp -rp /mnt/iso/. livecd && umount /mnt/isounsquashfs livecd/casper/filesystem.squashfs,得到 squashfs-rootsudo chroot squashfs-rootmount -t proc proc /proc; mount -t sysfs sys /sys; mount -t devpts devpts /dev/ptscp /etc/resolv.conf /squashfs-root/etc/resolv.conf/etc/apt/sources.list 中加入
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverseapt-get update && apt-get install -y openssh-server vim docker.io docker-composeexit && umount squashfs-root/{proc,sys,dev/pts}chmod +w livecd/casper/filesystem.manifestchroot squashfs-root dpkg-query -W --showformat='${Package} ${Version}\n' > livecd/casper/filesystem.manifestcp livecd/casper/filesystem.manifest livecd/casper/filesystem.manifest-desktopsed -i '/ubiquity/d' livecd/casper/filesystem.manifest-desktopsed -i '/casper/d' livecd/casper/filesystem.manifest-desktoprm livecd/casper/filesystem.squashfs && mksquashfs squashfs-root livecd/casper/filesystem.squashfsxorriso -as mkisofs -iso-level 3 -o custom-ubuntu-22.04.iso -full-iso9660-filenames -volid "Custom Ubuntu 22.04" -eltorito-alt-boot -e EFI/boot/bootx64.efi -no-emul-boot -isohybrid-gpt-basdat livecd/xorriso -as mkisofs -iso-level 3 -o custom-ubuntu-22.04.iso -full-iso9660-filenames -volid "Custom Ubuntu 22.04" -boot-info-table --grub2-boot-info -eltorito-alt-boot -b 'boot/grub/i386-pc/eltorito.img' -no-emul-boot -isohybrid-gpt-basdat livecd/三、自动化构建与高级定制
sudo add-apt-repository ppa:cubic-wizard/release && sudo apt install --no-install-recommends cubicsudo apt-get install -y git live-buildlb config 生成配置骨架,按需编辑 config/*(包列表、钩子脚本、引导配置等),最后 lb build 生成 Live 镜像,适合版本化管理与持续集成。sudo cp wallpaper.png /usr/share/backgrounds//usr/share/glib-2.0/schemas/99_custom-wallpaper.gschema.override:
[org.gnome.desktop.background] picture-uri='file:///usr/share/backgrounds/wallpaper.png' picture-options='zoom'sudo glib-compile-schemas /usr/share/glib-2.0/schemas/update-alternatives --install /usr/share/plymouth/themes/default.plymouth default.plymouth /usr/share/plymouth/themes/custom-boot/custom-boot.plymouth 100update-alternatives --set default.plymouth /usr/share/plymouth/themes/custom-boot/custom-boot.plymouthupdate-initramfs -u四、从零构建最小 Linux 系统(学习向)
sudo apt-get install -y fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bisonmake x86_64_defconfigmake menuconfig(启用 Initial RAM filesystem 等)make -j$(nproc)arch/x86/boot/bzImagemake defconfig && make menuconfig(Settings → Build static binary)make -j$(nproc) && make install(生成 _install 目录)_install 中创建 init:
#!/bin/shmount -t proc proc /proc; mount -t sysfs sys /sys; mount -t devtmpfs devtmpfs /devecho /sbin/mdev > /proc/sys/kernel/hotplugmdev -sexec /bin/shfind . | cpio -o -H newc | gzip -9 > initramfs.cpio.gzqemu-system-x86_64 -kernel arch/x86/boot/bzImage -initrd initramfs.cpio.gz -nographic -append "console=ttyS0"五、实用建议与常见问题
apt clean,减少 filesystem.squashfs 体积。/etc/resolv.conf,并切换到就近镜像源(如 aliyun/ustc)以加速安装。/etc/machine-id,避免克隆后冲突;预装软件注意许可证与版权合规。