是否可以制作一张基于linux的livecd,用于iventoy或者ventoy直接运行,里面包含了必须得运维软件,尤其是像ipmitool、storcli这种,方便操作BMC以及RAID卡。

制作的主要过程是:

  1. 准备一个debian12的虚拟机
  2. 然后做一个chroot环境
  3. 安装必要的软件、服务
  4. 封装

制作过程

基础过程

sudo apt-get install -y \
    debootstrap \
    squashfs-tools \
    xorriso \
    isolinux \
    syslinux-efi \
    grub-pc-bin \
    grub-efi-amd64-bin \
    grub-efi-ia32-bin \
    mtools \
    dosfstools

mkdir -p "${HOME}/LIVE_BOOT"

sudo debootstrap \
    --arch=amd64 \
    --variant=minbase \
    stable \
    "${HOME}/LIVE_BOOT/chroot" \
    http://mirrors.ustc.edu.cn/debian/

echo "JINGAN-DTS" | sudo tee "${HOME}/LIVE_BOOT/chroot/etc/hostname"

sudo chroot "${HOME}/LIVE_BOOT/chroot" << EOF
apt-get update && \
apt-get install -y --no-install-recommends \
    linux-image-amd64 \
    live-boot \
    systemd-sysv
EOF

sudo chroot "${HOME}/LIVE_BOOT/chroot" << EOF
apt-get install -y --no-install-recommends \
    iwd \
    curl openssh-client \
    openbox xserver-xorg-core xserver-xorg xinit xterm \
    nano
EOF

sudo chroot "${HOME}/LIVE_BOOT/chroot" << EOF
apt-get install -y --no-install-recommends  curl tree wget vi vim telnet openssh-client rsync iftop nload dstat sysstat lrzsz net-tools traceroute tcpdump wireshark dnsutils smem apt-file psmisc ipmitool 
EOF

