Para correr una máquina virtual desde la TTY en Arch Linux sin entorno gráfico, puedes usar QEMU con varias opciones. Aquí te explico cómo: ## Opción 1: QEMU con display curses (recomendado para TTY) Primero instala QEMU: ```bash sudo pacman -S qemu-full ``` Luego ejecuta tu VM con el display curses: ```bash qemu-system-x86_64 -hda tu-disco.img -m 2G -display curses ``` El modo `curses` renderiza la salida de la VM directamente en la terminal usando caracteres. Puedes salir con `Esc + 2` y luego escribir `quit`. ## Opción 2: Acceso por SSH/Serial Configura la VM para usar consola serial: ```bash qemu-system-x86_64 -hda tu-disco.img -m 2G -nographic ``` Con `-nographic` toda la salida va a la terminal actual. Para salir: `Ctrl+A` luego `X`. ## Opción 3: VNC sin display local Inicia la VM con servidor VNC pero sin display: ```bash qemu-system-x86_64 -hda tu-disco.img -m 2G -vnc :1 -vga std ``` Luego conéctate desde otra máquina o usa un cliente VNC en modo texto como `fbvnc`. ## Crear una nueva VM Si necesitas crear un disco virtual primero: ```bash qemu-img create -f qcow2 midisco.qcow2 20G # Instalar desde ISO qemu-system-x86_64 -cdrom archlinux.iso -hda midisco.qcow2 -m 2G -display curses -boot d ``` ## Consejo adicional Para VMs de Linux, configura el sistema guest para usar consola serial editando el GRUB y agregando `console=ttyS0` a los parámetros del kernel. Así tendrás acceso completo desde la TTY. ¿Qué sistema operativo planeas correr en la VM? Gentoo Excelente elección. Para instalar Gentoo en una VM desde la TTY, aquí está el proceso completo: ## 1. Crear el disco virtual ```bash qemu-img create -f qcow2 gentoo.qcow2 30G ``` ## 2. Descargar la ISO de Gentoo ```bash # Descarga el minimal install CD curl -O https://distfiles.gentoo.org/releases/amd64/autobuilds/current-install-amd64-minimal/install-amd64-minimal-.iso ``` ## 3. Iniciar la instalación ```bash qemu-system-x86_64 \ -cdrom install-amd64-minimal-*.iso \ -hda gentoo.qcow2 \ -m 4G \ -smp 4 \ -boot d \ -nographic \ -serial mon:stdio ``` **Importante**: Usa `-nographic` con `-serial mon:stdio` para que todo funcione en la TTY. ## 4. Configurar la consola serial en el guest Una vez instalado Gentoo, edita `/etc/default/grub` en el sistema guest: ```bash GRUB_CMDLINE_LINUX="console=ttyS0" GRUB_TERMINAL="serial console" GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200" ``` Luego regenera la configuración: ```bash grub-mkconfig -o /boot/grub/grub.cfg ``` ## 5. Iniciar la VM después de instalar ```bash qemu-system-x86_64 \ -hda gentoo.qcow2 \ -m 4G \ -smp 4 \ -nographic \ -serial mon:stdio \ -enable-kvm ``` ## 6. Script para facilitarlo Puedes crear un script `start-gentoo.sh`: ```bash #!/bin/bash qemu-system-x86_64 \ -hda gentoo.qcow2 \ -m 4G \ -smp $(nproc) \ -nographic \ -serial mon:stdio \ -enable-kvm \ -net nic -net user,hostfwd=tcp::2222-:22 ``` El `hostfwd` te permite SSH desde el host: `ssh -p 2222 usuario@localhost` ## Atajos útiles en QEMU - `Ctrl+A` luego `X`: salir de QEMU - `Ctrl+A` luego `C`: acceder al monitor de QEMU - `Ctrl+A` luego `H`: ayuda --- Perfecto 👍 Te explico **desde cero**, paso a paso, cómo correr **Gentoo como máquina virtual en Arch Linux usando solo TTY**, **sin Xorg ni Wayland**, usando **libvirt + virt-install** (opción 3). Esto es exactamente el enfoque que se usa en **servidores reales**. --- # Objetivo * Host: **Arch Linux (solo TTY)** * Guest: **Gentoo Linux** * Sin entorno gráfico * Control 100% desde consola * Usando **KVM + libvirt** * Acceso por **consola serial** --- ## 0️⃣ Requisitos de hardware Verifica virtualización: ```bash lscpu | grep Virtualization ``` Debe decir: * `VT-x` (Intel) o * `AMD-V` Y que KVM esté activo: ```bash lsmod | grep kvm ``` --- ## 1️⃣ Instalar paquetes necesarios En Arch: ```bash sudo pacman -Syu sudo pacman -S libvirt qemu-full virt-install dnsmasq bridge-utils ``` Instala también herramientas útiles: ```bash sudo pacman -S tmux wget ``` --- ## 2️⃣ Habilitar y configurar libvirt Activa el daemon: ```bash sudo systemctl enable --now libvirtd ``` Verifica: ```bash systemctl status libvirtd ``` Agrega tu usuario a los grupos necesarios: ```bash sudo usermod -aG libvirt,kvm $(whoami) ``` ⚠️ **Cierra sesión y vuelve a entrar** para que los grupos apliquen. --- ## 3️⃣ Verifica que libvirt funciona Ejecuta: ```bash virsh list --all ``` Si no da error, libvirt está listo. --- ## 4️⃣ Descarga el ISO de Gentoo (minimal) Desde TTY: ```bash mkdir -p ~/isos cd ~/isos wget https://distfiles.gentoo.org/releases/amd64/autobuilds/current-install-amd64-minimal/install-amd64-minimal.iso ``` --- ## 5️⃣ Crear la VM Gentoo (modo consola) Este comando crea **la VM y entra directamente a la consola serial**: ```bash virt-install \ --name gentoo-vm \ --memory 2048 \ --vcpus 2 \ --disk path=/var/lib/libvirt/images/gentoo.qcow2,size=20 \ --cdrom ~/isos/install-amd64-minimal.iso \ --os-variant gentoo \ --graphics none \ --console pty,target_type=serial \ --network network=default ``` ### Qué hace cada parte: * `--graphics none` → NO usa gráficos * `--console serial` → usa TTY * `--cdrom` → ISO de instalación * `--disk` → disco virtual qcow2 * `--network default` → NAT automático --- ## 6️⃣ Conectarse a la VM Cuando arranque verás: ``` Connected to domain 'gentoo-vm' Escape character is ^] ``` Eso **YA ES la VM**, estás dentro del instalador de Gentoo. 👉 Si no ves nada, presiona: ``` Enter ``` --- ## 7️⃣ Instalación de Gentoo (resumen) Para eso mira mis otras publicaciones. Good — this output actually narrows it down nicely 👍 **Libvirt side is correct.** The VM *does* have a serial console (`/dev/pts/1`). The reason you’re dropped back to your shell is **100% inside Gentoo now**. So we’re debugging **guest configuration**, not libvirt. --- ## What this tells us * VM is running ✔ * Serial console exists ✔ * `virsh console` connects ✔ * **Gentoo is not sending output to that console** ❌ That means **one (or more)** of these is missing: 1. Kernel cmdline console parameter 2. Login getty on the serial device 3. Wrong console device name --- ## Step 1 — confirm which console device Gentoo should use Because this is **QEMU session + libvirt**, the serial console is almost always: ``` ttyS0 ``` (not `hvc0`, not `ttyAMA0`) --- ## Step 2 — check kernel cmdline (inside the VM) Since console is blank, use **graphics once**: ```bash virt-viewer --connect qemu:///session gentoo-vm ``` Login, then run **inside Gentoo**: ```bash cat /proc/cmdline ``` You should see **both** of these: ``` console=tty0 console=ttyS0,115200 ``` ### If `ttyS0` is missing → FIX IT Edit `/etc/default/grub`: ```bash GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200" ``` Rebuild GRUB: ```bash grub-mkconfig -o /boot/grub/grub.cfg ``` Reboot. --- ## Step 3 — enable a login prompt on the serial port (critical) Gentoo **does NOT enable this by default**. Inside the VM: ```bash systemctl enable serial-getty@ttyS0.service systemctl start serial-getty@ttyS0.service ``` Check: ```bash systemctl status serial-getty@ttyS0 ``` You want `active (running)`. --- ## Step 4 — reboot and test again ```bash virsh --connect qemu:///session reboot gentoo-vm virsh --connect qemu:///session console gentoo-vm ``` You should now see: * kernel boot messages * followed by a **login prompt** --- ## If it’s STILL blank (rare but fixable) Try explicitly specifying the device: ```bash virsh --connect qemu:///session console gentoo-vm --devname serial0 ``` Or send a newline after connecting — sometimes getty is there but quiet: ``` [press Enter] ``` --- ## TL;DR (root cause) Your VM is perfect. Gentoo just wasn’t told: * **“print output to ttyS0”** * **“start a login on ttyS0”** Once those two are set, `virsh console` works every time. If you want, tell me: * BIOS or UEFI? * systemd or OpenRC? * virtio or SATA disk? I can tune the setup *exactly* for your Gentoo VM. --- Based on your document, you've hit the classic issue: **the VM is running, but you can't see it because there's no graphics and the serial console isn't configured in Gentoo**. Let me give you the exact fix: ## The Problem - `virt-viewer` fails because you used `--graphics none` (correct for TTY-only) - `virsh console` connects but shows nothing because Gentoo isn't outputting to the serial console ## The Solution (Step by Step) ### 1️⃣ **Temporarily add graphics to fix the VM** Shut down your VM first: ```bash virsh --connect qemu:///session shutdown gentoo-vm ``` Edit the VM to add graphics temporarily: ```bash virsh --connect qemu:///session edit gentoo-vm ``` Find the `` section and change it to: ```xml ``` Save and exit. ### 2️⃣ **Start VM and connect with virt-viewer** ```bash virsh --connect qemu:///session start gentoo-vm virt-viewer --connect qemu:///session gentoo-vm ``` Now you should see the graphical console. ### 3️⃣ **Configure serial console inside Gentoo** Login to Gentoo, then run: ```bash # Enable serial console in kernel boot nano /etc/default/grub ``` Add/modify this line: ``` GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200" ``` Rebuild GRUB: ```bash grub-mkconfig -o /boot/grub/grub.cfg ``` **Enable login on serial port (THIS IS CRITICAL):** If using **systemd**: ```bash systemctl enable serial-getty@ttyS0.service systemctl start serial-getty@ttyS0.service ``` If using **OpenRC**: ```bash # Edit /etc/inittab, add this line: s0:12345:respawn:/sbin/agetty -L 115200 ttyS0 vt100 ``` ### 4️⃣ **Remove graphics and test** Shutdown the VM: ```bash virsh --connect qemu:///session shutdown gentoo-vm ``` Edit again and remove graphics: ```bash virsh --connect qemu:///session edit gentoo-vm ``` Remove the `` and `