Estensione e riduzione del file system ext4 su iSCSI
Adesso vediamo come estendere il file system ext4 creati precedentemente su iSCSI e LVM sul target
Premessa
Il presente howto è basato su quanto creato qui, ovvero un'architettura basata su un sistema iSCSI target (server) con Ubuntu LTS 10.04 che esporta una partizione LVM, ed un'altro sistema iSCSI Initiator (client) basato anch'esso su Ubuntu LTS 10.04 che si aggancia alla partizione LVM in modalità esclusiva. Per maggiori dettagli, anche architetturali potete fare riferimento qui, di seguito vedremo:
- come espandere un LVM;
- come espandere un file system ext4;
- come effettuare la riduzione (shrink) di un file system ext4.
Di seguito la tabella riassuntiva dei sistemi coinvolti:
| l64ubuntu01 | l64ubuntu02 | |
|---|---|---|
| IP |
192.168.1.100 | 192.168.1.64 |
| S.O. |
Ubuntu LTS 10.04 |
Ubuntu LTS 10.04 |
| Kernel |
2.6.32-31-server | 2.6.32-31-server |
| Tipologia |
Target |
Initiator |
Estensione delle partizioni LVM
Prima di estendere il file system dovremo procedere con l'estensione dei logical volume sul sistema iSCSI Target, per fare questo ovviamente dovremo avere a disposizione degli extent liberi sul volume group.
Verifichiamo quanti extent abbiamo a disposizione
root@l64ubuntu01:~# vgdisplay ISCSI_VG0 --- Volume group --- VG Name ISCSI_VG0 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 1.99 GiB PE Size 8.00 MiB Total PE 255 Alloc PE / Size 75 / 600.00 MiB Free PE / Size 180 / 1.41 GiB VG UUID dWVmNy-VaG2-ebDb-1rN6-Rtur-1n4c-5mBrJH
Da qui possiamo vedere che sono presenti 180 physical extent liberi da 8MiB ciascuno che andremo ad utilizzare parzialmente per l'estensione.
Per vedere il dettaglio del volume logico
root@l64ubuntu01:~# lvdisplay /dev/ISCSI_VG0/LOC_LUN1 --- Logical volume --- LV Name /dev/ISCSI_VG0/LOC_LUN1 VG Name ISCSI_VG0 LV UUID klpSPt-iJa6-fGez-tjZu-ZLAJ-K5yS-PobGJc LV Write Access read/write LV Status available # open 1 LV Size 200.00 MiB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 251:3
E come viene agganciato e visto dal nostro Initiator (client)
root@l64ubuntu02:~# fdisk -l /dev/sda Disk /dev/sda: 209 MB, 209715200 bytes 7 heads, 58 sectors/track, 1008 cylinders Units = cylinders of 406 * 512 = 207872 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x408a6f13 Device Boot Start End Blocks Id System /dev/sda1 1 1008 204595 83 Linux
Come potete vedere i 200 MiB del nostro volume logico LOC_LUN1 vengono visti da fdisk come circa 209 MB, questo perchè fdisk utilizza nel calcolo dello spazio multipli di 1000, invece le utility lvm utilizzano le potenze del due nel calcolo, questa peculiarità è da considerare quando andremo a ridimensionare il file system, per ora basta sapere che ogni Unit è di 207872 bytes e che il nostro disco /dev/sda ha 1008 cilindri per un totale di circa 209 MB.
Estensione del logical volume sul Target
Per prima cosa estenderemo il volume logico sul nostro Target (server) iSCSI a 400MiB di cabienza totale
root@l64ubuntu01:~# lvextend -l +25 /dev/ISCSI_VG0/LOC_LUN1 Extending logical volume LOC_LUN1 to 400.00 MiB Logical volume LOC_LUN1 successfully resized
Ovvero andremo ad aggiunre ulteriori 25 extent ai 25 già presenti di 8 MiB ciascuno.
Restart dei servizi
Per rendere visibile sull'initiator la nuova dimensione del disco servirà riavviare i servizi iscsitarget sul target e open-iscsi sull'initiator, ma prima bisognerà smontare il file system sempre sull'initiator
root@l64ubuntu02:~# umount /mnt/app1/
Stop dell'initiator
root@l64ubuntu02:~# /etc/init.d/open-iscsi stop * Disconnecting iSCSI targets [ OK ] * Stopping iSCSI initiator service [ OK ]
Adesso sul target possiamo eseguire il restart
root@l64ubuntu01:~# /etc/init.d/iscsitarget restart
* Removing iSCSI enterprise target devices [ OK ]
* Stopping iSCSI enterprise target service [ OK ]
* Removing iSCSI enterprise target modules
[fail]
* Starting iSCSI enterprise target service [ OK ]
E riavviare nuovamente l'initiator
root@l64ubuntu02:~# /etc/init.d/open-iscsi start * Starting iSCSI initiator service iscsid [ OK ] ln: target `/lib/init/rw/sendsigs.omit.d/' is not a directory: No such file or directory * Setting up iSCSI targets [ OK ]
Verifichiamo adesso la dimensione del nostro disco
root@l64ubuntu02:~# fdisk -l /dev/sda Disk /dev/sda: 419 MB, 419430400 bytes 7 heads, 58 sectors/track, 2017 cylinders Units = cylinders of 406 * 512 = 207872 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x408a6f13 Device Boot Start End Blocks Id System /dev/sda1 1 1008 204595 83 Linux
Come potete vedere la dimensione del disco è diventata di 419MB ed il numero totale di cilindri è passato da 1008 a 2017. Ora non ci resta che estendere questa partizione fino a ricoprire l'intera area del disco, ovvero i 2017 cilindri.
Estensione del file system ext4
Per estendere un file system ext utilizzeremo il comando resize2fs, ma prima di fare questo dovremo creare una nuova tabella delle partizioni sul nostro disco /dev/sda e per fare questo utilizzeremo l'utility fdisk.
Ma per prima cosa, se ancora non è stato fatto smontiamo il file system
root@l64ubuntu02:~# umount /mnt/app1
Ed eseguiamo un file system check
root@l64ubuntu02:~# e2fsck -f /dev/sda1 e2fsck 1.41.11 (14-Mar-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sda1: 12/51200 files (0.0% non-contiguous), 12110/204592 blocks
Modifica della tabella delle partizioni
Per estendere la nostra partizione /dev/sda1 utilizzeremo fdisk andando prima a cancellare la partizione esistente per poi ricrearne una nuova con la nuova dimensione
root@l64ubuntu02:~# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/sda: 419 MB, 419430400 bytes
7 heads, 58 sectors/track, 2017 cylinders
Units = cylinders of 406 * 512 = 207872 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x408a6f13
Device Boot Start End Blocks Id System
/dev/sda1 1 1008 204595 83 Linux
Command (m for help): d
Selected partition 1
Command (m for help): p
Disk /dev/sda: 419 MB, 419430400 bytes
7 heads, 58 sectors/track, 2017 cylinders
Units = cylinders of 406 * 512 = 207872 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x408a6f13
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2017, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2017, default 2017):
Using default value 2017
Command (m for help): p
Disk /dev/sda: 419 MB, 419430400 bytes
7 heads, 58 sectors/track, 2017 cylinders
Units = cylinders of 406 * 512 = 207872 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x408a6f13
Device Boot Start End Blocks Id System
/dev/sda1 1 2017 409422 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Come potete vedere viene eseguita prima la delete con il comando "d" e poi viene creata una nuova partizione con il comando "n", questa nuova partizione dovrà essere primaria come la precedente ("p") ed iniziare allo stesso punto della precedente (1), mentre potrà occupare tutto lo spazio disponibile fino alla fine del disco (cilindro 2017).
Estensione
Adesso non ci resta che estendere il file system, ma prima eseguiamo nuovamente il file system check
root@l64ubuntu02:~# e2fsck -f /dev/sda1 e2fsck 1.41.11 (14-Mar-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sda1: 12/51200 files (0.0% non-contiguous), 12110/204592 blocks
ed in ultimo il resize
root@l64ubuntu02:~# resize2fs /dev/sda1 resize2fs 1.41.11 (14-Mar-2010) Resizing the filesystem on /dev/sda1 to 409420 (1k) blocks. The filesystem on /dev/sda1 is now 409420 blocks long.
Con il comando precedente diciamo a resize2fs di prendersi tutto lo spazio a disposizione. Andiamo a verificare la nuova dimensione
root@l64ubuntu02:~# mount /mnt/app1/ root@l64ubuntu02:~# df -m /mnt/app1 Filesystem 1M-blocks Used Available Use% Mounted on /dev/sda1 388 7 378 2% /mnt/app1
Riduzione del file system ext4
Nel caso si voglia ridurre la partizione logica /dev/sda1 dagli attuali 400MiB a circa 296MiB bisognerà procedere in modo inverso alla sua estensione. Ovvero i macro passi logici saranno
- smontaggio del file system;
- riduzione del file system ext4 sull'initiator;
- riduzione della tabella delle partizioni sull'initiator;
- riduzione del logical volume sul target;
- riavvio dei servizi sul target e sull'initiator.
Comandi da eseguire sull'initiator
Iniziamo a smontare il file system sull'initiator
root@l64ubuntu02:~# umount /mnt/app1
e ad eseguire il check del file system
root@l64ubuntu02:~# e2fsck -f /dev/sda1 e2fsck 1.41.11 (14-Mar-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sda1: 12/102400 files (0.0% non-contiguous), 19334/409420 blocks
ora non ci resta che diminuire lo spazio occupato da ext4 con una dimensione di circa 290 MiB. Bisogna fare attenzione al fatto che il tutto si appoggia sui physical extent di LVM presenti sul Target iSCSI, che nel nostro caso sono di 8 MiB ciascuno, pertanto il consiglio è tenersi leggermente al di sotto della dimensione totale e poi successivamente una volta ridotto il logical volume sul target si potrà eseguire nuovamente il resize su tutto lo spazio disponibile.
Riduzione a 290 MiB
root@l64ubuntu02:~# resize2fs /dev/sda1 290M resize2fs 1.41.11 (14-Mar-2010) Resizing the filesystem on /dev/sda1 to 296960 (1k) blocks. The filesystem on /dev/sda1 is now 296960 blocks long.
Se volete potete verificare la dimensione attuale montando la partizione ed eseguendo il comando df
root@l64ubuntu02:~# mount /mnt/app1 root@l64ubuntu02:~# df -m /mnt/app1 Filesystem 1M-blocks Used Available Use% Mounted on /dev/sda1 281 7 272 3% /mnt/app1
Ricordatevi di smontare il file system prima di continuare
root@l64ubuntu02:~# umount /mnt/app1
Ridimensionamento della tabella delle partizioni
Prima di ridurre il logical volume sul Target dovremo ridimensionare la tabella delle partizioni sull'Initiator, e per fare questo ci basterà utilizzare l'utility fdisk. Per ridurre a 296 MiB dovremmo effettuare alcuni semplici calcoli, ovvero ricavarci tramite fdisk il valore della "Units" in bytes che nel nostro esempio corrisponde a 207872 byte e con questo valore calcolarci il multiplo di cilindri per arrivare a 296 MiB, che nel nostro caso corrisponde a 1493. Questo numero lo utilizzeremo come limite superiore per la partizione sda1
root@l64ubuntu02:~# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/sda: 419 MB, 419430400 bytes
7 heads, 58 sectors/track, 2017 cylinders
Units = cylinders of 406 * 512 = 207872 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x408a6f13
Device Boot Start End Blocks Id System
/dev/sda1 1 2017 409422 83 Linux
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2017, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-2017, default 2017): 1493
Command (m for help): p
Disk /dev/sda: 419 MB, 419430400 bytes
7 heads, 58 sectors/track, 2017 cylinders
Units = cylinders of 406 * 512 = 207872 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x408a6f13
Device Boot Start End Blocks Id System
/dev/sda1 1 1493 303050 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Sopra potete vedere come viene prima eliminata la partizione sda1 e poi ricreata occupando soltanto 1493 cilindri, che corrispondono a circa 296 MiB.
Una volta fatto questo eseguiamo lo stop del servizio open-iscsi sull'initiator
root@l64ubuntu02:~# /etc/init.d/open-iscsi stop * Disconnecting iSCSI targets [ OK ] * Stopping iSCSI initiator service [ OK ]
Riduzione del volume logico sul target
Non ci resta che ridurre il nostro volume logico LOC_LUN1 sul target a 296 MiB, che considerando la dimensione di 8 MiB di ciascun physical extent, ci basterà ridurli a 37 in totale
root@l64ubuntu01:~# lvreduce -l 37 /dev/ISCSI_VG0/LOC_LUN1 WARNING: Reducing active and open logical volume to 296.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce LOC_LUN1? [y/n]: y Reducing logical volume LOC_LUN1 to 296.00 MiB Logical volume LOC_LUN1 successfully resized
Restart dei servizi
In ultimo ci basterà eseguire il restart del servizio iscsitarget sul Target e startare nuovamente il servizio open-iscsi sull'initiator.
Restart di iscsitarget sul target
root@l64ubuntu01:~# /etc/init.d/iscsitarget restart
* Removing iSCSI enterprise target devices [ OK ]
* Stopping iSCSI enterprise target service [ OK ]
* Removing iSCSI enterprise target modules
[ OK ]
* Starting iSCSI enterprise target service [ OK ]
Start di open-iscsi sull'initiator
root@l64ubuntu02:~# /etc/init.d/open-iscsi start * Starting iSCSI initiator service iscsid [ OK ] ln: target `/lib/init/rw/sendsigs.omit.d/' is not a directory: No such file or directory * Setting up iSCSI targets [ OK ]
Verifica della dimensione del disco sull'initiator
root@l64ubuntu02:~# fdisk -l /dev/sda Disk /dev/sda: 310 MB, 310378496 bytes 7 heads, 58 sectors/track, 1493 cylinders Units = cylinders of 406 * 512 = 207872 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x408a6f13 Device Boot Start End Blocks Id System /dev/sda1 1 1493 303050 83 Linux
In ultimo se si desidera espandere il file system ext4 precedentemente creato di 290 MiB basterà eseguire nuovamente il comando resize2fs
root@l64ubuntu02:~# resize2fs /dev/sda1 resize2fs 1.41.11 (14-Mar-2010) Resizing the filesystem on /dev/sda1 to 303048 (1k) blocks. The filesystem on /dev/sda1 is now 303048 blocks long.
Adesso possiamo montare la partizione
root@l64ubuntu02:~# mount /mnt/app1 root@l64ubuntu02:~# df -m /mnt/app1 Filesystem 1M-blocks Used Available Use% Mounted on /dev/sda1 287 7 278 3% /mnt/app1
Conclusioni
Abbiamo visto come estendere e diminuire una partizione ext4 andando a manipolare la tabella della partizioni sul nostro client iSCSI Initiator, ed anche come effettuare le operazioni corrispondenti sul server iSCSI Target, che però utilizza partizioni LVM.
