Quellcode durchsuchen

Cambio nombre de README y contenido

Celestino Rey vor 7 Monaten
Ursprung
Commit
d0aed721a1
3 geänderte Dateien mit 510 neuen und 510 gelöschten Zeilen
  1. 0 398
      Complete Guide to KVM Virtualization.md
  2. 349 112
      README.md
  3. 161 0
      VMCreation.md

+ 0 - 398
Complete Guide to KVM Virtualization.md

@@ -1,398 +0,0 @@
-# Complete Guide to KVM Virtualization on Ubuntu 24.04 LTS
->KVM (Kernel-based Virtual Machine) is a powerful open-source virtualization technology that transforms Linux into a type-1 (bare-metal) hypervisor. With Ubuntu 24.04 LTS, KVM provides enterprise-grade virtualization capabilities that rival proprietary solutions while maintaining the flexibility and cost-effectiveness of open source.
-
-## Introduction
-
-KVM (Kernel-based Virtual Machine) is a powerful open-source virtualization technology that transforms Linux into a type-1 (bare-metal) hypervisor. With Ubuntu 24.04 LTS, KVM provides enterprise-grade virtualization capabilities that rival proprietary solutions while maintaining the flexibility and cost-effectiveness of open source.
-
-This comprehensive guide will walk you through setting up KVM on Ubuntu 24.04, creating virtual machines, and mastering essential management techniques. Whether you're building a home lab, deploying production workloads, or migrating from VMware, this tutorial provides everything you need to get started.
-
-## Prerequisites
-
-Before installing KVM, ensure your system meets these requirements:
-
-## Hardware Requirements
-
-CPU: 64-bit processor with hardware virtualization support
-Intel: VT-x (vmx flag)
-AMD: AMD-V (svm flag)
-RAM: Minimum 4GB (8GB+ recommended)
-Storage: At least 20GB free space for host OS and VMs
-Network: Ethernet adapter for bridge networking
-Verify Hardware Virtualization Support
-
-Check if your CPU supports virtualization:
-
-    # Check for Intel VT-x or AMD-V support
-    egrep -c '(vmx|svm)' /proc/cpuinfo
-
-    # If the output is greater than 0, virtualization is supported
-    # For detailed CPU flags
-    lscpu | grep Virtualization
-
-## Installing KVM on Ubuntu 24.04
-
-### Step 1: Update System Packages
-
-    sudo apt update && sudo apt upgrade -y
-
-### Step 2: Install KVM and Related Packages
-
-    sudo apt -y install qemu-kvm libvirt-daemon-system libvirt-daemon virtinst bridge-utils libosinfo-bin
-
-Package breakdown:
-
-* ```qemu-kvm```: The main KVM hypervisor
-* ```libvirt-daemon-system```: System daemon for managing VMs
-* ```libvirt-daemon```: Virtualization management daemon
-* ```virtinst```: Command-line tools for creating VMs
-* ```bridge-utils```: Utilities for configuring network bridges
-* ```libosinfo-bin```: Database of operating systems for optimal configurations
-
-### Step 3: Add User to Required Groups
-
-    # Add your user to libvirt and kvm groups
-    sudo usermod -aG libvirt $USER
-    sudo usermod -aG kvm $USER
-
-    # Apply group changes without logging out
-    newgrp libvirt
-    newgrp kvm
-
-### Step 4: Verify Installation
-
-    # Check if KVM modules are loaded
-    lsmod | grep kvm
-    # Verify libvirt service is running
-    sudo systemctl status libvirtd
-    # Test virsh command
-    virsh list --all
-
-## Configuring Bridge Networking
-
-Bridge networking allows VMs to appear as physical hosts on your network, getting IP addresses from your DHCP server.
-
-### Step 1: Identify Your Network Interface
-
-    ip addr show
-    # Note your primary interface name (e.g., enp1s0, eth0)
-
-### Step 2: Configure Netplan for Bridge Networking
-
-Edit your Netplan configuration:
-
-    sudo vi /etc/netplan/50-cloud-init.yaml
-
-Replace the content with:
-
-    network:
-    version: 2
-    ethernets:
-        enp4s0:
-        dhcp4: true
-    bridges:
-        br0:
-        dhcp4: yes
-        interfaces:
-            - enp4s0
-
-Substitute ```enp4s0``` with the interface from Step 1 above.
-
-### Step 3: Apply Network Configuration
-
-    # Apply the new configuration
-    sudo netplan apply
-    # Verify bridge creation
-    ip addr show br0
-    brctl show
-
-## Creating Your First Virtual Machine
-
-### Option 1: Command-Line Installation with virt-install
-
-This method provides full control over VM creation:
-
-    ​​​​​​​# Create a directory for VM images
-    sudo mkdir -p /var/kvm/images
-
-    # Download Ubuntu 24.04 Server ISO
-    wget https://releases.ubuntu.com/24.04/ubuntu-24.04-live-server-amd64.iso
-
-    # Create VM with virt-install
-    sudo virt-install \
-    --name ubuntu-vm1 \
-    --ram 4096 \
-    --disk path=/var/kvm/images/ubuntu-vm1.img,size=20 \
-    --vcpus 2 \
-    --os-variant ubuntu24.04 \
-    --network bridge=br0 \
-    --graphics none \
-    --console pty,target_type=serial \
-    --location /path/to/ubuntu-24.04-live-server-amd64.iso,kernel=casper/vmlinuz,initrd=casper/initrd \
-    --extra-args 'console=ttyS0,115200n8'
-
-### Option 2: Using virt-manager GUI
-
-For desktop users, install the graphical interface:
-
-    ​sudo apt install virt-manager
-    # Launch virt-manager
-    virt-manager
-
-#### Understanding virt-install Parameters
-
-| Parameter	| Description |
-| --------- | ----------- |
-| ```--name```	| VM name (must be unique) |
-| ```--ram```	| 	Memory allocation in MB |
-| ```--disk```	| 	Disk configuration (path and size) |
-| ```--vcpus```	| 	Number of virtual CPUs |
-| ```--os-variant```	| 	OS type for optimization |
-| ```--network```	| 	Network configuration |
-| ```--graphics```	| 	Display type (none for headless) |
-| ```--console```	| 	Console connection type |
-
-## Essential VM Management Commands
-
-#### Starting and Stopping VMs
-
-    ​​​​​​​# Start a VM
-    virsh start ubuntu-vm1
-    # Start and connect to console
-    virsh start ubuntu-vm1 --console
-    # Graceful shutdown
-    virsh shutdown ubuntu-vm1
-    # Force stop (use cautiously)
-    virsh destroy ubuntu-vm1
-    # Reboot VM
-    virsh reboot ubuntu-vm1
-
-#### Listing and Monitoring VMs
-
-    ​​​​​​​# List running VMs
-    virsh list
-    # List all VMs (including stopped)
-    virsh list --all
-    # Show VM information
-    virsh dominfo ubuntu-vm1
-    # Display VM configuration
-    virsh dumpxml ubuntu-vm1
-
-#### Console Access
-
-    # Connect to VM console
-    virsh console ubuntu-vm1
-    # Exit console: Ctrl + ]
-
-#### Auto-start Configuration
-
-    # Enable auto-start
-    virsh autostart ubuntu-vm1
-    # Disable auto-start
-    virsh autostart --disable ubuntu-vm1
-
-
-## Storage Management
-
-### Creating Storage Pools
-
-    ​​​​​​​# Create a new storage pool directory
-    sudo mkdir -p /var/lib/libvirt/images/vmpool
-    # Define the storage pool
-    virsh pool-define-as vmpool dir - - - - "/var/lib/libvirt/images/vmpool"
-    # Start the pool
-    virsh pool-start vmpool
-    # Enable auto-start
-    virsh pool-autostart vmpool
-    # List storage pools
-    virsh pool-list --all
-
-### Managing Virtual Disks
-
-    ​​​​​​​# Create a new disk
-    virsh vol-create-as vmpool ubuntu-vm2.qcow2 30G --format qcow2
-    # List volumes in a pool
-    virsh vol-list vmpool
-    # Delete a volume
-    virsh vol-delete ubuntu-vm2.qcow2 --pool vmpool
-
-## Advanced VM Management Tools
-
-### Install Management Utilities
-
-​​​​    ​​​sudo apt -y install libguestfs-tools virt-top
-
-### Using libguestfs Tools
-
-    ​​​​​​​# List files in VM
-    virt-ls -l -d ubuntu-vm1 /etc
-    # View file content
-    virt-cat -d ubuntu-vm1 /etc/hostname
-    # Edit files in VM (while stopped)
-    virt-edit -d ubuntu-vm1 /etc/hosts
-    # Check disk usage
-    virt-df -d ubuntu-vm1
-    # Mount VM filesystem
-    sudo guestmount -d ubuntu-vm1 -i /mnt
-    sudo umount /mnt
-
-### Real-time Monitoring with virt-top
-
-    # Monitor VM performance
-    virt-top
-    # Sort by CPU usage: shift + P
-    # Sort by memory: shift + M
-    # Help: h
-    # Quit: q
-
-## VM Cloning and Snapshots
-
-### Cloning VMs
-
-    # Clone a VM
-    virt-clone --original ubuntu-vm1 --name ubuntu-vm2 --file /var/kvm/images/ubuntu-vm2.img
-    # Clone with auto-generated storage
-virt-clone --original ubuntu-vm1 --name ubuntu-vm3 --auto-clone
-
-### Managing Snapshots
-
-    # Create snapshot
-    virsh snapshot-create-as ubuntu-vm1 --name "before-updates" --description "Clean install"
-    # List snapshots
-    virsh snapshot-list ubuntu-vm1
-    # Revert to snapshot
-    virsh snapshot-revert ubuntu-vm1 "before-updates"
-    # Delete snapshot
-    virsh snapshot-delete ubuntu-vm1 "before-updates"
-
-## Nested Virtualization
-
-Enable nested virtualization to run VMs inside VMs:
-
-### Check Current Status
-
-    # For Intel
-    cat /sys/module/kvm_intel/parameters/nested
-    # For AMD
-    cat /sys/module/kvm_amd/parameters/nested
-
-### Enable Nested Virtualization
-
-    ​​​​​​​# For Intel CPUs
-    echo 'options kvm_intel nested=1' | sudo tee /etc/modprobe.d/kvm-intel.conf
-    # For AMD CPUs
-    echo 'options kvm_amd nested=1' | sudo tee /etc/modprobe.d/kvm-amd.conf
-    # Reload module (Intel example)
-    sudo modprobe -r kvm_intel
-    sudo modprobe kvm_intel
-
-### Configure VM for Nested Virtualization
-
-    # Edit VM configuration
-    virsh edit ubuntu-vm1
-    # Add or modify CPU configuration:
-    <cpu mode='host-passthrough' check='none' migratable='on'/>
-
-## Performance Optimization
-
-### CPU Pinning
-
-    ​​​​​​​# Pin vCPUs to physical CPUs
-    virsh vcpupin ubuntu-vm1 0 0
-    virsh vcpupin ubuntu-vm1 1 1
-
-## Memory Optimization
-
-    ​​​​​​​# Set memory balloon
-    virsh setmem ubuntu-vm1 2048M --config
-    # Enable hugepages
-    echo 'vm.nr_hugepages = 1024' | sudo tee -a /etc/sysctl.conf
-    sudo sysctl -p
-
-## Disk I/O Optimization
-
-Use VirtIO drivers and cache modes:
-
-    ​​​​​​​<disk type='file' device='disk'>
-    <driver name='qemu' type='qcow2' cache='writeback' io='threads'/>
-    <source file='/var/kvm/images/ubuntu-vm1.img'/>
-    <target dev='vda' bus='virtio'/>
-    </disk>
-
-## Backup and Migration
-
-### Backup VMs
-
-    ​​​​​​​# Backup VM configuration
-    virsh dumpxml ubuntu-vm1 > ubuntu-vm1.xml
-    # Backup disk image
-    sudo cp /var/kvm/images/ubuntu-vm1.img /backup/
-    # Create compressed backup
-    sudo qemu-img convert -c -O qcow2 /var/kvm/images/ubuntu-vm1.img /backup/ubuntu-vm1-backup.qcow2
-
-### Live Migration (requires shared storage)
-
-    # Migrate to another host
-    virsh migrate --live ubuntu-vm1 qemu+ssh://dest-host/system
-
-### Troubleshooting Common Issues
-
-#### VM Won't Start
-
-    # Check logs
-    journalctl -u libvirtd -f
-    # Verify VM configuration
-    virsh domblklist ubuntu-vm1
-    virsh domiflist ubuntu-vm1
-    # Check for errors
-    virsh start ubuntu-vm1 --console
-
-#### Network Issues
-
-    # Verify bridge configuration
-    brctl show
-    ip addr show br0
-    # Check VM network
-    virsh domiflist ubuntu-vm1
-    virsh domifaddr ubuntu-vm1
-
-#### Permission Issues
-
-    # Fix ownership
-    sudo chown -R libvirt-qemu:kvm /var/lib/libvirt/images/
-    # Check AppArmor
-    sudo aa-status
-
-### Security Best Practices
-
-#### Regular Updates
-    sudo apt update && sudo apt upgrade
-
-#### Firewall Configuration
-    sudo ufw allow 22/tcp
-	sudo ufw enable
-
-#### SELinux/AppArmor
-* Keep security modules enabled
-* Update policies as needed
-#### Resource Limits
-* Set CPU and memory limits
-* Use cgroups for resource control
-#### Network Isolation
-* Use VLANs for network segmentation
-* Implement firewall rules between VMs
-
-## Conclusion
-
-KVM on Ubuntu 24.04 provides a robust, enterprise-ready virtualization platform that's both powerful and free. With features like live migration, snapshots, and nested virtualization, it rivals commercial hypervisors while maintaining the flexibility of open source.
-
-Whether you're running a home lab, development environment, or production infrastructure, KVM offers the tools and performance needed for modern virtualization workloads. The combination of command-line tools and graphical interfaces makes it accessible to both beginners and advanced users.
-
-As you continue your virtualization journey, explore advanced features like:
-
-* GPU passthrough for graphics-intensive workloads
-* SR-IOV for high-performance networking
-* Integration with cloud platforms like OpenStack
-* Automation with tools like Terraform and Ansible
-
-With Ubuntu 24.04 LTS's five-year support cycle, you have a stable foundation for building and maintaining your virtualized infrastructure.

