1 UsefulltricksubuntuServer
philc edited this page 2023-02-09 09:57:15 +01:00

Machine d'installation ubuntu server type

Ubuntu server 22.04 LTS with an internet link to update the installer

Plug your machine on your network to get IP Ubuntu server use /etc/netplan to parameter network

Manage Hardware

# check HD conf
sudo lsblk -f
sudo fdisk -l
# in case of LVM
sudo vgdisplay
# if Free PE / Size then increase with
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
check df -h # check that / increase properly

To remove partition and to create 1

sudo fdisk /dev/sdbx
# type d (interactive))
# n (to add a new partition answer question by default (extented to store data))
# at the end type w to save change
# to format
sudo mkfs.ext4 /dev/sdbx

#to rename label disk
sudo e2label /dev/sdxN my_label
#disks monut for user edifiance in / by disk uuid (get into lsblk -f)
sudo vim /etc/fstab #add this line per disk (to get user uid $id -u <username> to get gid $id -G <username>)  
UUID=d9f51ab7-7be1-4a75-a218-c97c50d807f8 /home/edifiance/Backup0 ext4 umask=0077,gid=1001,uid=1001 0     1

#for mounting without rebooting
sudo mount -a

# liste of add fdisk -l (voir la liste des dd)
fdisk /dev/sdb
# delete an create one partition with a 2Tb format with:
mkfs.ext4 /dev/sdb1
#hd2T = espace disque de 2 Tera en root 
mkdir /mnt/hdexterne
sudo vim /etc/fstab #addthis line
/dev/sdb1       /mnt/hdexterne      ext4    defaults        0       1
#Check access right of the folder belong to the final user
sudo chown -R user:group B*
sudo chmod 662 -R B*
# authorize phil to access to the mount 
# cmd id give back the uis and gid (ften the same)
id # connected with the relevant user
# instead of 1000 we add uid of the previous cmd
echo "root:1000:1" | sudo tee -a /etc/subuid /etc/subgid
#check cat /etc/subuid thzt we have root with uid of phil'

Manage network

If multi ethernet card => chose the bonds option

/etc/netplan

# This is the network config written by 'subiquity'
network:
  bonds:
    bond0:
      dhcp4: yes
      routes:
        - to: default
          via: 192.168.1.1
      interfaces:
      - enp0s25
      - enp2s0
      parameters:
        mode: balance-rr
  ethernets:
    enp0s25: {}
    enp2s0: {}
  version: 2
sudo netplan generate # process file from your yaml file
sudo netplan apply # apply it 



Then into a container

# network address info 
ip a
# check if host is reachable
ping gateway  # check if gateway is accessible often 192.168.1.1
ping 8.8.8.8  # check if internet is accessible by ip (this is one of the dns of google)
ping www.google.com # check if dns transciption is available



Manage linux server:

#set a time server
sudo apt install ntp
sudo timedatectl
sudo timedatectl set-timezone 'Europe/Paris'

# List running service on a machine (active or not)
systemctl --type=service
# To check status of service
systemectl status servicename
# restart stop load a service
systemctl start servicename
# Change hostname of a server do not use . or any other char than a-z A-Z 0-9 -
sudo hostnamectl set-hostname hill-ants

Manage lxd lxc container

We use snapd to manage lxd https://snapcraft.io/lxd

sudo snap install lxd
sudo adduser phil lxd 
lxd init

Would you like to use LXD clustering? (yes/no) [default=no]: 
Do you want to configure a new storage pool? (yes/no) [default=yes]: 
Name of the new storage pool [default=default]: VMpool
Name of the storage backend to use (btrfs, dir, lvm, zfs, ceph) [default=zfs]: dir
Would you like to connect to a MAAS server? (yes/no) [default=no]: 
Would you like to create a new local network bridge? (yes/no) [default=yes]: 
What should the new bridge be called? [default=lxdbr0]: 
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: none
Would you like LXD to be available over the network? (yes/no) [default=no]: yes
Would you like stale cached images to be updated automatically? (yes/no) [default=yes] 
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: 

lxc --help
lxc cmdname --help 
# to get list of container
lxc list
# Show list of available VM
$ lxc image list images:debian ou ubuntu ...
# create a Nomcontainer into VMpool
lxc launch images:ubuntu/focal NomContainer --storage VMpool
# to access an ubuntu VM
lxc exec MonContainer -- sudo --login --user ubuntu
# To access an other distro
lxc exec NomContainer -- /bin/bash
# to debug into the host
journalctl -u LXD
# to debug into a Namecontainer
lxc info Namecontainer --show-log

Si pb de resolv.conf check if it is running (if not start it)
sudo systemctl status systemd-resolved.service

Pour réinitialiser le réseau on peut faire sudo dpkg-reconfigure -p medium lxd