Estendere disco LVM in ubuntu server 14 VmWare

Linux Varie

Estendere disco LVM in Ubuntu Server 14 o CentOS 7 VmWare

Come prima operazione a macchina accesa andare nelle proprietà della VM ed incrementare lo spazio desiderato nel nostro caso aumenteremo da 600 a 750.
Fatto questo bisogna riavviare il server affinche Ubuntu veda la nuova configurazione del disco
Entrare in terminale sulla macchina con privileggi di root
  •  Utilizzare il comando parted per verificare l’effettivo spazio libero non allocato.

root@cloud:~# parted
GNU Parted 2.3
Viene usato /dev/sda
Benvenuti in GNU Parted. Digitare “help” per l’elenco dei comandi.
(parted) print free
Modello: VMware Virtual disk (scsi)
Disco /dev/sda: 805GB
Dimensione del settore (logica/fisica): 512B/512B
Tabella delle partizioni: msdos

Numero    Inizio      Fine            Dimensione    Tipo               File system        Flag
32,3kB    1049kB      1016kB                                    Spazio libero
1                 1049kB   256MB       255MB             primary        ext2                     avvio
256MB    257MB       1048kB                                  Spazio libero
2                 257MB    805GB       805GB             extended
5                 257MB     215GB       214GB              logical                                        lvm
6                 215GB      644GB      429GB              logical
7                 644GB      805GB      161GB              logical

(parted) q

  • creare una nuova partizione
root@CloudServer:~# cfdisk

Una volta aperto il programma selezionare la riga dello spazio libero interessato a questo punto premere su Nuovo selezionare partizione logica tipo LVM poi premere sul pulsante Scrivi e poi esci.

  • controllare l’avvenuta creazione della partizione, nel mio caso /dev/sda7

root@cloud:~# fdisk -l /dev/sda

Disk /dev/sda: 805.3 GB, 805306368000 bytes
255 testine, 63 settori/tracce, 97906 cilindri, totale 1572864000 settori
Unità = settori di 1 * 512 = 512 byte
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Identificativo disco: 0x00067251

Dispositivo    Boot     Start                 End                    Blocks               Id     System
/dev/sda1      *            2048                499711               248832             83    Linux
/dev/sda2                   501758             1572863999     786181121        5       Esteso
/dev/sda5                   501760             419428351       209463296      8e     Linux LVM
/dev/sda6                   419428415       1258291199     419431392+    83     Linux
/dev/sda7                   1258291263     1572863999    157286368+    83     Linux

  • creare il volume fisico per sda7
root@CloudServer:~# pvcreate /dev/sda7
  Physical volume "/dev/sda7" successfully created

5. controllare i volumi fisici

root@cloud:~# pvdisplay
— Physical volume —
PV Name                        /dev/sda5
VG Name                        ubuntu-vg
PV Size                            199,76 GiB / not usable 2,00 MiB
Allocatable                     yes (but full)
PE Size                           4,00 MiB
Total PE                         51138
Free PE                          0
Allocated PE                 51138
PV UUID                       v2vX73-9zrg-EVfd-Zbvu-pRQj-vCD5-Vg7eTA

— Physical volume —
PV Name                       /dev/sda6
VG Name                      ubuntu-vg
PV Size                          400,00 GiB / not usable 4,97 MiB
Allocatable                   yes (but full)
PE Size                         4,00 MiB
Total PE                       102399
Free PE                        0
Allocated PE               102399
PV UUID                     XbvqTN-1Sh1-txwp-V6F3-s4kt-alZj-Qa5d30

“/dev/sda7” is a new physical volume of “150,00 GiB”
— NEW Physical volume —
PV Name                    /dev/sda7
VG Name
PV Size                       150,00 GiB
Allocatable                NO
PE Size                       0
Total PE                     0
Free PE                      0
Allocated PE             0
PV UUID                   deULNo-2OWM-CekT-RCm1-4sKt-C13m-k4U8vL

  • estendere il nuovo volume creato (sda7) dandogli lo stesso VG name del volume principale (sda6), nel mio caso ubuntu-vg
root@CloudServer:~# vgextend ubuntu-vg /dev/sda7
  Volume group "ubuntu-vg" successfully extended
  •  controllare il nome del volume logico da estendere (nel mio caso /dev/ubuntu-vg/root)

root@cloud:~# lvdisplay
— Logical volume —
LV Path                             /dev/ubuntu-vg/root
LV Name                          root
VG Name                         ubuntu-vg
LV UUID                          J9C1Ov-0zu3-qHXn-kAjJ-BQPc-KiVn-Om7CcF
LV Write Access             read/write
LV Creation host, time ubuntu, 2016-06-06 16:49:38 +0200
LV Status                         available
# open                              1
LV Size                             595,75 GiB
Current LE                      152513
Segments                         2
Allocation                        inherit
Read ahead sectors       auto
– currently set to            256
Block device                   252:0

— Logical volume —
LV Path                           /dev/ubuntu-vg/swap_1
LV Name                        swap_1
VG Name                       ubuntu-vg
LV UUID                       hIOCtP-VwLS-Vcfa-d6ml-SQyY-2B3t-fz7mem
LV Write Access          read/write
LV Creation host, time ubuntu, 2016-06-06 16:49:38 +0200
LV Status                      available
# open                           2
LV Size                          4,00 GiB
Current LE                   1024
Segments                      1
Allocation                     inherit
Read ahead sectors    auto
– currently set to         256
Block device                252:1

  • estendiamo il volume logico

root@cloud:~# lvextend -l+100%FREE /dev/ubuntu-vg/root
Extending logical volume root to 745,75 GiB
Logical volume root successfully resized

  • Estendiamo il file system per UBUNTU

root@cloud:~# resize2fs /dev/mapper/ubuntu–vg-root
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/mapper/ubuntu–vg-root is mounted on /; on-line resizing required
old_desc_blocks = 38, new_desc_blocks = 47
The filesystem on /dev/mapper/ubuntu–vg-root is now 195493888 blocks long.

  • Estendiamo il file system per CentOS

meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=2455296 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=9821184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=4795, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 9821184 to 20317184

  • Tutto ok adesso un controllino
root@cloud:~# df -h
File system     Dim.     Usati     Dispon.    Uso%     Montato su
udev            2,0G     12K       2,0G       1%      /dev
tmpfs           396M     1,2M      395M       1%      /run
/dev/dm-0       734G     555G      148G       79%     /
none            4,0K     0         4,0K       0%      /sys/fs/cgroup
none            5,0M     0         5,0M       0%      /run/lock
none            2,0G     76K       2,0G       1%      /run/shm
none            100M     48K       100M       1%      /run/user
/dev/sda1       236M     71M       153M       32%     /boot

Facile no....
Ciao a tutti

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *