LXD e LXC

sudo snap install lxd  
lxd init – -auto   – – minimal
lxc launch images:ubuntu/22.04 nome_macc_virt macc_x
lxc list  
lxc image list  
lxc image info  
lxc image info UUID es: 1e98e1a26b1b
lxc exec macc_x bash  
lxc delete macc_x – – force
lxc launch images:ubuntu/22.04 macch_x  
lxc copy macch_1 macch_2  
lxc start macch_x restart stop
lxc info macch_x  
sudo lxc config set vmName limits.cpu 4 per variare parametri. anche limits.memory

https://linuxcontainers.org/
https://linuxcontainers.org/lxd/docs/master/
https://uk.lxd.images.canonical.com/
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-lxd-on-ubuntu-20-04
https://radar231.com/LXD.html

 

 

Storage

lxc storage create nome dir source=/dev/lxd dir oppure ZFS
lxc storage list  
lxc storage volume create default u2004v-sdb size=100GiB --type=block
$ lxc config device add u2004v u2004v-sdb disk pool=default source=u2004v-sdb
Creare ed aggiungere secondo volume ad una VM
   
   
   
   
   
   
lxc config device override macch_x eth0  
lxc config device set macch_x eth0 ipv4.address <IP> impostare IP statico – fare restart
lxc config edit macch_x  
   
   

 

Aggiunto ulteriore disco a VM LXD e montaggio come home
– tra < > mettere il nome pensato per i vari oggetti; ad es <pool> io ho usato default.
lxc storage volume create <pool> <vm> <nome-sdb> size=100GiB –type block
lxc config device add <vm> <nome-sdb> disk pool=<pool> source=<nome-sdb>
lxc storage volume delete default <nome-sdb> – da dare manualmente se si cancella la vm
– comandi da dare in console della vm per gestire il disco sdb collegato
fdisk -l
fdisk /dev/sdb
mkfs -t ext4 /dev/sdb   se si vuole formattare ext4, io ho usato zfs
blkid                              -> verifichi e copi UUID della partizione creata
cp /etc/fstab /etc/fstab.original
vim /etc/fstab
    —> aggiungere UUID=<uuidverificataconcomandosopra> /home ext4 defaults 0 2
reboot
df -h      —-> x verifcare

lxc network info lxdbr0
lxc network edit lxdbr0 —-> in formato yaml visualizzi valori delle key; per modificarlo usare
lxc network set lxdbr0 <key> <value>
<key> esempi: https://linuxcontainers.org/lxd/docs/master/networks/
ipv4.address 192.168.200.x
ipv4.dhcp true (ho provato false ma non mi da accesso ad alcuni container)

Configurazione del file /etc/netplan/00….yaml della macchina host:

network:
 version: 2
 renderer: networkd
 ethernets:
   eno1:
     dhcp4: false
     dhcp6: false
#      addresses:
#      – 192.168.200.10/24
#      gateway4: 192.168.200.1
#      nameservers:
#        addresses:
#        – 8.8.8.8
#        search:
#        – GDC_LAN
 bridges:
   lxdbr0:
     dhcp4: false
     dhcp6: false
     addresses:
     – 192.168.200.10/24
#      routes:
#        – to: default
#          via: 192.168.200.1
     gateway4: 192.168.200.1
     nameservers:
       addresses: [192.168.200.1,8.8.8.8]
     interfaces:
       –  eno1
#      parameters:
#        stp: true
#        forward-delay: 4
#      mtu: 1452