Vi sara capitato di avere la necessita in Linux estendere la partizione di root senza riavviare.
Questa procedura vi permetterà di estendere una partizione di root senza riavviare la VM. Solitamente per estendere la partizione di una vm la procedura più semplice è quella di utilizzare una LIVE CD, ma questo implica lo spegnimento della VM. In questo articolo vedremo come poter aumentare lo spazio della partizione che stiamo utilizzando senza riavviare la VM.
Qui vediamo la dimensione e il partizionamento del disco:
root@test:~# df -h / 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 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 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 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% /