+ 349 - 112
README.md

@@ -1,161 +1,398 @@
-# Notas sobre la creación de VM
+# Complete Guide to KVM Virtualization on Ubuntu 24.04 LTS
+>KVM (Kernel-based Virtual Machine) is a powerful open-source virtualization technology that transforms Linux into a type-1 (bare-metal) hypervisor. With Ubuntu 24.04 LTS, KVM provides enterprise-grade virtualization capabilities that rival proprietary solutions while maintaining the flexibility and cost-effectiveness of open source.
 
-## Comando general para lanzar la VM
+## Introduction
 
-Lo encontré en [este enlace](https://wiki.debian.org/KVM#Introduction)
+KVM (Kernel-based Virtual Machine) is a powerful open-source virtualization technology that transforms Linux into a type-1 (bare-metal) hypervisor. With Ubuntu 24.04 LTS, KVM provides enterprise-grade virtualization capabilities that rival proprietary solutions while maintaining the flexibility and cost-effectiveness of open source.
 
-## Corregir error de desconexión de monitor
+This comprehensive guide will walk you through setting up KVM on Ubuntu 24.04, creating virtual machines, and mastering essential management techniques. Whether you're building a home lab, deploying production workloads, or migrating from VMware, this tutorial provides everything you need to get started.
 
-Para que no de error de que se desconecta del monitor, hay que modificar el fichero
+## Prerequisites
 
-    /etc/libvirt/qemu.conf
+Before installing KVM, ensure your system meets these requirements:
 
-y añadir las siguientes líneas (yo las puse al final del fichero)
+## Hardware Requirements
 
-    user = "root"
-    group = "root"
+CPU: 64-bit processor with hardware virtualization support
+Intel: VT-x (vmx flag)
+AMD: AMD-V (svm flag)
+RAM: Minimum 4GB (8GB+ recommended)
+Storage: At least 20GB free space for host OS and VMs
+Network: Ethernet adapter for bridge networking
+Verify Hardware Virtualization Support
 
+Check if your CPU supports virtualization:
 
-# Especificar initrd y kernel
+    # Check for Intel VT-x or AMD-V support
+    egrep -c '(vmx|svm)' /proc/cpuinfo
 
-| Distro |Kernel path|RAM disk path|
-|Fedora|/isolinux/vmlinuz|/isolinux/initrd.img|
-|RHEL5/CentOS5|/isolinux/vmlinuz|/isolinux/initrd.img|
-|openSUSE|/boot/i386/loader/linux|/boot/i386/loader/initrd|
-|Mandriva|/i586/isolinux/alt0/vmlinuz|/i586/isolinux/alt0/all.rdz|
-|Ubuntu|/casper/vmlinuz|/casper/initrd.gz or /casper/initrd|
-|Debian|/install.386/vmlinuz/|/isolinux/initrd.img|
+    # If the output is greater than 0, virtualization is supported
+    # For detailed CPU flags
+    lscpu | grep Virtualization
 
+## Installing KVM on Ubuntu 24.04
 
-## Relocate an existing libvirtd (KVM) images directory
-By default, KVM (libvirtd) images on Ubuntu and most other Linux distributions are found in /var/lib/libvirt/images. This can be inconvenient if you don't have a separate /var partition that can grow over time to accommodate multiple large images.
+### Step 1: Update System Packages
 
-You _can_ simply rename the images folder to something else and then symlink to a larger space with it (e.g. ```ln -s /data1/libvirt/images /var/lib/libvirt/images```). That's what I used to do.
+    sudo apt update && sudo apt upgrade -y
 
-But that can lead to all sorts of unanticipated trouble. The _right_ way to have your images on a bigger disk is to change the path for libvirt's default storage pool to a partition on that big disk, which is logically where KVM is going to create them.
+### Step 2: Install KVM and Related Packages
 
-NOTE: The Ubuntu package for libvirt-daemon-system automatically sets up a [libvirt group](https://documentation.ubuntu.com/server/how-to/virtualisation/libvirt/) for libvirt admins (that includes members of the sudo group by default). Members of libvirt can run virsh commands without sudo. YMMV if not a member of the sudo group, or not on Ubuntu.
+    sudo apt -y install qemu-kvm libvirt-daemon-system libvirt-daemon virtinst bridge-utils libosinfo-bin
 
-First check to make sure a default pool exists:
+Package breakdown:
 
-```bash
-$ virsh pool-list --all
- Name      State    Autostart
--------------------------------
- default   active   yes
-```
+* ```qemu-kvm```: The main KVM hypervisor
+* ```libvirt-daemon-system```: System daemon for managing VMs
+* ```libvirt-daemon```: Virtualization management daemon
+* ```virtinst```: Command-line tools for creating VMs
+* ```bridge-utils```: Utilities for configuring network bridges
+* ```libosinfo-bin```: Database of operating systems for optimal configurations
 
-**NOTE: If no default pool exists, follow the instructions in [this gist](https://gist.github.com/plembo/13ce29c9279807adfd9bd6b959f43fac) to create one on your preferred storage volume.**
+### Step 3: Add User to Required Groups
 
-Assuming a default pool exists, find the current default pool's path:
+    # Add your user to libvirt and kvm groups
+    sudo usermod -aG libvirt $USER
+    sudo usermod -aG kvm $USER
 
-```xml
-$ virsh pool-dumpxml default
-<pool type='dir'>
-  <name>default</name>
-  <uuid>91c6d1b3-4e42-4a1f-989e-89b2127da056</uuid>
-  <capacity unit='bytes'>133070688256</capacity>
-  <allocation unit='bytes'>25177309184</allocation>
-  <available unit='bytes'>107893379072</available>
-  <source>
-  </source>
-  <target>
-    <path>/var/lib/libvirt/images</path>
-    <permissions>
-      <mode>0711</mode>
-      <owner>64055</owner>
-      <group>108</group>
-    </permissions>
-  </target>
-</pool>
-```
+    # Apply group changes without logging out
+    newgrp libvirt
+    newgrp kvm
 
-Before going further it is best to shut down ("destroy") all existing virtual machines).
+### Step 4: Verify Installation
 
-Now use ```virsh edit``` to change the disk path in each virtual machines's configuration to the default pool's new location. Assuming this will be "/data1/libvirt/images", you would proceed like this:
+    # Check if KVM modules are loaded
+    lsmod | grep kvm
+    # Verify libvirt service is running
+    sudo systemctl status libvirtd
+    # Test virsh command
+    virsh list --all
 
-```xml
-$ virsh edit example
-...
-<disk type='file' device='disk'>
-    <driver name='qemu' type='qcow2'/>
--   <source file='/var/lib/libvirt/images/example.qcow2'/>
-+   <source file='/data1/libvirt/images/example.qcow2'/>
-```
-(the line will then read ```<source file='/data1/libvirt/images/example.qcow2'```
+## Configuring Bridge Networking
 
-Next, the default pool should be completely shut down:
+Bridge networking allows VMs to appear as physical hosts on your network, getting IP addresses from your DHCP server.
 
-```
-$ virsh pool-destroy default
-```
-Then, undefined:
+### Step 1: Identify Your Network Interface
 
-```
-$ virsh pool-undefine default
-```
-NOTE: By default, virt-manager creates additional pools automatically for things like iso files. These should also be destroyed and undefined before proceeding, to free things up for redefining the default pool (if you don't, the system will spit out "error: operation failed: Storage source conflict with pool" messages when you try redefining).
+    ip addr show
+    # Note your primary interface name (e.g., enp1s0, eth0)
 
-Now, recreate the default pool anew and start:
+### Step 2: Configure Netplan for Bridge Networking
 
-```bash
-$ virsh pool-define-as default dir --target "/data1/libvirt/images"
-$ virsh pool-build default
-$ virsh pool-start default
-$ virsh pool-autostart default
-```
+Edit your Netplan configuration:
 
-Check the status with virsh-info:
-```bash
-$ virsh pool-info default
-```
+    sudo vi /etc/netplan/50-cloud-init.yaml
 
-And then the configuration with pool-dumpxml:
+Replace the content with:
 
-```bash
-$ virsh pool-dumpxml default
-```
+    network:
+    version: 2
+    ethernets:
+        enp4s0:
+        dhcp4: true
+    bridges:
+        br0:
+        dhcp4: yes
+        interfaces:
+            - enp4s0
 
-Finally, move any existing disk images from /var/lib/libvirt/images to the new location (e.g. /data1/libvirt/images).
+Substitute ```enp4s0``` with the interface from Step 1 above.
 
+### Step 3: Apply Network Configuration
 
-## Cambiar el interfaz de red de una VM
+    # Apply the new configuration
+    sudo netplan apply
+    # Verify bridge creation
+    ip addr show br0
+    brctl show
 
-To change a VM's network with virsh, you can either edit the VM's XML configuration using virsh edit and then restart the VM, or use virsh net-edit to modify the network itself and then restart the network. The most common method is to shut down the VM, edit its XML definition, and then start it again. For network-wide changes, you can edit the network's XML definition and then restart the network to apply the changes. 
+## Creating Your First Virtual Machine
 
-### Method 1: Editing the VM's network configuration
+### Option 1: Command-Line Installation with virt-install
 
-This method is for when you want to change the network attached to a specific VM.
+This method provides full control over VM creation:
 
-1. Shut down the VM:
-    virsh shutdown <vm_name>
-2. Edit the VM's XML:
-    virsh edit <vm_name>
+    ​​​​​​​# Create a directory for VM images
+    sudo mkdir -p /var/kvm/images
 
-This will open the VM's XML file in a text editor. Find the <interface> section for the network you want to change.
+    # Download Ubuntu 24.04 Server ISO
+    wget https://releases.ubuntu.com/24.04/ubuntu-24.04-live-server-amd64.iso
 
-    <interface type='network'>
-      <mac address='52:54:00:7a:a0:cd'/>
--      <source network='default'/>
-+      <source network='hostbridge'/>
-      <model type='virtio'/>
-      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
-    </interface>
+    # Create VM with virt-install
+    sudo virt-install \
+    --name ubuntu-vm1 \
+    --ram 4096 \
+    --disk path=/var/kvm/images/ubuntu-vm1.img,size=20 \
+    --vcpus 2 \
+    --os-variant ubuntu24.04 \
+    --network bridge=br0 \
+    --graphics none \
+    --console pty,target_type=serial \
+    --location /path/to/ubuntu-24.04-live-server-amd64.iso,kernel=casper/vmlinuz,initrd=casper/initrd \
+    --extra-args 'console=ttyS0,115200n8'
 
+### Option 2: Using virt-manager GUI
 
-3. Save and close the editor.
+For desktop users, install the graphical interface:
 
-Apply the changes:
+    ​sudo apt install virt-manager
+    # Launch virt-manager
+    virt-manager
 
-    virsh start <vm_name>
+#### Understanding virt-install Parameters
 
-The VM will start with the new network configuration. 
+| Parameter	| Description |
+| --------- | ----------- |
+| ```--name```	| VM name (must be unique) |
+| ```--ram```	| 	Memory allocation in MB |
+| ```--disk```	| 	Disk configuration (path and size) |
+| ```--vcpus```	| 	Number of virtual CPUs |
+| ```--os-variant```	| 	OS type for optimization |
+| ```--network```	| 	Network configuration |
+| ```--graphics```	| 	Display type (none for headless) |
+| ```--console```	| 	Console connection type |
 
+## Essential VM Management Commands
 
+#### Starting and Stopping VMs
 
-## Renombrar máquina
+    ​​​​​​​# Start a VM
+    virsh start ubuntu-vm1
+    # Start and connect to console
+    virsh start ubuntu-vm1 --console
+    # Graceful shutdown
+    virsh shutdown ubuntu-vm1
+    # Force stop (use cautiously)
+    virsh destroy ubuntu-vm1
+    # Reboot VM
+    virsh reboot ubuntu-vm1
 
-    virsh dumpxml myvm > foo.xml
-    <edit foo.xml, change the name, move storage>
-    virsh undefine myvm
-    virsh define foo.xml
+#### Listing and Monitoring VMs
+
+    ​​​​​​​# List running VMs
+    virsh list
+    # List all VMs (including stopped)
+    virsh list --all
+    # Show VM information
+    virsh dominfo ubuntu-vm1
+    # Display VM configuration
+    virsh dumpxml ubuntu-vm1
+
+#### Console Access
+
+    # Connect to VM console
+    virsh console ubuntu-vm1
+    # Exit console: Ctrl + ]
+
+#### Auto-start Configuration
+
+    # Enable auto-start
+    virsh autostart ubuntu-vm1
+    # Disable auto-start
+    virsh autostart --disable ubuntu-vm1
+
+
+## Storage Management
+
+### Creating Storage Pools
+
+    ​​​​​​​# Create a new storage pool directory
+    sudo mkdir -p /var/lib/libvirt/images/vmpool
+    # Define the storage pool
+    virsh pool-define-as vmpool dir - - - - "/var/lib/libvirt/images/vmpool"
+    # Start the pool
+    virsh pool-start vmpool
+    # Enable auto-start
+    virsh pool-autostart vmpool
+    # List storage pools
+    virsh pool-list --all
+
+### Managing Virtual Disks
+
+    ​​​​​​​# Create a new disk
+    virsh vol-create-as vmpool ubuntu-vm2.qcow2 30G --format qcow2
+    # List volumes in a pool
+    virsh vol-list vmpool
+    # Delete a volume
+    virsh vol-delete ubuntu-vm2.qcow2 --pool vmpool
+
+## Advanced VM Management Tools
+
+### Install Management Utilities
+
+​​​​    ​​​sudo apt -y install libguestfs-tools virt-top
+
+### Using libguestfs Tools
+
+    ​​​​​​​# List files in VM
+    virt-ls -l -d ubuntu-vm1 /etc
+    # View file content
+    virt-cat -d ubuntu-vm1 /etc/hostname
+    # Edit files in VM (while stopped)
+    virt-edit -d ubuntu-vm1 /etc/hosts
+    # Check disk usage
+    virt-df -d ubuntu-vm1
+    # Mount VM filesystem
+    sudo guestmount -d ubuntu-vm1 -i /mnt
+    sudo umount /mnt
+
+### Real-time Monitoring with virt-top
+
+    # Monitor VM performance
+    virt-top
+    # Sort by CPU usage: shift + P
+    # Sort by memory: shift + M
+    # Help: h
+    # Quit: q
+
+## VM Cloning and Snapshots
+
+### Cloning VMs
+
+    # Clone a VM
+    virt-clone --original ubuntu-vm1 --name ubuntu-vm2 --file /var/kvm/images/ubuntu-vm2.img
+    # Clone with auto-generated storage
+virt-clone --original ubuntu-vm1 --name ubuntu-vm3 --auto-clone
+
+### Managing Snapshots
+
+    # Create snapshot
+    virsh snapshot-create-as ubuntu-vm1 --name "before-updates" --description "Clean install"
+    # List snapshots
+    virsh snapshot-list ubuntu-vm1
+    # Revert to snapshot
+    virsh snapshot-revert ubuntu-vm1 "before-updates"
+    # Delete snapshot
+    virsh snapshot-delete ubuntu-vm1 "before-updates"
+
+## Nested Virtualization
+
+Enable nested virtualization to run VMs inside VMs:
+
+### Check Current Status
+
+    # For Intel
+    cat /sys/module/kvm_intel/parameters/nested
+    # For AMD
+    cat /sys/module/kvm_amd/parameters/nested
+
+### Enable Nested Virtualization
+
+    ​​​​​​​# For Intel CPUs
+    echo 'options kvm_intel nested=1' | sudo tee /etc/modprobe.d/kvm-intel.conf
+    # For AMD CPUs
+    echo 'options kvm_amd nested=1' | sudo tee /etc/modprobe.d/kvm-amd.conf
+    # Reload module (Intel example)
+    sudo modprobe -r kvm_intel
+    sudo modprobe kvm_intel
+
+### Configure VM for Nested Virtualization
+
+    # Edit VM configuration
+    virsh edit ubuntu-vm1
+    # Add or modify CPU configuration:
+    <cpu mode='host-passthrough' check='none' migratable='on'/>
+
+## Performance Optimization
+
+### CPU Pinning
+
+    ​​​​​​​# Pin vCPUs to physical CPUs
+    virsh vcpupin ubuntu-vm1 0 0
+    virsh vcpupin ubuntu-vm1 1 1
+
+## Memory Optimization
+
+    ​​​​​​​# Set memory balloon
+    virsh setmem ubuntu-vm1 2048M --config
+    # Enable hugepages
+    echo 'vm.nr_hugepages = 1024' | sudo tee -a /etc/sysctl.conf
+    sudo sysctl -p
+
+## Disk I/O Optimization
+
+Use VirtIO drivers and cache modes:
+
+    ​​​​​​​<disk type='file' device='disk'>
+    <driver name='qemu' type='qcow2' cache='writeback' io='threads'/>
+    <source file='/var/kvm/images/ubuntu-vm1.img'/>
+    <target dev='vda' bus='virtio'/>
+    </disk>
+
+## Backup and Migration
+
+### Backup VMs
+
+    ​​​​​​​# Backup VM configuration
+    virsh dumpxml ubuntu-vm1 > ubuntu-vm1.xml
+    # Backup disk image
+    sudo cp /var/kvm/images/ubuntu-vm1.img /backup/
+    # Create compressed backup
+    sudo qemu-img convert -c -O qcow2 /var/kvm/images/ubuntu-vm1.img /backup/ubuntu-vm1-backup.qcow2
+
+### Live Migration (requires shared storage)
+
+    # Migrate to another host
+    virsh migrate --live ubuntu-vm1 qemu+ssh://dest-host/system
+
+### Troubleshooting Common Issues
+
+#### VM Won't Start
+
+    # Check logs
+    journalctl -u libvirtd -f
+    # Verify VM configuration
+    virsh domblklist ubuntu-vm1
+    virsh domiflist ubuntu-vm1
+    # Check for errors
+    virsh start ubuntu-vm1 --console
+
+#### Network Issues
+
+    # Verify bridge configuration
+    brctl show
+    ip addr show br0
+    # Check VM network
+    virsh domiflist ubuntu-vm1
+    virsh domifaddr ubuntu-vm1
+
+#### Permission Issues
+
+    # Fix ownership
+    sudo chown -R libvirt-qemu:kvm /var/lib/libvirt/images/
+    # Check AppArmor
+    sudo aa-status
+
+### Security Best Practices
+
+#### Regular Updates
+    sudo apt update && sudo apt upgrade
+
+#### Firewall Configuration
+    sudo ufw allow 22/tcp
+	sudo ufw enable
+
+#### SELinux/AppArmor
+* Keep security modules enabled
+* Update policies as needed
+#### Resource Limits
+* Set CPU and memory limits
+* Use cgroups for resource control
+#### Network Isolation
+* Use VLANs for network segmentation
+* Implement firewall rules between VMs
+
+## Conclusion
+
+KVM on Ubuntu 24.04 provides a robust, enterprise-ready virtualization platform that's both powerful and free. With features like live migration, snapshots, and nested virtualization, it rivals commercial hypervisors while maintaining the flexibility of open source.
+
+Whether you're running a home lab, development environment, or production infrastructure, KVM offers the tools and performance needed for modern virtualization workloads. The combination of command-line tools and graphical interfaces makes it accessible to both beginners and advanced users.
+
+As you continue your virtualization journey, explore advanced features like:
+
+* GPU passthrough for graphics-intensive workloads
+* SR-IOV for high-performance networking
+* Integration with cloud platforms like OpenStack
+* Automation with tools like Terraform and Ansible
+
+With Ubuntu 24.04 LTS's five-year support cycle, you have a stable foundation for building and maintaining your virtualized infrastructure.

+ 161 - 0
VMCreation.md

@@ -0,0 +1,161 @@
+# Notas sobre la creación de VM
+
+## Comando general para lanzar la VM
+
+Lo encontré en [este enlace](https://wiki.debian.org/KVM#Introduction)
+
+## Corregir error de desconexión de monitor
+
+Para que no de error de que se desconecta del monitor, hay que modificar el fichero
+
+    /etc/libvirt/qemu.conf
+
+y añadir las siguientes líneas (yo las puse al final del fichero)
+
+    user = "root"
+    group = "root"
+
+
+# Especificar initrd y kernel
+
+| Distro |Kernel path|RAM disk path|
+|Fedora|/isolinux/vmlinuz|/isolinux/initrd.img|
+|RHEL5/CentOS5|/isolinux/vmlinuz|/isolinux/initrd.img|
+|openSUSE|/boot/i386/loader/linux|/boot/i386/loader/initrd|
+|Mandriva|/i586/isolinux/alt0/vmlinuz|/i586/isolinux/alt0/all.rdz|
+|Ubuntu|/casper/vmlinuz|/casper/initrd.gz or /casper/initrd|
+|Debian|/install.386/vmlinuz/|/isolinux/initrd.img|
+
+
+## Relocate an existing libvirtd (KVM) images directory
+By default, KVM (libvirtd) images on Ubuntu and most other Linux distributions are found in /var/lib/libvirt/images. This can be inconvenient if you don't have a separate /var partition that can grow over time to accommodate multiple large images.
+
+You _can_ simply rename the images folder to something else and then symlink to a larger space with it (e.g. ```ln -s /data1/libvirt/images /var/lib/libvirt/images```). That's what I used to do.
+
+But that can lead to all sorts of unanticipated trouble. The _right_ way to have your images on a bigger disk is to change the path for libvirt's default storage pool to a partition on that big disk, which is logically where KVM is going to create them.
+
+NOTE: The Ubuntu package for libvirt-daemon-system automatically sets up a [libvirt group](https://documentation.ubuntu.com/server/how-to/virtualisation/libvirt/) for libvirt admins (that includes members of the sudo group by default). Members of libvirt can run virsh commands without sudo. YMMV if not a member of the sudo group, or not on Ubuntu.
+
+First check to make sure a default pool exists:
+
+```bash
+$ virsh pool-list --all
+ Name      State    Autostart
+-------------------------------
+ default   active   yes
+```
+
+**NOTE: If no default pool exists, follow the instructions in [this gist](https://gist.github.com/plembo/13ce29c9279807adfd9bd6b959f43fac) to create one on your preferred storage volume.**
+
+Assuming a default pool exists, find the current default pool's path:
+
+```xml
+$ virsh pool-dumpxml default
+<pool type='dir'>
+  <name>default</name>
+  <uuid>91c6d1b3-4e42-4a1f-989e-89b2127da056</uuid>
+  <capacity unit='bytes'>133070688256</capacity>
+  <allocation unit='bytes'>25177309184</allocation>
+  <available unit='bytes'>107893379072</available>
+  <source>
+  </source>
+  <target>
+    <path>/var/lib/libvirt/images</path>
+    <permissions>
+      <mode>0711</mode>
+      <owner>64055</owner>
+      <group>108</group>
+    </permissions>
+  </target>
+</pool>
+```
+
+Before going further it is best to shut down ("destroy") all existing virtual machines).
+
+Now use ```virsh edit``` to change the disk path in each virtual machines's configuration to the default pool's new location. Assuming this will be "/data1/libvirt/images", you would proceed like this:
+
+```xml
+$ virsh edit example
+...
+<disk type='file' device='disk'>
+    <driver name='qemu' type='qcow2'/>
+-   <source file='/var/lib/libvirt/images/example.qcow2'/>
++   <source file='/data1/libvirt/images/example.qcow2'/>
+```
+(the line will then read ```<source file='/data1/libvirt/images/example.qcow2'```
+
+Next, the default pool should be completely shut down:
+
+```
+$ virsh pool-destroy default
+```
+Then, undefined:
+
+```
+$ virsh pool-undefine default
+```
+NOTE: By default, virt-manager creates additional pools automatically for things like iso files. These should also be destroyed and undefined before proceeding, to free things up for redefining the default pool (if you don't, the system will spit out "error: operation failed: Storage source conflict with pool" messages when you try redefining).
+
+Now, recreate the default pool anew and start:
+
+```bash
+$ virsh pool-define-as default dir --target "/data1/libvirt/images"
+$ virsh pool-build default
+$ virsh pool-start default
+$ virsh pool-autostart default
+```
+
+Check the status with virsh-info:
+```bash
+$ virsh pool-info default
+```
+
+And then the configuration with pool-dumpxml:
+
+```bash
+$ virsh pool-dumpxml default
+```
+
+Finally, move any existing disk images from /var/lib/libvirt/images to the new location (e.g. /data1/libvirt/images).
+
+
+## Cambiar el interfaz de red de una VM
+
+To change a VM's network with virsh, you can either edit the VM's XML configuration using virsh edit and then restart the VM, or use virsh net-edit to modify the network itself and then restart the network. The most common method is to shut down the VM, edit its XML definition, and then start it again. For network-wide changes, you can edit the network's XML definition and then restart the network to apply the changes. 
+
+### Method 1: Editing the VM's network configuration
+
+This method is for when you want to change the network attached to a specific VM.
+
+1. Shut down the VM:
+    virsh shutdown <vm_name>
+2. Edit the VM's XML:
+    virsh edit <vm_name>
+
+This will open the VM's XML file in a text editor. Find the <interface> section for the network you want to change.
+
+    <interface type='network'>
+      <mac address='52:54:00:7a:a0:cd'/>
+-      <source network='default'/>
++      <source network='hostbridge'/>
+      <model type='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
+    </interface>
+
+
+3. Save and close the editor.
+
+Apply the changes:
+
+    virsh start <vm_name>
+
+The VM will start with the new network configuration. 
+
+
+
+## Renombrar máquina
+
+    virsh dumpxml myvm > foo.xml
+    <edit foo.xml, change the name, move storage>
+    virsh undefine myvm
+    virsh define foo.xml