# Debian

Ici je me mets divers memo pour l'installation de Debian.

# installation & mise à jour de debian

> qemu-guest-agent est à installé si on utilise KVM ou QEMU
```sh
su -s
apt update && apt upgrade -y && apt dist-upgrade -y \
&& apt autoremove -y && apt purge && apt autoclean \
&& apt install -y vim htop sudo curl software-properties-common dirmngr ca-certificates apt-transport-https qemu-guest-agent \
&& sudo usermod -a -G sudo mon_user
```

### Ajout utilisateur a sudo permission
```sh
vim /etc/sudoers
mon_user ALL=(ALL:ALL) ALL
systemctl reboot
```

### fdisk : commande introuvable
Si la commande fdisk ne fonctionne pas exécuter cette command comme ci-dessous:
```bash
user@myhost:~$ PATH="/sbin:$PATH"
user@myhost:~$ command -v fdisk
/sbin/fdisk
```

# Installation Mariadb

[![Capture d’écran 2022-06-13 à 14.27.42.png](https://wiki.fuseboat.co/uploads/images/gallery/2022-06/scaled-1680-/capture-decran-2022-06-13-a-14-27-42.png)](https://wiki.fuseboat.co/uploads/images/gallery/2022-06/capture-decran-2022-06-13-a-14-27-42.png)

> Ici on va sur le site de mariadb on selectionne la version à installer: 
[Mariadb repos](https://mariadb.org/download/?t=repo-config&d=Debian+11+%22Bullseye%22&v=10.8&r_m=mva)

## installation du dépot maraidb 10.8:
```sh
sudo timedatectl set-timezone Europe/Zurich \
&& sudo apt update \
&& sudo apt-get install apt-transport-https curl qemu-guest-agent \
&& sudo curl -o /etc/apt/trusted.gpg.d/mariadb_release_signing_key.asc 'https://mariadb.org/mariadb_release_signing_key.asc' \
&& sudo sh -c "echo 'deb https://mirror.mva-n.net/mariadb/repo/10.8/debian bullseye main' >>/etc/apt/sources.list" && sudo reset
```

## Install mariadb
```sh
sudo apt update \
&& sudo apt install -y mariadb-server mariadb-client \
&& sudo systemctl enable mariadb && sudo systemctl start mariadb
```

## On commence ca configuration:
```
sudo mysql_secure_installatio

Switch to unix_socket authentication [Y/n] Y
Change the root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
```

## connection distante:
```sh
sudo mysql -u root -p
```
```mysql
GRANT ALL PRIVILEGES ON *.* TO 'mon_user'@'%' IDENTIFIED BY 'mot_de_passe' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
```

## Activation de connection distante & augmentation des perfs:
```sh
sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf
```
```conf
# Permet la connection distante
bind-address = 0.0.0.0
# Selon la ram disponible
innodb_buffer_pool_size = 4G
``

# HDD Home

> #### Attribution d'un disque dur au dossier **/home** à faire en mode root ``sudo -s``

## Parted
Créer une patition **gpt** et partitioner le disque dure
```bash
parted /dev/vdb 
# mklabel gpt
# quit
```

Partitionnement du disque dure avec fdisk (commande n => nouvel partition, w => enregistrer la partition crée, q => quitter )
```bash
fdisk /dev/vdb
```
### Volume LVM
création de volume lvm
```bash
vgcreate home-data-vg /dev/vdb1 && \
lvcreate -n  home-data-lv -l 100%free home-data-vg && lvs && \
mkfs.ext4  /dev/home-data-vg/home-data-lv
```

Déplacer le contenu du dossier **/home** sur un repertoire temporair Déplacer le contenu du dossier **/home** sur un repertoire temporaire,
monter le volume lvm sur home et le redéplacer le contenur sur le repertoire **/home**
```bash
mkdir -r /old-home && \
mv * /home /old-home && ls -la /old-home && \
mount /dev/home-data-vg/home-data-lv /home && \
echo "" >> /etc/fstab && cat /etc/fstab && \
echo "# Mount home directory" >> /etc/fstab && cat /etc/fstab && echo "/dev/home-data-vg/home-data-lv /home	ext4	defaults	0 1" >> /etc/fstab && cat /etc/fstab && \ mv * /old-home /home  && ls -la /home && df -h
```