ReLoad

Thierry Jaouen ~ WikiBlog
"Rien à foutre d'être lu, tant que je peux me relire."

Outils pour utilisateurs

Outils du site


Action disabled: source
blog:2012:11:11:lvm_agrandir_et_creer_partitions

LVM agrandir et créer partitions

Jouer avec LVM et un peu avec “parted” pour agrandir ou créer une nouvelle partition…

~~READMORE~~

Agrandir LVM PV

En fait, j'aimerai agrandir le “PV” …

Pour l'instant j'ai:

# parted /dev/sda print
Model: DELL PERC H800 (scsi)      
Disk /dev/sda: 9991GB             
Sector size (logical/physical): 512B/512B
Partition Table: gpt         

Number  Start   End     Size    File system  Name     Flags
 1      17,4kB  6561GB  6561GB               primary  lvm

… la même chose en secteur:

# parted /dev/sda unit s print
Model: DELL PERC H800 (scsi)
Disk /dev/sda: 19513999360s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End           Size          File system  Name     Flags
 1      34s    12813614753s  12813614720s               primary  lvm

… la même chose en Tera:

# parted /dev/sda unit TB print
Model: DELL PERC H800 (scsi)
Disk /dev/sda: 9,99TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      0,00TB  6,56TB  6,56TB               primary  lvm

On va agrandir a 7,5TB :

:!: ATTENTION
  • :!: Bien prendre note de l'etat actuel des partitions.
  • :!: Arreter tout accès sur le disk. Sinon: y a des risques
  • :!: On va devoir supprimer et re-creer la partition
  • :!: A la fin, on devra sans doute rebooter… ou pas.
  • :!: Adapter les commandes selon votre configuration.

Ceci dit, on y va :

# parted /dev/sda
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.

Vérifier qu'on parle bien de la bonne partition:

(parted) print                                                            
Model: DELL PERC H800 (scsi)
Disk /dev/sda: 9991GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17,4kB  6561GB  6561GB               primary  lvm

Effacer la partition (mais pas les données qui sont dedans) :

(parted) rm 1                                                             
Error: Partition(s) 1 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
Ignore/Cancel? I
:!: Cette Error est le présage qu'on devra rebooter à la fin! gasp

Recréer la partition, mais en plus grand !

(parted) mkpart primary 34s 7,5TB
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                          
Error: Partition(s) 1 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
Ignore/Cancel? I

Redire que c'est une partition “LVM” :

(parted) set 1 lvm on         
Error: Partition(s) 1 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
Ignore/Cancel? I

Un dernier regard avant de sortir:

(parted) print
Model: DELL PERC H800 (scsi)
Disk /dev/sda: 9991GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17,4kB  7500GB  7500GB               primary  lvm

(parted) unit s print
Model: DELL PERC H800 (scsi)
Disk /dev/sda: 19513999360s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End           Size          File system  Name     Flags
 1      34s    14648437500s  14648437467s               primary  lvm

Ok. On sort.

(parted) quit
Information: You may need to update /etc/fstab.
# sync

(ne sert surement a rien…)

# blktool /dev/sda reread-part
BLKRRPART: Device or resource busy

C'est la confirmation qu'il faut mieux rebooter et ne pas tenter d'utiliser la partition avant cela.

# reboot

Aprés reboot, on peut agrandir le “PV” afin qu'il intègre la nouvelle dimension:

# pvresize /dev/sda1
Physical volume "/dev/sda1" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

Vérifions:

# pvs /dev/sda1
PV         VG   Fmt  Attr PSize PFree  
/dev/sda1  vg1  lvm2 a-   6,82t 874,92g

Voila.

Ajouter une nouvelle partition

Maintenant, on va créer une nouvelle partition (lvm) qui occupera tout le reste du disk.

Donc, on a pour le moment (voir partie ci-dessus) :

# parted /dev/sda unit s print
Model: DELL PERC H800 (scsi)
Disk /dev/sda: 19513999360s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End           Size          File system  Name     Flags
 1      34s    14648437500s  14648437467s               primary  lvm

Avant de continuer, un peu de calcul.

En effet, mkpart ne cesse de clamer :

Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel?

C'est anodin, sans doute, mais ça m'énerve :-|

Après moult recherche j'ai cru voir qu'il faut aligner sur 64MB , soit 131072 secteurs !

FIXME : source ?

Donc, je sors ma calculatrice.

Soit PS le premier secteur libre , et Soit AS le premier secteur le mieux aligné.

La formule: AS = Entier( ( PS + 131071 ) / 131072 ) * 131072

Donc, dans mon cas, le premier secteur PS libre est: 14648437500 + 1 , soit : 14648437501

J'applique la formule:

Calcul Résultat
14648437501 + 131071 14648568572
14648568572 / 131072 111759
111759 * 131072 14648475648

Donc, le premier secteur libre bien aligné est : 14648475648

Retour sur parted .

Création de la (2ieme) partition:

(parted) mkpart primary 14648475648s -1s
Warning: You requested a partition from 14648475648s to 19513999359s.     
The closest location we can manage is 14648475648s to 19513999326s.
Is this still acceptable to you?
Yes/No? Yes
  • -1s signifie : le dernier secteur
  • L'avertissement est pour alignement sur le dernier secteur, pas le premier

Si on veut créer une partition LVM , alors ajouter:

(parted) set 1 lvm on 

Voila:

(parted) unit s print                                                     
Model: DELL PERC H800 (scsi)
Disk /dev/sda: 19513999360s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start         End           Size          File system  Name     Flags
 1      34s           14648437500s  14648437467s               primary  lvm
 2      14648475648s  19513999326s  4865523679s                primary  lvm

Voila.

blog/2012/11/11/lvm_agrandir_et_creer_partitions.txt · Dernière modification : 2012/11/11 18:31 de thierry