Skip to content

Instantly share code, notes, and snippets.

@mickaelperrin
Created September 20, 2019 09:05
Show Gist options
  • Save mickaelperrin/1ab00e41e516f0279a8d3dfd8406e9da to your computer and use it in GitHub Desktop.
Save mickaelperrin/1ab00e41e516f0279a8d3dfd8406e9da to your computer and use it in GitHub Desktop.
Repartition Server

#1 - installation par défaut:

Partitionnement au travers de l'outil online:

  • /boot : Ext4 / RAID1 / 1000Mo
  • swap: SWAP / pas de raid / 3000Mo
  • /: Ext4 / RAID5 / 20000Mo
  • /data: EXT4 / RAID5 / le reste 215Go

#2 - une fois l'installation par défaut faite

Se connecter en SSH

installer vim

apt install vim

Editer GRUB pour afficher les messages d'erreur

vi /etc/default/grub
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10
GRUB_CMDLINE_LINUX_DEFAULT=""

Une fois fini, appliquer les changements

update-grub

Mettre à jour initram-fs, pb de montage LVM au boot

BUG: https://bugs.launchpad.net/ubuntu/+source/lvm2/+bug/1573982/comments/10

apt install lvm2

mkdir -p /etc/initramfs-tools/scripts/local-top

vi /etc/initramfs-tools/scripts/local-top/forcelvm
-----------------
#!/bin/sh
PREREQ=""
prereqs()
{
   echo "$PREREQ"
}
case $1 in
prereqs)
   prereqs
   exit 0
   ;;
esac
. /scripts/functions
# Begin real processing below this line

# This was necessary because ubuntu's LVM autodetect is completely broken. This
# is the only line they needed in their script. It makes no sense.
# How was this so hard for you to do, Ubuntu?!?!?
lvm vgchange -ay
------------------------
chmod +x /etc/initramfs-tools/scripts/local-top/forcelvm

update-initramfs -k all -c

Redémarrer et s'assurer que le menu est visibile ainsi que les logs de démarrage en se connectant au KVM

Redémarrer en mode rescue

Création du volume LVM

Lister les volumes RAID

cat /proc/mdstat

Monter les partitions:

mountall.sh

Voir quel est le volume qui contient la partition /data, /data => /dev/md125 /boot => /dev/md126 / => /dev/md127

Démonter les partitions:

umountall.sh

Créer les volumes LVM sur la partition /data ici /dev/md125

pvcreate /dev/md125
WARNING: ext4 signature detected on /dev/md125 at offset 1080. Wipe it? [y/n]: y
vgcreate -y ubuntu /dev/md125
lvcreate -y -n usr -L 30G ubuntu
lvcreate -y -n var -L 25G ubuntu
lvcreate -y -n log -L 25G ubuntu
lvcreate -y -n tmp -L 15G ubuntu
lvcreate -y -n home -l 100%FREE ubuntu

Formatage des partitions créées:

for d in usr var log tmp home; do mkfs.ext4 -F /dev/mapper/ubuntu-${d} -L ubuntu-${d}; done

Montage des partitions existantes et des nouvelles partitions créées:

mountall.sh
cd /mnt
mkdir -p /mnt/{var,tmp,home,usr,varlog}
mount /dev/mapper/ubuntu-var /mnt/var
mount /dev/mapper/ubuntu-log /mnt/varlog
mount /dev/mapper/ubuntu-tmp /mnt/tmp
mount /dev/mapper/ubuntu-home /mnt/home
mount /dev/mapper/ubuntu-usr /mnt/usr

Identification de la partition /, ici /mnt/md127

Déplacement des contenus:

rsync -avXS --remove-source-files /mnt/md127/home/. /mnt/home/
rsync -avXS --remove-source-files /mnt/md127/var/log/. /mnt/varlog
rsync -avXS --remove-source-files /mnt/md127/var/. /mnt/var
rsync -avXS --remove-source-files /mnt/md127/tmp/. /mnt/tmp
rsync -avXS --remove-source-files /mnt/md127/usr/. /mnt/usr

Remove remaining base folders:

find /mnt/md127/home -type d -delete
find /mnt/md127/var -type d -delete
find /mnt/md127/tmp -type d -delete
find /mnt/md127/usr -type d -delete

Générer le configuration à base d'UUID à mettre dans le fstab pour monter les nouvelles partitions:

for d in usr var log tmp home; do echo "$(blkid | grep ubuntu-$d | awk '{print $3}' | tr -d '"') /$d ext4    defaults,noatime  0       1"; done

Editer fstab

vi /mnt/md127/etc/fstab
# Remove /data partition
# Add generated configuration
# Rename /log in /var/log

Create mounted dirs

mkdir -p /mnt/md127/{var,tmp,home,usr}
chmod a+trwx /mnt/md127/tmp
mount /dev/mapper/ubuntu-var /mnt/md127/var
mkdir -p /mnt/md127/var/log

Redémarrer en mode normal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment