다음을 사용하여 생성된 부트스트랩된 Debian 이미지가 있습니다.
qemu-img create -f qcow2 disk.qcow2 16G
su
export PATH=$PATH:/sbin:/usr/sbin
export TERM=xterm
modprobe nbd
qemu-nbd --connect=/dev/nbd0 disk.qcow2 --cache=unsafe --discard=unmap
parted --align optimal --script --machine --fix /dev/nbd0 -- \
mklabel gpt \
mkpart efi fat32 '0%' 500MiB \
set 1 boot on \
mkpart swap linux-swap 500MiB 1GiB \
mkpart root ext4 1GiB '100%'
mkfs.vfat -F 32 /dev/nbd0p1
mkswap /dev/nbd0p2
mkfs.ext4 /dev/nbd0p3
mkdir -p disk
mount /dev/nbd0p3 disk
debootstrap --arch amd64 bullseye ./disk
mkdir -p ./disk/boot/efi
mount /dev/nbd0p1 ./disk/boot/efi
mount --bind /dev ./disk/dev
mount -t devpts /dev/pts ./disk/dev/pts
mount -t proc proc ./disk/proc
mount -t sysfs sysfs ./disk/sys
mount -t tmpfs tmpfs ./disk/tmp
chroot ./disk
echo -e 'password\npassword' | passwd
echo debian > /etc/hostname
UUID1=$(blkid /dev/nbd0p1 | grep -Eo ' UUID="[^ ]*"' | sed 's/[" ]//g')
UUID2=$(blkid /dev/nbd0p2 | grep -Eo ' UUID="[^ ]*"' | sed 's/[" ]//g')
UUID3=$(blkid /dev/nbd0p3 | grep -Eo ' UUID="[^ ]*"' | sed 's/[" ]//g')
echo "none /tmp tmpfs defaults 0 0" > /etc/fstab
echo "$UUID1 /boot/efi vfat defaults 0 2" >> /etc/fstab
echo "$UUID2 none swap sw 0 0" >> /etc/fstab
echo "$UUID3 / ext4 errors=remount-ro 0 1" >> /etc/fstab
cat > /etc/apt/sources.list << __EOF__
deb http://deb.debian.org/debian/ bullseye main
deb-src http://deb.debian.org/debian/ bullseye main
deb http://deb.debian.org/debian/ bullseye-updates main
deb-src http://mirror.mephi.ru/debian/ bullseye-updates main
deb http://deb.debian.org/debian-security/ bullseye-security main
deb-src http://deb.debian.org/debian-security/ bullseye-security main
__EOF__
export DEBIAN_FRONTEND=noninteractive
export LANG="C.UTF-8"
apt-get update
apt-get upgrade
systemctl enable [email protected]
systemctl enable systemd-networkd.service
cat > /etc/systemd/network/80-dhcp.network << __EOF__
[Match]
Name=en*
[Network]
DHCP=yes
__EOF__
apt-get install -y linux-image-5.10.0-8-amd64 grub-efi
apt-get clean
apt-get autoclean
rm -rf /var/lib/apt/lists/*
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --no-nvram /dev/nbd0
echo 'GRUB_DISABLE_OS_PROBER=true' >> /etc/default/grub
update-grub2
exit
for dev in tmp sys proc dev/pts dev boot/efi; do
umount ./disk/$dev
done
umount disk
rmdir disk
qemu-nbd --disconnect /dev/nbd0
exit
드라이브에서 커널 및 initrd 이미지를 복사하고 다음 명령을 사용하여 직접 부팅하면 이 이미지를 성공적으로 실행할 수 있습니다.
qemu-system-x86_64 \
-drive format=qcow2,file=disk.qcow2 \
-kernel vmlinuz \
-initrd initrd.img \
-cpu host -M q35 \
-enable-kvm \
-m 2G,maxmem=4G \
-device rtl8139,netdev=network0 \
-netdev user,id=network0 \
-append "root=/dev/sda3"
하지만 GRUB을 사용하여 디스크를 부팅하려고 하면하이 바이오스(기본 QEMU BIOS) 다음 명령을 사용하십시오.
qemu-system-x86_64 \
-drive format=qcow2,file=disk.qcow2 \
-boot c \
-cpu host -M q35 \
-enable-kvm \
-m 2G,maxmem=4G \
-device rtl8139,netdev=network0 \
-netdev user,id=network0
Booting from Hard Disk...
라인 에 붙어있습니다 .
그것을 사용할 때OVMF 전자 주입명령 사용
qemu-system-x86_64 \
-drive format=qcow2,file=disk.qcow2 \
-boot c \
-bios /usr/share/ovmf/OVMF.fd \
-cpu host -M q35 \
-enable-kvm \
-m 2G,maxmem=4G \
-device rtl8139,netdev=network0 \
-netdev user,id=network0
나는 오류 라인을 얻는다
BdsDxe: failed to load Boot0001 "UEFI QEMU DVD-ROM QM00005 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x2,0xFFFF,0x0): Not Found
BdsDxe: failed to load Boot0002 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0): Not Found
디스크에 GRUB을 로드하려면 어떻게 해야 합니까?
답변1
UEFI 버전이 작동하도록 할 수 없지만 BIOS 설치는 제대로 작동합니다.
다음은 QEMU에서 부팅 가능한 debootstrap 데비안을 얻는 전체 코드입니다:
qemu-img create -f qcow2 disk.qcow2 16G
su
export PATH=$PATH:/sbin:/usr/sbin
export TERM=xterm
modprobe nbd
qemu-nbd --connect=/dev/nbd0 disk.qcow2 --cache=unsafe --discard=unmap
parted --align optimal --script --machine --fix /dev/nbd0 -- \
mklabel gpt \
mkpart fat32 '0%' 2MiB \
set 1 bios_grub on \
mkpart swap linux-swap 2MiB 1GiB \
mkpart root ext4 1GiB '100%'
mkswap /dev/nbd0p2
mkfs.ext4 /dev/nbd0p3
mkdir -p disk
mount /dev/nbd0p3 disk
debootstrap --include=systemd-sysv --variant=minbase --arch amd64 bullseye ./disk
mount --bind /dev ./disk/dev
mount -t devpts /dev/pts ./disk/dev/pts
mount -t proc proc ./disk/proc
mount -t sysfs sysfs ./disk/sys
mount -t tmpfs tmpfs ./disk/tmp
chroot ./disk
echo -e 'password\npassword' | passwd
echo debian > /etc/hostname
UUID1=$(blkid /dev/nbd0p2 | grep -Eo ' UUID="[^ ]*"' | sed 's/[" ]//g')
UUID2=$(blkid /dev/nbd0p3 | grep -Eo ' UUID="[^ ]*"' | sed 's/[" ]//g')
echo "none /tmp tmpfs defaults 0 0" > /etc/fstab
echo "$UUID1 none swap sw 0 0" >> /etc/fstab
echo "$UUID2 / ext4 errors=remount-ro 0 1" >> /etc/fstab
cat > /etc/apt/sources.list << __EOF__
deb http://deb.debian.org/debian/ bullseye main
deb-src http://deb.debian.org/debian/ bullseye main
deb http://deb.debian.org/debian/ bullseye-updates main
deb-src http://mirror.mephi.ru/debian/ bullseye-updates main
deb http://deb.debian.org/debian-security/ bullseye-security main
deb-src http://deb.debian.org/debian-security/ bullseye-security main
__EOF__
export DEBIAN_FRONTEND=noninteractive
export LANG="C.UTF-8"
apt-get update
apt-get upgrade -y
systemctl enable [email protected]
systemctl enable systemd-networkd.service
cat > /etc/systemd/network/80-dhcp.network << __EOF__
[Match]
Name=en*
[Network]
DHCP=yes
__EOF__
apt-get install -y linux-image-5.10.0-8-amd64 grub2
apt-get clean
apt-get autoclean
rm -rf /var/lib/apt/lists/*
echo 'GRUB_DISABLE_OS_PROBER=true' >> /etc/default/grub
grub-install --target=i386-pc --recheck /dev/nbd0
update-grub2
exit
for dev in tmp sys proc dev/pts dev; do
umount ./disk/$dev
done
umount disk
rmdir disk
qemu-nbd --disconnect /dev/nbd0
exit
qemu-system-x86_64 \
-drive format=qcow2,file=disk.qcow2 \
-boot c \
-cpu host -M q35 \
-enable-kvm \
-m 2G,maxmem=4G \
-device rtl8139,netdev=network0 \
-netdev user,id=network0