debian bootstrap without libvirt

    which kvm
    man kvm

    mkdir -p /etc/qemu/
    vi /etc/qemu/bridge.conf

    allow guestbr0

    vdisk=/root/guest1.ext4
    vdisk=/root/guest2.ext4
    vdisk=/root/guest3.ext4

    dd if=/dev/zero of=$vdisk bs=1G count=0 seek=10
    mkfs.ext4 $vdisk

    mkdir lala/
    mount -o loop $vdisk lala/

    # use same mirror as from host system
    cat /etc/apt/sources.list
    mirror=`cat /etc/apt/sources.list | awk '{print $2}'`

    apt install lsb-release debootstrap

    # use same release as host system
    lsb_release -cs
    time debootstrap --arch=amd64 `lsb_release -cs 2>/dev/null` lala/ $mirror

    cat > lala/etc/fstab <<-EOF # override
    /dev/vda1 / ext4 defaults 0 0
    proc /proc proc defaults 0 0
    tmpfs /tmp tmpfs rw,nodev,nosuid,noatime,relatime 0 0
    devpts /dev/pts devpts gid=5,mode=620 0 0
    EOF

    kvm -nic model=help

    # host kernel is not suitable for serial output?
    ls -lhF /boot/config*
    grep CONFIG_VIRTIO_CONSOLE /boot/config-6.1.0-32-cloud-amd64
    grep -i virtio /boot/config-6.1.0-32-cloud-amd64

    screen -S consoles

    vdisk=/root/guest1.ext4
    vdisk=/root/guest2.ext4
    vdisk=/root/guest3.ext4

    bridge=guestbr0

    # guest1
    mac=0a:01:01:01:01:01
    # guest2
    mac=0e:02:02:02:02:02
    # guest3
    mac=02:03:03:03:03:03

    # we are lucking we're doing a poc using nested virtualization here...
    ls -lhF /boot/vmlinuz*
    ls -lhF /boot/initrd*
    kernel=/boot/vmlinuz-6.1.0-32-cloud-amd64
    initrd=/boot/initrd.img-6.1.0-32-cloud-amd64

    # beware the path here needs to be /dev/vda not /dev/vda1
    kvm --enable-kvm -m 256 \
            -display curses -serial pty \
            -drive file=$vdisk,media=disk,if=virtio,format=raw \
            -kernel $kernel -initrd $initrd -append "ro root=/dev/vda net.ifnames=0 biosdevname=0 mitigations=off init=/bin/bash" \
            -nic bridge,br=guestbr0,model=virtio-net-pci,mac=$mac

            # -overcommit mem-lock=off \
            # -display none -nographic -serial pty \
            # -device virtio-serial-pci,id=serial0 \

HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun