Inserisci qui la tua pubblicità
Linux - Come aumentare l'HDD senza perdere dati
Assegnare Maggiore Spazio di archiviazione senza perdita di dati
In questo articolo andiamo a vedere come aumentare lo spazio di archiviazione del nostro VPS (Virtual Private Server) con sistema operativo Linux.
Capita molti infatti che acquistando un server VPS, quest'ultimo si acquisti nella versione basilare, sia per risparmiare , sia perché se in futuro si avrà bisogno di maggiore hardware i VPS permettono di essere upgradati.
Ma vediamo come effettuare l'upgrade dello spazio di archiviazione senza tuttavia perdere i dati presenti nel nostro server. Nel mio caso passero da un VPS SSD1 con 10 gb di archiviazine a un VPS SSD2 con 20 GB di archiviazione.
Questa guida è valida per qualsiasi sistema operativo Linux.
Nel mio caso, avevo raggiunto la dimensione massima di archiviazione in un VPS ssd di livello 1 acquistato su ovh.com.
Per risolvere il problema ho prima acquistato il servizio Snapshot. Lo snapshot permette di effettuare il salvataggio di tutta la macchina virtuale così com'è comprendente quindi:
- Lo stato di tutti i dischi della macchina virtuale
- Il contenuto della memoria della macchina virtuale
Lo snapshop è consigliato a tutti, ci mette al riparo da qualsiasi perdita di dati causati da un nostro errore o da un guasto, in quanto il backup non sarà fatto sul nostro stesso ssd.
Procediamo, colleghiamoci al nostro VPS tramite terminale ssh, e assegniamoci i comandi di root per farlo bisogna effettuare l'accesso come root, oppure far diventare il nostri user root con il comando:
sudo su
La prima cosa da fare è controllare le partizioni presenti sul disco:
[root]# fdisk -l
L’output del precedente comando dovrebbe essere simile al seguente:
Qui vediamo la dimensione e il partizionamento del disco:
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 24G 1008M 22G 5% /
root@test:~# fdisk -l /dev/vda
Disk /dev/vda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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
Disk identifier: 0x0009256d
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 50329215 25163584 83 Linux
/dev/vda2 50329216 52426367 1048576 82 Linux swap / Solaris
Prima di tutto è necessario assicurarsi di disabilitare lo swap:
root@test:~# swapoff -a
root@test:~# free -m
total used free shared buffers cached
Mem: 1024 324 700 0 10 120
-/+ buffers/cache: 46 715
Swap: 0 0 0
Ora rimuoviamo la partizione di swap e si estendono partizione root. Dal comando precedente fdisk possiamo vedere che la nostra partizione di swap è seconda (/ dev / vda2).
Nei seguenti passi andremo a rimuovere la partizione di swap e la partizione di root, creare la partizione di root con il nuovo formato.
root@test:~# fdisk /dev/vda
Il risultato
Command (m for help): p
Disk /dev/vda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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
Disk identifier: 0x0009256d
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 50329215 25163584 83 Linux
/dev/vda2 50329216 52426367 1048576 82 Linux swap / Solaris
Command (m for help): d
Partition number (1-4): 2
Command (m for help): d
Selected partition 1
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +103809023
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 2):
Using default value 2
First sector (103811072-104857599, default 103811072):
Using default value 103811072
Last sector, +sectors or +size{K,M,G} (103811072-104857599, default 104857599):
Using default value 104857599
Command (m for help): p
Disk /dev/vda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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
Disk identifier: 0x0009256d
Device Boot Start End Blocks Id System
/dev/vda1 2048 103811071 51904512 83 Linux
/dev/vda2 103811072 104857599 523264 83 Linux
Prima di scrivere le modifiche su disco dobbiamo impostare tipo di partizione appropriato e fare partizione root avviabile:
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 83
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/vda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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
Disk identifier: 0x0009256d
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 103811071 51904512 83 Linux
/dev/vda2 103811072 104857599 523264 82 Linux swap / Solari
Ora scriviamo le modifiche sul disco e tabella delle partizioni (tabella delle partizioni per rileggere è possibile che sia necessario riavviare la VM) in modo che il sistema possa vedere nuove dimensioni:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
root@test:~# partprobe
root@test:~# fdisk -l
Il risultato:
Disk /dev/vda: 53.7 GB, 53687091200 bytes
16 heads, 63 sectors/track, 104025 cylinders, total 104857600 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
Disk identifier: 0x0009256d
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 103811071 51904512 83 Linux
/dev/vda2 103811072 104857599 523264 82 Linux swap / Solaris
Ora possiamo vedere le partizioni ridimensionate, ma il filesystem della partizione di root deve essere ridimensionata.
root@test:~# resize2fs /dev/vda1
Il risultato sarà:
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/vda1 is now 12976128 blocks long.
root@test:~# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 49G 1009M 46G 3% /
barone.anto1@gmail.com
Iscriviti alla nostra newsletter
Iscriviti alla nostra newsletter per non perderti nessuna novità!