Sei sulla pagina 1di 5

Come estendere un disco virtuale (img)

Visualizzare i dischi montati: df -Th


/dev/mapper/vg_vsrv1-lv_root ext4 45G 5.2G 38G 13% /
tmpfs tmpfs 939M 76K 939M 1% /dev/shm
/dev/vda1 ext4 477M 119M 333M 27% /boot
/dev/vdb1 ext4 197G 72G 115G 39% /home/Server
/dev/vdc1 ext4 246G 168G 66G 72% /home/DocTecnica
/dev/vdd1 ext4 976M 907M 18M 99% /home/Amministrazione
/dev/vde1 ext4 99G 44G 50G 47% /home/Manuali
/dev/vdf1 ext4 197G 101G 87G 54% /home/Utenti
/dev/vdg1 ext4 99G 69G 25G 74% /home/Foto
/dev/vdk1 ext4 197G 50G 138G 27% /home/Comm
/dev/vdi1 ext4 1008G 856G 102G 90% /home/Software
/dev/sda1 ext4 5.4T 5.1T 30G 100% /home/Ghost
/dev/vdh1 ext4 197G 288M 187G 1% /home/Qualita
/dev/sdb1 ext4 5.3T 417G 4.7T 9% /home/Ghost2

Visualizzare i block device: lsblk -f


NAME FSTYPE LABEL UUID MOUNTPOINT
sr0
vda
├─vda1 ext4 6d4e2bb3-78a3-4e93-a5e4-88472cda4d20 /boot
└─vda2 LVM2_mem PmoyWU-vixW-20Kn-JIMb-X7Ov-YiYN-S05LAB
├─vg_vsrv1-lv_root (dm-0)
ext4 19931151-ca78-4071-91b0-96dec37b5247 /
└─vg_vsrv1-lv_swap (dm-1)
swap 4c28404e-cd33-4a2a-97fb-54f6c1e12da0 [SWAP]
vdb
└─vdb1 ext4 a79e1bd4-3995-4572-bd36-da13f31608c9 /home/Server

Visualizzare le caratteristiche dei dischi e delle partizioni: fdisk -l


Disk /dev/vdd: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System


/dev/vdd1 1 1045 8388607+ ee GPT

Visualizzare il contenuto di file immagine KVM .img


losetup -f viene generato il /dev/loop0
losetup /dev/loop0 /var/lib/libvirt/images/disco1.img viene mappata l’immagine al file loop0
losetup -a, visualizza i file di loop e associazioni
kpartx -av /dev/loop0 vengono generati gli special file in /dev/mapper per le partizioni, loop0p1, loop0p2 ecc
mount /dev/mapper/loop0p1 /mnt montare la partizione
umount /mnt smontare la partizione
kpartx -dv /dev/loop0 eliminare gli special file
losetup -d /dev/loop0 eliminare il loop creato

Se LVM usare lvdisplay e special file /dev/mapper/lv_root ….

Aggiungere un disco virtuale alla VM


Avviare Virtual Manager, aprire la VM e selezionare dettagli
Selezionare aggiungi nuovo hardware, selezionare storage e compilare i campi come segue

Aprire un terminale o sessione SSH e individuare il nuovo disco con il comando fdisk -l
Creare la partizione con il comando fdisk /dev/<nome del disco virtuale>, procedere come segue:
p + invio, non ci sono partizioni
n + invio, crea la nuova partizione
t + invio, impostare il tipo di partizione (Default 83 Linux)
w + invio, salva la nuova configurazione
Formattare la partizione in formato ext4 con il comando: mkfs.ext4 /dev/<nome specialfile>
Creare una cartella dove montare il nuovo disco virtuale, mkdir /home/<nome cartella>
Montare la cartella, mount /dev/<nome special file> <nome cartella>
Se tutto funziona correttamente, smontare la cartella e inserire permanentemente la mount in fstab

Condivisione Samba
Editare /etc/smb.conf e inserire la nuova condivisione
[<nome condivisione>]
path = /home/<nome cartella>
read only = no