sudo chroot "${HOME}/LIVE_BOOT/chroot" << EOF
wget --no-check-certificate -O /tmp/trzsz_1.1.7_linux_x86_64.tar.gz http://vip.123pan.cn/1815238395/download/tssh/trzsz_1.1.7/trzsz_1.1.7_linux_x86_64.tar.gz
cd /tmp
tar xvf trzsz_1.1.7_linux_x86_64.tar.gz
mv -f trzsz_1.1.7_linux_x86_64/* /bin/
rm -rf trzsz*

cd /tmp/ ; wget https://d2.sddts.cn/d/download/usbos/Unified_storcli_all_os/Ubuntu/storcli_007.2807.0000.0000_all.deb 
dpkg -i storcli_007.2807.0000.0000_all.deb
echo 'export PATH=/opt/MegaRAID/storcli/:$PATH' >> /etc/profile
EOF


sudo chroot "${HOME}/LIVE_BOOT/chroot" passwd root

mkdir -p "${HOME}/LIVE_BOOT"/{staging/{EFI/BOOT,boot/grub/x86_64-efi,isolinux,live},tmp}

sudo mksquashfs \
    "${HOME}/LIVE_BOOT/chroot" \
    "${HOME}/LIVE_BOOT/staging/live/filesystem.squashfs" \
    -e boot

cp "${HOME}/LIVE_BOOT/chroot/boot"/vmlinuz-* \
    "${HOME}/LIVE_BOOT/staging/live/vmlinuz" && \
cp "${HOME}/LIVE_BOOT/chroot/boot"/initrd.img-* \
    "${HOME}/LIVE_BOOT/staging/live/initrd"

cat <<'EOF' > "${HOME}/LIVE_BOOT/staging/isolinux/isolinux.cfg"
UI vesamenu.c32

MENU TITLE Boot Menu
DEFAULT linux
TIMEOUT 600
MENU RESOLUTION 640 480
MENU COLOR border       30;44   #40ffffff #a0000000 std
MENU COLOR title        1;36;44 #9033ccff #a0000000 std
MENU COLOR sel          7;37;40 #e0ffffff #20ffffff all
MENU COLOR unsel        37;44   #50ffffff #a0000000 std
MENU COLOR help         37;40   #c0ffffff #a0000000 std
MENU COLOR timeout_msg  37;40   #80ffffff #00000000 std
MENU COLOR timeout      1;37;40 #c0ffffff #00000000 std
MENU COLOR msg07        37;40   #90ffffff #a0000000 std
MENU COLOR tabmsg       31;40   #30ffffff #00000000 std

LABEL linux
  MENU LABEL Debian Live [BIOS/ISOLINUX]
  MENU DEFAULT
  KERNEL /live/vmlinuz
  APPEND initrd=/live/initrd boot=live

LABEL linux
  MENU LABEL Debian Live [BIOS/ISOLINUX] (nomodeset)
  MENU DEFAULT
  KERNEL /live/vmlinuz
  APPEND initrd=/live/initrd boot=live nomodeset
EOF

cat <<'EOF' > "${HOME}/LIVE_BOOT/staging/boot/grub/grub.cfg"
insmod part_gpt
insmod part_msdos
insmod fat
insmod iso9660

insmod all_video
insmod font

set default="0"
set timeout=7

# If X has issues finding screens, experiment with/without nomodeset.

menuentry "JingAn Live CD (Default settings)" --id live-default {
  search --set -f /live/vmlinuz
  linux /live/vmlinuz boot=live union=overlay username=user config components quiet noswap  net.ifnames=0  nosplash 
  initrd /live/initrd.img
}

menuentry "Debian Live [EFI/GRUB]" {
    search --no-floppy --set=root --label DEBLIVE
    linux ($root)/live/vmlinuz boot=live
    initrd ($root)/live/initrd
}

menuentry "Debian Live [EFI/GRUB] (nomodeset)" {
    search --no-floppy --set=root --label DEBLIVE
    linux ($root)/live/vmlinuz boot=live nomodeset
    initrd ($root)/live/initrd
}
EOF

cp "${HOME}/LIVE_BOOT/staging/boot/grub/grub.cfg" "${HOME}/LIVE_BOOT/staging/EFI/BOOT/"

cat <<'EOF' > "${HOME}/LIVE_BOOT/tmp/grub-embed.cfg"
if ! [ -d "$cmdpath" ]; then
    # On some firmware, GRUB has a wrong cmdpath when booted from an optical disc.
    # https://gitlab.archlinux.org/archlinux/archiso/-/issues/183
    if regexp --set=1:isodevice '^(\([^)]+\))\/?[Ee][Ff][Ii]\/[Bb][Oo][Oo][Tt]\/?$' "$cmdpath"; then
        cmdpath="${isodevice}/EFI/BOOT"
    fi
fi
configfile "${cmdpath}/grub.cfg"
EOF

cp /usr/lib/ISOLINUX/isolinux.bin "${HOME}/LIVE_BOOT/staging/isolinux/" && \
cp /usr/lib/syslinux/modules/bios/* "${HOME}/LIVE_BOOT/staging/isolinux/"

cp -r /usr/lib/grub/x86_64-efi/* "${HOME}/LIVE_BOOT/staging/boot/grub/x86_64-efi/"


grub-mkstandalone -O i386-efi \
    --modules="part_gpt part_msdos fat iso9660" \
    --locales="" \
    --themes="" \
    --fonts="" \
    --output="${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTIA32.EFI" \
    "boot/grub/grub.cfg=${HOME}/LIVE_BOOT/tmp/grub-embed.cfg"

grub-mkstandalone -O x86_64-efi \
    --modules="part_gpt part_msdos fat iso9660" \
    --locales="" \
    --themes="" \
    --fonts="" \
    --output="${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTx64.EFI" \
    "boot/grub/grub.cfg=${HOME}/LIVE_BOOT/tmp/grub-embed.cfg"

(cd "${HOME}/LIVE_BOOT/staging" && \
    dd if=/dev/zero of=efiboot.img bs=1M count=20 && \
    mkfs.vfat efiboot.img && \
    mmd -i efiboot.img ::/EFI ::/EFI/BOOT && \
    mcopy -vi efiboot.img \
        "${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTIA32.EFI" \
        "${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTx64.EFI" \
        "${HOME}/LIVE_BOOT/staging/boot/grub/grub.cfg" \
        ::/EFI/BOOT/
)

修改

chroot ${HOME}/LIVE_BOOT/chroot

封装

rm -f ${HOME}/LIVE_BOOT/staging/live/filesystem.squashfs
sudo mksquashfs \
    "${HOME}/LIVE_BOOT/chroot" \
    "${HOME}/LIVE_BOOT/staging/live/filesystem.squashfs" \
    -e boot


xorriso \
    -as mkisofs \
    -iso-level 3 \
    -o "${HOME}/LIVE_BOOT/debian-custom.iso" \
    -full-iso9660-filenames \
    -volid "DEBLIVE" \
    --mbr-force-bootable -partition_offset 16 \
    -joliet -joliet-long -rational-rock \
    -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
    -eltorito-boot \
        isolinux/isolinux.bin \
        -no-emul-boot \
        -boot-load-size 4 \
        -boot-info-table \
        --eltorito-catalog isolinux/isolinux.cat \
    -eltorito-alt-boot \
        -e --interval:appended_partition_2:all:: \
        -no-emul-boot \
        -isohybrid-gpt-basdat \
    -append_partition 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B ${HOME}/LIVE_BOOT/staging/efiboot.img \
    "${HOME}/LIVE_BOOT/staging"

rm -f /tmp/debian-custom.iso ; mv ${HOME}/LIVE_BOOT/debian-custom.iso /tmp/

echo done!

参考

https://www.willhaley.com/blog/custom-debian-live-environment/

最后修改:2024 年 06 月 06 日
如果觉得我的文章对你有用,请随意赞赏