Renaming of files to reflect that Day 1 wes not about any note-taking
This commit is contained in:
@@ -1,161 +1,76 @@
|
||||
# Infra avancée
|
||||
|
||||
## Cours
|
||||
|
||||
### Contenerisation
|
||||
|
||||
- Namespace : les processus ne peuvent pas voir les ressources utilisées par l'hôte ou ses congénères
|
||||
- cgroups : contrôle des ressources allouées à un processus
|
||||
|
||||
#### Solutions :
|
||||
|
||||
- Docker / Podman
|
||||
- OpenVZ
|
||||
- Les zones (Solaris)
|
||||
- Les jails (FreeBSD)
|
||||
- LXC
|
||||
|
||||
### LXC
|
||||
|
||||
```
|
||||
# Avec interactivté
|
||||
sudo lxc-create -n NOM_CONTENEUR -t download
|
||||
|
||||
# Sans interactivité (pour script)
|
||||
sudo lxc-create --template=download --name NOM_CONTENEUR -- --dist NOM_DISTRIBUTION --release NUMERO_VERSION --arch amd64
|
||||
```
|
||||
|
||||
```
|
||||
# Démarrer
|
||||
sudo lxc-start -n NOM_CONTENEUR
|
||||
|
||||
# Entrer dans un conteneur
|
||||
sudo lxc-attach -n NOM_CONTENEUR
|
||||
|
||||
# Stopper
|
||||
sudo lxc-stop -n NOM_CONTENEUR
|
||||
|
||||
# Supprimer
|
||||
sudo lxc-destroy -n NOM_CONTENEUR
|
||||
|
||||
# Lister
|
||||
sudo lxc-ls (--active, --running, --frozen)
|
||||
|
||||
# Info sur conteneur précis
|
||||
sudo lxc-info -n NOM_CONTENEUR
|
||||
```
|
||||
|
||||
Fichier config du conteneur (/var/lib/lxc/xxx) :
|
||||
```
|
||||
# Méthode 1 : Montage d'un dossier de l'hôte
|
||||
lxc.mount.entry = /dossier_hote dossier_interne_conteneur none bind,create=dir 0 0
|
||||
|
||||
# Méthode 2 : Montage d'un disque entier ou partition de l'hôte
|
||||
lxc.mount.entry = /dev/disque_ou_partition dossier_interne_conteneur FS_type defaults,create=dir 0 0
|
||||
```
|
||||
# L'infra avancée :
|
||||
|
||||
## Exercice 1
|
||||
|
||||
https://dl-cdn.alpinelinux.org/alpine/v3.17/releases/x86_64/alpine-xen-3.17.10-x86_64.iso
|
||||
### Lancer une machine
|
||||
|
||||
```
|
||||
wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-13.1.0-amd64-netinst.iso
|
||||
`qemu-img create -f qcow2 'C:\Program Files\qemu\testVM.qcow2' 10G`
|
||||
|
||||
mv debian-13.1.0-amd64-netinst.iso debian.iso
|
||||
`qemu-system-x86_64 -m 2048 -hda 'C:\_VMs\testVM.qcow2' -cdrom 'D:\Users\GaWin\Downloads\_Compressed\debian-13.1.0-amd64-netinst.iso' -boot d`
|
||||
|
||||
sudo chmod 666 debian.iso
|
||||
```
|
||||
Pour lancer une machine depuis le disque :
|
||||
|
||||
Ensuite
|
||||
`qemu-system-x86_64 -m 4096 -smp 4 -hda 'C:\_VMs\testVM.qcow2' -boot c`
|
||||
|
||||
```
|
||||
sudo virt-install \
|
||||
--name test-vm \
|
||||
--os-variant=debiantesting \
|
||||
--ram 2048 \
|
||||
--vcpus 2 \
|
||||
--location ./debian.iso \
|
||||
--disk path=/var/lib/libvirt/images/vm.qcow2,size=15,format=qcow2 \
|
||||
--graphics none \
|
||||
--console pty,target_type=serial \
|
||||
--extra-args "console=ttys0,115200n8 serial"
|
||||
```
|
||||
- -boot d : Boot sur le CD/ROM
|
||||
- -boot c : Boot sur le Disque Dur
|
||||
- m XXXX : Alloue une mémoire RAM fixe
|
||||
- smp X : Alloue un nombre de coeurs virtuels fixe
|
||||
|
||||
`virsh attach-interface --type bridge --source enp0s3 --model virtio test-vm`
|
||||
Pour convertir le .qcow2 en .vdi, dans l'interface c'est plus clair.
|
||||
|
||||
## Exercice 2
|
||||
|
||||
### Petit A
|
||||
### Créer une VM
|
||||
|
||||
C'est installé.
|
||||
|
||||
### Petit B
|
||||
Pour refaire une VM en CLI :
|
||||
|
||||
```
|
||||
sudo lxc-create -n ConteneurDebian -t download
|
||||
# debian, bullseye, amd64
|
||||
vboxmanage createvm --basefolder="C:\_VMs\VirtualCreationCLI" --register --name "VirtualBoxCLI"
|
||||
|
||||
sudo lxc-start ConteneurDebian
|
||||
sudo lxc-attach ConteneurDebian
|
||||
vboxmanage storagectl "VirtualBoxCLI" --name "sata-controller" --add sata --controller IntelAHCI --portcount 1 --bootable on
|
||||
|
||||
### In the container ###
|
||||
uname -a
|
||||
vboxmanage storageattach "VirtualBoxCLI" --storagectl "sata-controller" --port 0 --device 0 --type hdd --medium ".\test_copy.vdi"
|
||||
|
||||
> Linux ConteneurDebian 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64 GNU/Linux
|
||||
|
||||
cat /proc/version
|
||||
> Linux version 6.1.0-40-amd64 (gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20)
|
||||
|
||||
exit
|
||||
|
||||
### Outside the container ###
|
||||
|
||||
sudo lxc-ls
|
||||
> ConteneurDebian Test-Linux
|
||||
|
||||
sudo lxc-ls --running
|
||||
> ConteneurDebian
|
||||
|
||||
sudo lxc-stop ConteneurDebian
|
||||
|
||||
sudo lxc-ls --running
|
||||
>
|
||||
vboxmanage modifyvm "VirtualBoxCLI" --memory 4096 --cpus 4
|
||||
```
|
||||
|
||||
### Petit C
|
||||
### Convertir un disque virtuel .qcow2 en CLI
|
||||
|
||||
https://github.com/michaelrudy/qemu-img-convert
|
||||
|
||||
D'abord, dans la VM d'origine, il faut préparer la transition :
|
||||
|
||||
```
|
||||
sudo ls -glAiF /var/lib/lxc/
|
||||
> ConteneurDebian
|
||||
> Test-Linux
|
||||
sudo tee /etc/dracut.conf.d/hyperv.conf >/dev/null <<'EOF'
|
||||
add_drivers+=" hv_vmbus hv_storvsc hv_netvsc hv_utils "
|
||||
hostonly="no"
|
||||
EOF
|
||||
|
||||
sudo ls -glAiF /var/lib/lxc/ConteneurDebian
|
||||
> -rw-r----- root config
|
||||
> drwxr-xr-x root rootfs/
|
||||
sudo dracut -f --kver "$(uname -r)"
|
||||
|
||||
sudo du -h -glAiF /var/lib/lxc/ConteneurDebian
|
||||
> ...
|
||||
> 412M
|
||||
ls -lh /boot/initramfs-$(uname -r).img ### pour confirmer
|
||||
|
||||
sudo lxc-copy -n ConteneurDebian -N NewConteneur ### -N pour NewName
|
||||
cat /etc/fstab
|
||||
blkid
|
||||
|
||||
sudo ls -glAiF /var/lib/lxc/
|
||||
> ConteneurDebian
|
||||
> NewConteneur
|
||||
> Test-Linux
|
||||
sudo shutdown -h now
|
||||
```
|
||||
|
||||
### Petit D
|
||||
`qemu-img convert -f qcow2 -O vhdx -o subformat=dynamic .\test.qcow2 .\test_copy.vhdx`
|
||||
|
||||
Bizarrement, pour que la conversion soit prise en compte par Hyper-V, il faut lancer cette commande :
|
||||
|
||||
`fsutil sparse setflag .\test_copy.vhdx 0`
|
||||
|
||||
### Cloner une VM en CLI
|
||||
|
||||
Exporter pour VirtualBox
|
||||
`vboxmanage clonevm "VirtualBoxCLI" --basefolder ".\NewVirtualBoxCLI" --name "NewVirtualBoxCLI" --register`
|
||||
|
||||
Exporter pour HyperV
|
||||
```
|
||||
sudo nano /var/lib/lxc/ConteneurDebian/config
|
||||
|
||||
### Dans le fichier config ###
|
||||
|
||||
# Folder Attachment
|
||||
lxc.mount.entry = /mnt/lxc-debian-storage /var/lib/lxc/ConteneurDebian/rootfs/data none bind,create=dir 0 0
|
||||
|
||||
### Fin du fichier config ###
|
||||
|
||||
Export-VM -Name "HyperVCLI" -Path "C:\_VMs\HyperVCLI" -CaptureLiveState CaptureSavedState
|
||||
|
||||
Import-VM -Name "NewHyperVCLI" -Path "C:\_VMs\HyperVCLI\{ID-de-ses-morts}.vmcx" -Copy -GenerateNewId -VirtualMachinePath "C:\_VMs\NewHyperVCLI" -VhdDestinationPath "C:\_VMs\NewHyperVCLI"
|
||||
```
|
||||
Reference in New Issue
Block a user