Se avete la fortuna di utilizzare un sistema Linux virtualizzato, potrete struttare una serie di funzionalità interessanti, come ad esempio espandere al volo il disco di sistema.
Questa volta parlo di una VM con FileSystem Ext4, ma senza LVM. Non si può quindi seguire la guida per espandere un disco LVM.
Ipotizziamo un disco (/dev/sda) da 15GB che poi viene incrementato a 40GB lato host.
In elenco le procedure da seguire sono:
- Prendere nota dell’attuale distribuzione dello spazio
- Eliminare la partizione primaria
- Eliminare la partizione estesa
- Creare una nuova partiziona primaria iniziando dallo stesso settore di quella precedente e lasciare un po’ di spazio per lo swap
- Creare una partizione estesta con una partizione logica da usare come swap
Bene, procediamo.
ATTENZIONE: Benché la procedura sia semplice e collaudata, è molto facile fare danni. Consiglio vivamente uno snapshop da ripristinare all’occorrenza.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
~# fdisk /dev/sda Command (m for help): p Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0x42e4aa75 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 32088063 32086016 15,3G 83 Linux /dev/sda2 32090110 33552383 1462274 714M 5 Extended /dev/sda5 32090112 33552383 1462272 714M 82 Linux swap / Solaris Command (m for help): d Partition number (1-5): 1 Command (m for help): d Partition number (1-5): 2 Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): Using default value 1 First sector (2048-83886079, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079): 83886079 Command (m for help): p Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0x42e4aa75 Device Boot Start End Blocks Id System /dev/sda1 2048 83886079 82421760 83 Linux Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): e Partition number (1-4, default 2): 2 First sector (82423808-83886079, default 82423808): Using default value 82423808 Last sector, +sectors or +size{K,M,G} (82423809-83886079, default 83886079): Using default value 83886079 Command (m for help): p Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0x42e4aa75 Device Boot Start End Sectors Size Id Type /dev/sda1 2048 82423807 82421760 39,3G 83 Linux /dev/sda2 82423808 83886079 1462272 714M 5 Extended Command (m for help): n Partition type: p primary (1 primary, 1 extended, 2 free) l logical (numbered from 5) Select (default p): l Adding logical partition 5 First sector (82425856-83886079, default 82425856): Using default value 82425856 Last sector, +sectors or +size{K,M,G} (82425857-83886079, default 83886079): Using default value 83886079 Command (m for help): p Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0x42e4aa75 /dev/sda1 2048 82423807 82421760 39,3G 83 Linux /dev/sda2 82423808 83886079 1462272 714M 5 Extended /dev/sda5 82425856 83886079 1460224 713M 83 Linux Command (m for help): t Partition number (1-5): 5 Hex code (type L to list codes): 82 Changed system type of partition 5 to 82 (Linux swap / Solaris) Command (m for help): p Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0x42e4aa75 /dev/sda1 2048 82423807 82421760 39,3G 83 Linux /dev/sda2 82423808 83886079 1462272 714M 5 Extended /dev/sda5 82425856 83886079 1460224 713M 82 Linux swap / Solaris 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. ~# reboot |
Ora passiamo all’estensione del File System Ext4.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
~# df -h File system Dim. Usati Dispon. Uso% Montato su /dev/sda1 15G 3,5G 11G 25% / udev 10M 0 10M 0% /dev tmpfs 3,0G 8,7M 3,0G 1% /run ~# resize2fs /dev/sda1 resize2fs 1.42.5 (29-Jul-2012) Filesystem at /dev/sda1 is mounted on /; on-line resizing required old_desc_blocks = 6, new_desc_blocks = 16 The filesystem on /dev/sda1 is now 82421760 blocks long. ~# df -h File system Dim. Usati Dispon. Uso% Montato su /dev/sda1 39G 3,5G 35G 10% / udev 10M 0 10M 0% /dev tmpfs 3,0G 8,7M 3,0G 1% /run |
Bene, per concludere formattiamo lo swap:
1 2 3 |
~# mkswap /dev/sda5 Setting up swapspace version 1, size = 8384508 KiB no label, UUID=141d401a-b49d-4a96-9b85-c130cb0de40a |
1 |
~# swapon -a |
e poi ricordiamoci di modificare il file /etc/fstab per usare UUID=141d401a-b49d-4a96-9b85-c130cb0de40a (ad esempio nel nostro caso) per il corretto montaggio in fase di boot.
Nota GNU/Debian Stretch:
Ho effettuato la procedura su una nuova GNU/Debian Stretch ed al riavvio ha iniziato a visualizzare una serie di righe come segue, rallentando la procedura:
...
blk_update_request: I/O error, dev fd0, sector 0
...
In questo caso, basta eseguire un:
update-initramfs -u
Se per caso viene visualizzato un messaggio tipo:
W: initramfs-tools configuration sets RESUME=UUID=XXXXXXXXXX
W: but no matching swap device is available.
bisogna commentare la riga nel file /etc/initramfs-tools/conf.d/resume e poi rieseguire:
update-initramfs -u
ed infine riavviare.
enjoy!
Se hai trovato utili le informazioni su questo blog,
Fai una donazione!
Clicca sul bottone qui sotto o almeno clicca sul banner pubblicitario 🙂
Commenta