Français

Augmenter la taille d'une disque virtuel

Premièrement il faut determiner quel type de cas est présent sur votre machine virtuelle. Dans notre environnement de virtualisation il y a deux cas possibles:

Quand le disque virtuel a une table de partitions

Le but ici est de re-créer la table de partitions pour que la partition principale soit étendue à travers le disque virtuel au complet.

  1. Assurez-vous d'avoir des sauvegardes du système sur lequel vous travaillez.
  2. Rouler fdisk avec le disque que voulez modifier:

    fdisk /dev/xvda
    • Ces commandes sont conçues pour des installations de Debian Stretch et Buster.

    • Afficher les informations sur la table de partitions actuelle:

      p
      # ceci affichera quelquechose comme:
      # Disk /dev/vda: 14 GiB, xxx bytes, xxx sectors
      # Units: sectors of 1 * 512 = 512 bytes
      # Sector size (logical/physical): 512 bytes / 512 bytes
      # I/O size (minimum/optimal): 512 bytes / 512 bytes
      # Disklabel type: dos
      # Disk identifier: 0x00000000
      #
      # Device     Boot Start      End  Sectors Size Id Type
      # /dev/xvda1       2048 58720255 58718208  28G 83 Linux
    • Supprimer la partition que vous voulez aggrandir:

      d
      # Choisir la partition par numéro
      1

      Si à cette étape-ci on obtient un message comme le suivant, ça veut dire qu'on est dans une vieille VM qui n'a pas de table de partitions (e.g. tout le disque est un volume ext4). Arrêtez-vous ici et ne sauvegardez pas les changements que vous avez effectué à la table de partitions du disque.

      Command (m for help): d
      No partition is defined yet!
      Could not delete partition 1
    • Créer la nouvelle partition

      n
      # Choisir le type de partition: primaire
      p
      # Choisir le numéro de partition
      1
      # Choisir la début, 2048 par défaut. Fié à informations affiché par 'p'
      2048
      # Choisir la fin, la valeur par défaut suffiera dans les cas simples
      58720255
      # Il y aura un avertissement comme quoi une signature ext4 est présente. "Est-ce qu'on veut la détruire?" Répondez: ''non'''. (pour conserver la signature ext4)
      n
      # Sauvegarder les changements (ça quitte automatique)
      w
    1. Re-charger la table de partitions. Il y a trois façons de faire celà:
      • partprobe
      • kpartx
      • redémarrer la vm
    2. Redimensionner le système de fichiers ext3/ext4 en-ligne:

      resize2fs /dev/xvda1

Quand le disque virtuel est utilisé directement sans partitions

Reconfigurer la taille du disque swap

  1. Confirmer le nom du disque qui est utilisé pour la "swap" (c'est souvent /dev/xvdb) avec la commande suivante:

    lsblk -l -p | grep SWAP
  2. Vérifier que la mémoire "swap" peut être déplacée vers la mémoire active en comparant le total de mémoire utilisée en "swap" et le total mémoire vive disponible. Il est possible de voir cette information clairement avec htop, mais d'autres commandes tel que vmstat peuvent être utilisées.

  3. Désactiver la "swap":

    swapoff -a
  4. Configurer la "swap" sur le disque trouvé à l'étape 1:

    mkswap /dev/xvdb
  5. Verifier l'identifiant unique ("UUID") du disque "swap" avec ls -lah /dev/disk/by-uuid et assurer que l'entrée pour le disque "swap" dans /etc/fstab a le même "UUID".

  6. Activer la "swap" à nouveau:

    swapon -a

English

Resize (to a larger) virtual disk

Determine the style of virtualized disk being used. In our virtual environments there a two possible cases:

When the virtual disk has partitions

The goal here is to recreate the partition table of the virtual disk with larger extents, then grow the filesystem of the principal partition.

  1. Make sure you have backups of the system you are working on, in case something goes wrong.
  2. Open fdisk with the disk in question:

    fdisk /dev/xvda
    • These commands are written for and tested on Debian Stretch and Debian Jessie

    • Print the existing partition table using the command p while in fdisk. It will look something like the following:

      p
      # Disk /dev/vda: 14 GiB, xxx bytes, xxx sectors
      # Units: sectors of 1 * 512 = 512 bytes
      # Sector size (logical/physical): 512 bytes / 512 bytes
      # I/O size (minimum/optimal): 512 bytes / 512 bytes
      # Disklabel type: dos
      # Disk identifier: 0x00000000
      #
      # Device     Boot Start      End  Sectors Size Id Type
      # /dev/xvda1       2048 58720255 58718208  28G 83 Linux
    • Remove the partition that you would like grow:

      d
      # Choose the partition by number
      1

      If this step has an error message like the following, it indicates that it is probably an old VM that doesn't use partition tables. The entire virtual is the ext4 filesystem. Stop here and don't save any of the fdisk changes to disk. In this case, resize2fs alone should be fine.

      Command (m for help): d
      No partition is defined yet!
      Could not delete partition 1
    • Create the new, larger, partition:

      n
      # Chooose the partition type: primary
      p
      # Choosse the partition number
      1
      # Choose the start. 2048 by default. Re-use the information shown by the 'p' command in step 2.1
      2048
      # Choose the end. In most cases the default value will be sign.
      58720255
      # There will be warning that theree is an ext4 signature present. Do not remove the signature.
      n
      # Saves the changes (this will quit fdisk)
  3. Reload the the partion table. There are three commands that can do this
    • partprobe
    • kpartx
    • resetting the virtual machine
  4. Resize the filesystem:

    resize2fs /dev/xvda1

When the virtual disk is used directly

To increase the size of the filesystem on the device:

resize2fs /dev/xvda

Reset swap size of virtual disk

  1. Confirm the name of the disk being used for the swap space, usually /dev/xvdb by running the following command:

    lsblk -l -p | grep SWAP
  2. Check that the memory in swap can all be placed into the live system memory by comparing the available memory and swapped memory totals. htop can be used to see this clearly, but other commands such as vmstat output the same information.

  3. Disable the swap:

    swapoff -a
  4. Set up the swap area on the disk (replace with the disk found in step 1):

    mkswap /dev/xvdb
  5. Verify the UUID of the disk (ls -lah /dev/disk/by-uuid), and make sure the entry for the swap disk in /etc/fstab uses the correct UUID.

  6. Enable the swap:

    swapon -a

VserverService/ResizeDisks (last edited 2020-02-21 16:28:01 by anonymous)