domingo, 9 de octubre de 2022

Como arrancar linux kernel compilada con qemu

Basándome en las siguientes webs:

Booting a Custom Linux Kernel in QEMU and Debugging It With GDB

Manually booting the Linux kernel inside QEMU

 

Después de muchas pruebas he conseguido arrancar el kernel compilado desde qemu para probarlo.

El kernel probado es 6.0.0-rc2 y he ejecutado para configurarlo:

$ make defconfig
$ MAKEFLAGS="-j$(nproc)" BUILDDIR=/tmp/make make

después he ejecutado:

$ INSTALL_MOD_PATH=/tmp BUILDDIR=/tmp/make make modules_install

y he copiado la carpeta /tmp/lib/modules en /mnt/lib/ (en /mnt tiene que estar montado kernel-hd)

$ sudo cp -via /tmp/lib/modules/ /mnt/lib/

 

Actualmente (dom 09 oct 2022 20:30:46 CEST) tengo Archlinux con kernel 5.19.13-arch1-1 y qemu 7.1.0-8.

 

La línea a ejecutar es:

qemu-system-x86_64 -kernel arch/x86_64/boot/bzImage -initrd initramfs.img -m 4G -drive file=kernel-hd,index=0,media=disk,format=raw -append "root=/dev/sda rw"


Actualización el mar 11 oct 2022 21:29:33 CEST:

Si quieres tener internet, tienes que instalar networkmanager:

$ sudo mount kernel-hd /mnt

$ sudo pacstrap /mnt networkmanager

$ sudo umount /mnt

 

Y la línea a ejecutar es:

qemu-system-x86_64 -kernel arch/x86_64/boot/bzImage -initrd initramfs.img -m 4G -drive file=kernel-hd,index=0,media=disk,format=raw -append "root=/dev/sda rw" -net nic -net user,hostfwd=tcp::5022-:22


Dentro de la VM hay que ejecutar:

# systemctl start NetworkManager

# systemctl enable NetworkManager


Y ya tenemos internet dentro de la VM.


Actualizado mié 12 oct 2022 09:05:05 CEST

No hay comentarios:

Publicar un comentario