본문 바로가기
리눅스

How to create a custom Debian live from scratch

by 다움위키 2023. 12. 9.

데비안 라이브시디를 제작해 보려고 시도하는 과정입니다. 라이브시디로 부팅 후에, 설치는 Calamares를 이용합니다.

원본 문서와 다르게 우분투에서의 과정을 일부 추가해서 진행했습니다.

Prerequisites

환경을 구축하는 데 필요한 패키지를 설치합니다:

  • sudo apt install 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

Bootstrap

Checkout bootstrap

우분투 기본 환경을 정해진 미러 사이트에서 .deb 파일을 받아서 chroot하려는 디렉토리에 압축을 풀어서 만들어 줍니다:

Configure external mount point

이제, chroot로 들어가서 패키지 (그 중 grub)를 업데이트하고 설치해야 하기 때문에, 필요한 /dev 파일과 /run을 만들어야 합니다. 호스트에서 바인트를 통해서 이를 수행할 수 있습니다:

  • sudo mount --bind /dev $HOME/LIVE_BOOT/chroot/dev
  • sudo mount --bind /run $HOME/LIVE_BOOT/chroot/run

Define chroot environment

이제 라이브 시디를 구축할 환경으로 들어가서 작업을 계속합니다:

Access chroot environment

  • sudo chroot $HOME/LIVE_BOOT/chroot

Configure mount points, home and locale

  • mount none -t proc /proc
  • mount none -t sysfs /sys
  • mount none -t devpts /dev/pts
  • export HOME=/root
  • export LC_ALL=C

Set a custom hostname

  • echo "debian-live" > /etc/hostname

Configure apt sources.list

cat <<EOF > /etc/apt/sources.list
deb http://ftp.kaist.ac.kr/debian/ bullseye main contrib non-free
deb-src http://ftp.kaist.ac.kr/debian/ bullseye main contrib non-free

deb http://ftp.kaist.ac.kr/debian-security bullseye-security main contrib non-free
deb-src http://ftp.kaist.ac.kr/debian-security bullseye-security main contrib non-free

deb http://ftp.kaist.ac.kr/debian/ bullseye-updates main contrib non-free
deb-src http://ftp.kaist.ac.kr/debian/ bullseye-updates main contrib non-free
EOF

Update indexes packages

  • apt update

Install systemd

  • apt-get install -y libterm-readline-gnu-perl systemd-sysv

Configure machine-id and divert

  • dbus-uuidgen > /etc/machine-id
  • ln -fs /etc/machine-id /var/lib/dbus/machine-id
  • dpkg-divert --local --rename --add /sbin/initctl
  • ln -s /bin/true /sbin/initctl

Upgrade packages

  • apt -y upgrade

Install packages needed for Live System

  • apt install -y dialog
  • apt install -y sudo live-task-standard discover laptop-detect os-prober network-manager resolvconf net-tools wireless-tools wpagui locales grub-common grub-pc grub-pc-bin grub2-common
  • apt install -y --no-install-recommends linux-image-amd64 live-boot curl openssh-client nano

중간에 키보드 설정이 나타날 수 있습니다: Korean/Korean 102 Install window manager

  • apt install -y plymouth plymouth-themes
  • apt install -y gnome/stable

Install installation aplications

  • apt install -y rsync bash-completion calamares calamares-settings-debian

Remove unused applications (optional)

  • apt purge -y transmission-gtk transmission-common gnome-mahjongg gnome-mines gnome-sudoku aisleriot hitori

Remove unused packages

  • apt autoremove -y

System update

  • apt update
  • apt upgrade

Root user passwd & Add a user

  • passwd root
  • useradd -m -g users -G sudo -s /bin/bash liveuser
  • passwd liveuser

암호를 만드니, 설치 프로그램에서 sudo 권한을 얻기 위해 암호를 확인받습니다. 암호를 안 만드면, 그냥 실행될까요? Gnome Autologin

  • nano /etc/gdm3/daemon.conf

AutomaticLoginEnable=true AutomaticLogin=liveuser Generate locales

  • dpkg-reconfigure locales

en_US.UTF-8 UTF-8, ko_KR.UTF-8 UTF-8 Reconfigure resolvconf

  • dpkg-reconfigure resolvconf

Configure network-manager

cat <<EOF > /etc/NetworkManager/NetworkManager.conf
[main]
rc-manager=resolvconf
plugins=ifupdown,keyfile
dns=dnsmasq

[ifupdown]
managed=false
EOF

Reconfigure network-manager

  • dpkg-reconfigure network-manager

Cleanup the chroot environment

  • truncate -s 0 /etc/machine-id

Remove the diversion

  • rm /sbin/initctl
  • dpkg-divert --rename --remove /sbin/initctl

Clean up

  • apt clean
  • rm -rf /tmp/* ~/.bash_history
  • umount /proc
  • umount /sys
  • umount /dev/pts
  • export HISTSIZE=0
  • exit

Unbind mount points

  • sudo umount $HOME/LIVE_BOOT/chroot/dev
  • sudo umount $HOME/LIVE_BOOT/chroot/run
  • 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
    
  • 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=30
    
    # If X has issues finding screens, experiment with/without nomodeset.
    
    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 && \
        sudo 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/
    )
    
  • 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"
    

Troubleshootings

부팅 문제: 라이브 시디로 설치는 되지만, 부팅이 되지 않습니다. 이 문제는 원본 문서에서 mksquashfs을 만들 때 -e boot로 부트 디렉토리를 제외해서 발생하는 문제입니다.

설치 후: 위와 같이 하면, 설치 후에 liveuser로 로그인되고, 자동 로그인이 켜져 있어서, liveuser를 지우고, /etc/gdm3/daemon.conf 파일을 원래대로 만들어 주어야 합니다. 따라서, 위와 같이 수정하지 않고 루트 사용자의 암호도 만들지 않고 루트 사용자로 자동 로그인이 되도록 설정하는 것이 필요해 보입니다.

자동 로그인: 데비안 /etc/gdm3/daemon.conf 파일의 내용입니다:

AutomaticLoginEnable=true

AutomaticLogin=user

TimedLoginEnable=true

TimedLogin=user

TimedLoginDelay=5

root 암호는 만들지 않은 것으로 보이고, user는 암호를 만든 것으로 보입니다.

문제점: 해당 사용자가 설치 후에도 남아 있고, 이 설정 파일이 원래대로 변경되지 않습니다. 어디서 고쳐야 하나요?

External Resources

How_to_create_a_custom_Ubuntu_live_from_scratch