Ricaricare la configurazione di samba con il comando: smbcontrol smbd reload-config

METHOD #1: Partitions are ext2/ext3/ext4 based

The nuts of this method are as follows:

# 1. stop the VM
# 2. move the current image
mv mykvm.img mykvm.img.bak

# 3. create a new image


qemu-img create -f raw addon.raw 30G

# 4. concatenate the 2 images


cat mykvm.img.bak addon.raw >> mykvm.img

Now with the larger mykvm.img file in hand, boot gparted and extend the
existing partition into the newly added disk space. This last step
basically extends the OS partition so that it can make use of the extra
space.

METHOD #2: Partitions are LVM based

Here are the steps that I roughly followed to resize a KVM guest that
used LVM internally.

Shutdown the VM
add more space to the guest's "image file" (something like: cat
old.img 10G_addon.raw >> new.img
start the VM (using the newly created new.img)

run fdisk inside VM and delete & re-create LVM partition

% fdisk /dev/vda
...
Device Boot Start End Blocks Id System
/dev/vda1 * 1 13 104391 83 Linux
/dev/vda2 14 3263 26105625 8e Linux LVM

Command (m for help): d


Partition number (1-4): 2

Command (m for help): p

Disk /dev/vda: 48.3 GB, 48318382080 bytes


255 heads, 63 sectors/track, 5874 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


/dev/vda1 * 1 13 104391 83 Linux

Command (m for help): n


Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-5874, default 14): 14
Last cylinder or +size or +sizeM or +sizeK (14-5874, default 5874):
Using default value 5874

Command (m for help): p

Disk /dev/vda: 48.3 GB, 48318382080 bytes


255 heads, 63 sectors/track, 5874 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


/dev/vda1 * 1 13 104391 83 Linux
/dev/vda2 14 5874 47078482+ 83 Linux

Command (m for help): t


Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/vda: 48.3 GB, 48318382080 bytes


255 heads, 63 sectors/track, 5874 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


/dev/vda1 * 1 13 104391 83 Linux
/dev/vda2 14 5874 47078482+ 8e Linux LVM

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.
Syncing disks.
%

Reboot the VM

Resize the LVM physical volume

% pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name VolGroup00
PV Size 24.90 GB / not usable 21.59 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 796
Free PE 0
...

% pvresize /dev/vda2
% pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name VolGroup00
PV Size 44.90 GB / not usable 22.89 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 1436
Free PE 640
...

Resize the LVM Logical Volume

% lvresize /dev/VolGroup00/LogVol00 -l +640


Extending logical volume LogVol00 to 43.88 GB
Logical volume LogVol00 successfully resized

Grow the File system

% resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line
resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to
11501568 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 11501568 blocks
long.

File System Check Fail

Montare l’immagine del disco virtuale utilizzando il device di loop come


segue:

Esempio:
lenny.img è il file immagine in formato raw che contiene i dati della
macchina virtuale (sia Xen o QEMU (eventualmente KVM).

# losetup /dev/loop0 lenny.img

Il comando non fa altro che creare un dispositivo loop, qui si è scelto


il numero 0 ma se dovesse essere già occupato (usato da qualche altro
programma) è possibile sostituire loop0 con loop1, loop2… (avendo cura di
ricordare il cambiamento e riportarlo in tutti i passaggi della
procedura).

# kpartx -av /dev/loop0

Lo strumento kpartx non fa altro che leggere la tabella delle partizioni


del device specificato e crea un device map per ogni segmento di
partizione riconosciuto

Ora col comando mount si deve innestare il device map della prima
partizione su una directory del host. In questo caso è stato scelto /mnt

# mount /dev/mapper/loop0p1 /mnt/

Per smontare la partizione dal device map:

# umount /dev/mapper/loop0p1
Dissociare le partizioni dal device map:

# kpartx -vd /dev/loop0

Rimuovere i device map

# losetup -d /dev/loop0

Visualizzare tutte le mappature

# losetup -a

Potrebbero piacerti anche