Procedimento Para Gerenciar a LVM No HP

30
Procedimento para gerenciar a LVM no HP-UX por NoComments em Sáb Jan 12, 2008 11:36 pm Quando voce instala a maquina ja e possivel definir o numero de filesystems desejados e o tamanho de cada um. Porem, com o passar do tempo, dependendo dos recursos de disco consumidos pela sua aplicacao, ou devido a compra de discos adicionais, torna-se necessario alterar a configuracao inicial: ou voce aumenta o tamanho de um filesystem, ou o diminui, ou cria novos filesystems. Vamos reforcar alguns conceitos de uma forma bem simples antes de prosseguirmos com os exemplos: VG == Volume Group: e o grupo de volumes de disco configurados na maquina. Em cada VG voce pode incluir 1 ou mais discos. LVOL == Logical Volume: e a particao do disco. Quando voce criar o disco em um VG, deve particiona-lo (em 1 ou mais "pedacos"). File System: depois de particionado o disco, voce podera criar um sistema de arquivos para montar em um diretorio. OBS.: Se voce precisar usar um "raw device", basta criar o VG e o LVOL (nao precisa criar o filesystem). Queremos tambem ressaltar algumas observacoes importantes: - O barra (/), onde esta o "/dev/vg00/lvol1", nao pode ser modificado, ou seja, nao e possivel aumentar e nem diminuir o seu tamanho. Para altera-lo, e necessario uma reinstalacao do Sistema Operacional.

Transcript of Procedimento Para Gerenciar a LVM No HP

Page 1: Procedimento Para Gerenciar a LVM No HP

Procedimento para gerenciar a LVM no HP-UX

por NoComments em Sáb Jan 12, 2008 11:36 pm

Quando voce instala a maquina ja e possivel definir o numero de filesystems desejados e o tamanho de cada um. Porem, com o passar do tempo, dependendo dos recursos de disco consumidos pela sua aplicacao, ou devido a compra de discos adicionais, torna-se necessario alterar a configuracao inicial: ou voce aumenta o tamanho de um filesystem, ou o diminui, ou cria novos filesystems.

Vamos reforcar alguns conceitos de uma forma bem simples antes de prosseguirmos com os exemplos:

VG == Volume Group: e o grupo de volumes de disco configurados na maquina. Em cada VG voce pode incluir 1 ou mais discos.

LVOL == Logical Volume: e a particao do disco. Quando voce criar o disco em um VG, deve particiona-lo (em 1 ou mais "pedacos").

File System: depois de particionado o disco, voce podera criar umsistema de arquivos para montar em um diretorio.

OBS.: Se voce precisar usar um "raw device", basta criaro VG e o LVOL (nao precisa criar o filesystem).

Queremos tambem ressaltar algumas observacoes importantes:

- O barra (/), onde esta o "/dev/vg00/lvol1", nao pode sermodificado, ou seja, nao e possivel aumentar e nem diminuir o seutamanho. Para altera-lo, e necessario uma reinstalacao do SistemaOperacional.

- Voce pode alterar os volumes, atraves do SAM ou manualmente, comexcecao do /usr (se estiver em um volume logico separado do "/"), oqual deve ser alterado apenas manualmente.

- Para alterar os volumes logicos (lvols), eles devem estardesmontados.

- Nunca deixe de fazer backup regularmente e principalmente antes dequalquer alteracao na configuracao do LVM.

A seguir listamos 8 exemplos de duvidas que ocorrem com maisfrequencia:

A - Como criar um novo VG;

Page 2: Procedimento Para Gerenciar a LVM No HP

B - Como remover um VG;C - Como incluir um disco novo em um VG ja existente;D - Como excluir um disco de um VG;E - Como criar um novo LVOL;F - Como remover um LVOL;G - Como aumentar o tamanho de um LVOL;H - Como diminuir o tamanho de um LVOL.

A - ) COMO CRIAR UM NOVO VG:

Nesse exemplo supomos que voce tinha apenas 1 disco configurado namaquina e agora vai criar um novo VG para o segundo disco (um disconovo):

1) Execute o comando "ioscan" para saber o endereco do disco:

# /usr/sbin/ioscan -fC disk

Class I H/W Path Driver S/W State H/W Type Description================================================================disk 1 52.5.0 disc3 CLAIMED DEVICE HP C2474S disk 0 52.6.0 disc3 CLAIMED DEVICE HP C2247M1

Observe que temos um disco no endereco 6 e outro no endereco 5.

2) Verifique qual dos dois esta alocado no(s) VG(s) existente(s):

# /sbin/vgdisplay -v | grep "PV Name"PV Name /dev/dsk/c0t6d0

Observe que realmente so temos um disco alocado em VG. Note queesse disco e o dispositivo "c0t6d0", o qual esta no endereco 6.O disco de endereco 5 e o de dispositivo "c0t5d0".

3) Crie um novo VG para o novo disco:

# mkdir /dev/vg01# mknod /dev/vg01/group c 64 0x010000 |_> esse valor nao pode ser repetido# /sbin/pvcreate /dev/rdsk/c0t5d0# /sbin/vgcreate /dev/vg01 /dev/dsk/c0t5d0

B - ) COMO REMOVER UM VG:

Page 3: Procedimento Para Gerenciar a LVM No HP

Assumimos nesse exemplo que voce tem dois discos no VG01 e esse VGtem dois LVOLs criados:

1) Devemos, em primeiro lugar, desmontar os filesystems do VG emquestao:

# /usr/sbin/umount /dev/vg01/lvol1# /usr/sbin/umount /dev/vg01/lvol2

2) Agora, vamos remover os LVOLs criados para ele:

# /sbin/lvremove -f /dev/vg01/lvol1 /dev/vg01/lvol2

3) Em seguida, descobrimos quais discos fazem parte do VG01, pararemovermos:

# /sbin/vgdisplay -v vg01 | grep "PV Name"PV Name /dev/dsk/c0t5d0PV Name /dev/dsk/c0t4d0

4) Verificamos nesse exemplo que temos dois discos no VG01.Devemos remover "quase todos os discos" do VG01 (somentedeixamos um):

# /sbin/vgreduce /dev/vg01 /dev/dsk/c0t4d0

5) Restando apenas um disco no VG, basta remove-lo:

# /sbin/vgremove /dev/vg01

C - ) COMO INCLUIR UM DISCO NOVO EM UM VG JA EXISTENTE:

Assumimos nesse exemplo que voce somente tem o VG00, com um disco.Vamos incluir o novo disco nesse mesmo VG:

1) Execute o comando "ioscan" para saber o endereco do disco:

# /usr/sbin/ioscan -fC disk

Class I H/W Path Driver S/W State H/W Type Description================================================================

Page 4: Procedimento Para Gerenciar a LVM No HP

disk 1 52.5.0 disc3 CLAIMED DEVICE HP C2474S disk 0 52.6.0 disc3 CLAIMED DEVICE HP C2247M1

Observe que temos um disco no endereco 6 e outro no endereco 5.

2) Verifique qual dos dois esta alocado no(s) VG(s) ja existente(s):

# /sbin/vgdisplay -v | grep "PV Name"PV Name /dev/dsk/c0t6d0

Observe que realmente so temos um disco alocado em VG. Note queesse disco e o dispositivo "c0t6d0", o qual esta no endereco 6.O disco de endereco 5 e o de dispositivo "c0t5d0".

3) Agora e so inclui-lo no VG00:

# /sbin/pvcreate /dev/rdsk/c0t5d0# /sbin/vgextend /dev/vg00 /dev/dsk/c0t5d0

D - ) COMO EXCLUIR UM DISCO DE UM VG:

Assumimos nesse exemplo que voce tem dois discos no VG01 e esse VG tem dois LVOLs criados. O disco a ser removido e o de endereco 4. Tome o seguinte cuidado: pode ser que um determinado LVOL esteja ocupando uma parte de cada disco. Nesse caso, esse LVOL e perdido.

1) Devemos, em primeiro lugar, desmontar os filesystems do VG emquestao:

# /usr/sbin/umount /dev/vg01/lvol1# /usr/sbin/umount /dev/vg01/lvol2

2) E necessario descobrir quais LVOLs fazem parte do disco deendereco 4:

# /sbin/lvdisplay -v /dev/vg01/lvol2 | pg--- Logical volumes ---...--- Distribution of logical volume ---PV Name LE on PV PE on PV/dev/dsk/c0t5d0 12 12/dev/dsk/c0t4d0 40 40 ||\\==========> essa e a informacao que nos interessa.

Page 5: Procedimento Para Gerenciar a LVM No HP

--- Logical extends ---...

# /sbin/lvdisplay -v /dev/vg01/lvol1 | pg--- Logical volumes ---...--- Distribution of logical volume ---PV Name LE on PV PE on PV/dev/dsk/c0t5d0 12 12||\\==========> essa e a informacao que nos interessa.--- Logical extends ---...

Observe que nos comandos acima conseguimos visualizar que oLVOL2 ocupa dois discos e o LVOL1 ocupa apenas um. O LVOL queesta ocupando o disco a ser removido e o LVOL2.

3) Agora vamos remover o LVOL que ocupa o disco em questao:

# /sbin/lvremove -f /dev/vg01/lvol2

4) Livre de LVOLs, basta remover o disco do VG:

# /sbin/vgreduce /dev/vg01 /dev/dsk/c0t4d0

E - ) COMO CRIAR UM NOVO LVOL:

Nao se esqueca que para criar um LVOL, o VG ja deve estar previamente criado. Nesse exemplo assumimos que o VG01 ja esta criado, ja possui o LVOL1 e agora queremos usar o restante de seu espaco para criar outro LVOL (lvol2).

1) Primeiro devemos descobrir se ha espaco desalocado no VG equanto de espaco ainda ha disponivel:

# /sbin/vgdisplay vg01 | grep FreeFree PE 25

Se o numero resultante desse comando for 0, significa que naosera possivel criar um novo LVOL.

2) Vamos criar um LVOL com 25 extensoes (que tem 4Mb cada uma). Otamanho em bytes e de (25 * 4) == 100Mb.

# /sbin/lvcreate -l 25 vg01

Page 6: Procedimento Para Gerenciar a LVM No HP

OBS.: O novo lvol e um numero sequencial, a partir do ultimocriado. Como so tinhamos o LVOL1, o proximo a ser criado eo LVOL2.

3) Se voce for usar um Raw Device, ou alocar essa area para swapfisico, nao deve criar o sistema de arquivos. Porem, se vocequiser usar esse LVOL para um sistema de arquivos, para montarem um diretorio, deve cria-lo da seguinte forma:

# /usr/sbin/newfs -F vxfs /dev/vg01/rlvol2

4) Para monta-lo, ja deve existir o diretorio destino (e vazio!):

# mkdir /mnt# /usr/sbin/mount /dev/vg01/lvol2 /mnt

5) Para que o sistema de arquivos seja montado automaticamentedurante o boot e necessario inclui-lo no arquivo /etc/fstab:

# vi /etc/fstab

/dev/vg01/lvol2 /mnt vxfs delaylog 0 2

OBS.: Verifique no manual a sintaxe da fstab para conhecermais detalhes.

F - ) COMO REMOVER UM LVOL:

Assumimos nesse exemplo a remocao do LVOL2 que esta no VG01:

1) Desmonte o LVOL em questao:

# /usr/sbin/umount /dev/vg01/lvol2

2) Remova o LVOL:

# /sbin/lvremove -f /dev/vg01/lvol2

3) Nao se esqueca de remove-lo da tabela "/etc/fstab", antes deresetar a maquina.

G - ) COMO AUMENTAR O TAMANHO DE UM LVOL:

Page 7: Procedimento Para Gerenciar a LVM No HP

Assumimos nesse exemplo o aumento do tamanho do LVOL2, que esta no VG01. Atualmente ele tem 572Mb e incluiremos nesse LVOL mais 40Mb.

LEMBRETE: nao e possivel aumentar o barra ("/"), que esta no LVOL1 doVG00!!!

1) Verifique se ha espaco disponivel no VG, a fim de inclui-lo noLVOL em questao:

# /sbin/vgdisplay vg01 | grep FreeFree PE 25

Se o numero resultante desse comando for 0, significa que naosera possivel aumentar um LVOL.

Nesse caso temos 25 extensoes (de 4Mb cada uma), totalizandoentao 100Mb ainda disponiveis.

Como queremos apenas 40Mb, usamos 10 extensoes (40 / 4 = 10).

2) Desmonte o LVOL em questao:

# /usr/sbin/umount /dev/vg01/lvol2

3) Garanta que o LVOL esta realmente desmontado, atraves do comando"mount": nao deve aparecer a linha desse LVOL.

4) Vamos agora descobrir quantas extensoes de 4Mb temos alocadasatualmente no LVOL:

# /sbin/lvdisplay -v /dev/vg01/lvol2 | grep CurrentCurrent LE 143

5) Totalizamos agora o novo numero de extensoes logicas:

143 + 10 = 153| | || | |-------> total de extensoes (=> 153 * 4 = 612Mb).| |-------------> total que temos intencao de adicionar| (=> 10 * 4 = 40Mb)|------------------> total de extensoes atualmente (=> 143 * 4 = 572Mb)

Dessa forma chegamos a um novo tamanho de 612Mb.

Page 8: Procedimento Para Gerenciar a LVM No HP

6) Vamos agora aumentar o tamanho do LVOL:

# /sbin/lvextend -l 153 /dev/vg01/lvol2

7) Depois de aumentado o tamanho do LVOL, precisamos aumentar otamanho do sistema de arquivos para compatibilizar os tamanhos:

# /usr/sbin/extendfs –F vxfs /dev/vg01/rlvol2

8) Por ultimo, e so montar novamente o LVOL e usa-lo ja com o novotamanho!

H - ) COMO DIMINUIR O TAMANHO DE UM LVOL:

Assumimos nesse exemplo a diminuicao do LVOL2 que esta no VG01. Hoje, o LVOL2 esta com 612Mb e queremos deixa-lo com apenas 500Mb.

LEMBRETE: nao e possivel diminuir o tamanho do barra ("/"), que estano LVOL1 do VG00!!!

1) Em primeiro lugar devemos fazer um backup do diretorio onde estamontado o LVOL2, pois ao diminuirmos o seu tamanho, perderemosos dados:

# cd /diretorio# find . -print | cpio -ocvB > /dev/rmt/c0t0d0BEST

2) Em seguida, desmontamos o LVOL:

# cd / ; umount /dev/vg01/lvol2

3) Garanta que o LVOL esta realmente desmontado, atraves do comando"mount": nao deve aparecer a linha desse LVOL.

4) Como o LVOL esta com 612Mb e queremos diminui-lo para 500Mb,devemos calcular o numero de extensoes contidas em 500Mb:

calcule: 500 / 4 = 125

5) Reduza agora o tamanho do LVOL:

# /sbin/lvreduce -l 125 /dev/vg01/lvol2

Page 9: Procedimento Para Gerenciar a LVM No HP

6) Crie um novo sistema de arquivos (pois nao e possivel apenasdiminuir o tamanho do sistema de arquivos):

# /usr/sbin/newfs -F vxfs /dev/vg01/rlvol2

7) Monte o filesystem e restaure os dados do backup:

# mount /dev/vg01/lvol2 /diretorio# cd /diretorio# cpio -icvdumB < /dev/rmt/c0t0d0BEST

GERENCIAMENTO DO LVOL COM ADVANCED JFS

1. Como aumentar o tamanho do lvol:

Atencao: Para os procedimentos abaixo E' necessario que o pacote HP OnLine JFS Advanced VxFS esteja instalado.

1.1 - Verifique se existe espaco disponivel no vg00:

# /sbin/vgdisplay -v vg00 |grep FreeFree PE 178

Se o numero mostrado for 0, indica que o seu vg nao tem espacodisponivel para criar um novo lvol.

Atencao: Note que no item anterior, nos desmontamos o lvol; nessecaso, com o pacote instalado, nao E' necessario.

1.2 - Como queremos aumentar o lvol para o tamanho de 140MB, podemosutilizar:

# /sbin/lvextend -L 140 /dev/vg00/lvol10Logical volume "/dev/vg00/lvol10" has been successfully extended. Volume Group configuration for /dev/vg00 has been saved in /etc/lvmconf/vg00.conf

1.3 - Aumente o tamanho do sistema de arquivos para compatibilizar otamanho:

# /usr/sbin/fsadm -F vxfs -b 143360 /testefsadm: /dev/vg00/rlvol10 is currently 102400 sectors - size will be increased

onde:-b (total lvol * 1024)

Page 10: Procedimento Para Gerenciar a LVM No HP

1.4 - Para confirmar que o lvol foi realmente aumentado, pode-se executar:

#/usr/bin/bdfou#/usr/sbin/lvdisplay /dev/vg00/lvol10

2. Reduzindo o tamanho do lvol

2.1 - Tire backup do lvol (por seguranca).2.2 - Nao E' necessario desmontar o lvol.2.3 - Reduzindo o lvol:

# /usr/sbin/fsadm -F vxfs -b 102400 /testefsadm: /dev/vg00/rlvol10 is currently 155648 sectors - size will be reduced

#/usr/sbin/lvreduce -L 100 /dev/vg00/lvol10Then a logical volume is reduced useful data might get lost; do you really want the command to proceed (y/n) : y Logical volume "/dev/vg00/lvol10" has been successfully reduced. Volume Group configuration for /dev/vg00 has been saved in /etc/lvmconf/vg00.conf

2.4 - Para confirmar que o lvol foi realmente aumentado, pode-seexecutar:

#/usr/bin/bdfou#/usr/sbin/lvdisplay -v /dev/vg00/lvol10

HP/UX LVM configurationHome | UNIX | Oracle | Code | Practical | Private

HP/UX LVM configuration

HP/UX installation : pbraun.nethence.com/doc/sysutils_hpux/hpux_installation.html

HP/UX notes : pbraun.nethence.com/doc/sysutils_hpux/hpux.html

HP/UX LVM configuration : pbraun.nethence.com/doc/sysutils_hpux/hpux_lvm.html

View current configuration

Check for disks and disk sizes,

Page 11: Procedimento Para Gerenciar a LVM No HP

ioscan -fnkC disk | grep dsk

diskinfo /dev/rdsk/c1t2d0

Note. "diskinfo -v" for more details

Check for PV/VG/LV,

strings /etc/lvmtab

vgdisplay -v | grep Name

View available space on VGs,

wget pbraun.nethence.com/code/sysutils/hpux_vgspace.ksh

chmod +x hpux_vgspace.ksh

./hpux_vgspace.ksh

Create PV/VG/LV/FS

Initialize a disk for use with LVM,

pvcreate /dev/rdsk/c0t1d0

note. '-f' to delete existing VG information

note. otherwise to completely overwrite an existing PV,

dd if=/dev/zero of=/dev/rdsk/c0t1d0 bs=1024k count=4

pvcreate /dev/rdsk/c0t1d0

Create a VG,

vgcreate vgvm /dev/dsk/c0t1d0

Note. if it fails, you probably need to prepare the device file,

#cd /dev

#mkdir vgvm

#cd vgvm

#mknod group c 64 0x010000

Create an LV,

Page 12: Procedimento Para Gerenciar a LVM No HP

lvcreate -n lvexample -L 10000 vg01

Note. you may discard the "-n" option, which won't matter if you export/import the VG from another disk, unless you saved the LVM configuration using "vgcfgbackup".

Note. if the size extend failed (not enought space), you'll need to extend manually with a lower size,

lvextend -L 9000 /dev/vg01/lvexample

Create a FS,

mkfs /dev/vg01/lvexample

note. default filesystem is vxfs.

note. there's also 'newfs -F vxfs'

Mount the FS and configure for boot time,

mkdir -p /mnt/example

mount /dev/vg01/lvexample /mnt/example

vi /etc/fstab

add this line,

/dev/vg01/lvexample /mnt/example vxfs delaylog 0 2

note. possible options : rw,suid,nolargefiles,delaylog,datainlog

Otherwise with SAM,

#Disks and File Systems > Volume Groups > Actions > Create

Delete LV/VG/PV

Delete an LV,

cd ~/

vgdisplay -v | grep Name

lvremove /dev/vg01/lvexample

write down the PV name, then delete a VG and its PV,

vgdisplay -v | grep Name

vgremove vg01

Page 13: Procedimento Para Gerenciar a LVM No HP

pvremove /dev/rdsk/c2t0d1

Note. if the VG uses alternate links, use brute force,

vgchange -a n vg01

vgexport vg01

dd if=/dev/zero of=/dev/rdsk/c2t0d1 bs=1024k count=4

Disk and volume groups

Add disk to a VG,

ioscan -fnC disk

pvcreate -f /dev/rdsk/c0t1d0

vgextend vg00 /dev/dsk/c0t1d0

Note. raw device for pvcreate

Relocate PEs,

pvmove /dev/dsk/c0t1d0 /dev/disk/disk1_p2

and remove a disk from volume group,

vgreduce vg00 /dev/dsk/c0t1d0

LV extend / reduce

Extend an LV,

cd /dev/vg01

lvextend -L 41000 /dev/vg01/lvol1

Relocate an LV within a VG,

vgdisplay -v | grep Name

pvmove -n /dev/vg00/lvguest2 /dev/disk/disk1_p2 /dev/dsk/c0t1d0

Filesystem extend / reduce

Page 14: Procedimento Para Gerenciar a LVM No HP

Extend an unmounted FS,

bdf

umount /mnt/example

extendfs /dev/vg01/lvol1

mount /mnt/example

bdf

Extend a mounted FS. Write down the PE size,

vgdisplay vg01 | grep PE

note. should be 4 Mbytes

calculate the LEs,

41000 / 4 = 10250

check it corresponds to LV's "Current LE" and "Allocated PE",

lvdisplay /dev/vg01/lvol1

calculate the blocks,

10250 * 1024 = 10496000

extend an mounted FS,

fsadm -F vxfs -b 10496000 /mnt/example

Merge some LVs

Merge LVs example2 and example3 into LV example1,

lvmerge /dev/vg01/lvexample2 /dev/vg01/lvexample1

lvmerge /dev/vg01/lvexample3 /dev/vg01/lvexample1

Note. carefull this removes the content of the former

Note. this takes a while...

VG Import/export

Get back to an existing VG

Import a VG,

Page 15: Procedimento Para Gerenciar a LVM No HP

vgimport vg01 /dev/dsk/c4t0d1

vgchange -a y vg01

LVM configuration backup

Backup LVM configuration,

vgcfgbackup vg01

HP-UX: Disk and Filesystem tasks

Search for attached disk

ioscan -fnC disk

Initialize a disk for use with LVM

pvcreate -f /dev/rdsk/c0t1d0

Create the device structure needed for a new volume group.

cd /dev mkdir vgdata cd vgdata mknod group c 64 0x010000

Create volume group vgdata

vgcreate vgdata /dev/dsk/c0t1d0

{ if your expecting to use more than 16 physical disks use the -p option, range from 1 to 256 disks. }

Display volume group vgdata

vgdisplay -v vg01

Add another disk to volume group

pvcreate -f /dev/rdsk/c0t4d0

vgextend vg01 /dev/dsk/c0t4d0

Remove disk from volume group

vgreduce vg01 /dev/dsk/c0t4d0

Page 16: Procedimento Para Gerenciar a LVM No HP

Create a 100 MB logical volume lvdata

lvcreate -L 100 -n lvdata vgdata newfs -F vxfs /dev/vgdata/rlvdata

Extend logical volume to 200 MB

lvextend -L 200 /dev/vgdata/lvdata

Extend file system to 200 MB

{ if you don't have Online JFS installed volumes must be unmounted before you can extend the file system. }

fuser -ku /dev/vgdata/lvdata { kill all process that has open files on this volume. }

umount /dev/vgdata/lvdata extendfs /data

{ for Online JFS, 200 MB / 4 MB = 50 LE; 50 x 1024 = 51200 blocks }

fsadm -F vxfs -b 51200 /data

Set largefiles to support files greater than 2GB

fsadm -F vxfs -o largefiles /data

Exporting and Importing disks across system.

1. make the volume group unavailable

vgchange -a n /dev/vgdata

2. Export the the disk while creating a logical volume map file.

vgexport -v -m data_map vgdata

3. Disconnect the drives and move to new system.

4. Move the data_map file to the new system.

5. On the new system recreate the volume group directory

mkdir /dev/vgdata mknod /dev/vgdata/group c 64 0x02000

6. Import the disks to the new system

vgimport -v -m data_map /dev/vgdata /dev/dsk/c2t1d0 /dev/dsk/c2t2d0

Page 17: Procedimento Para Gerenciar a LVM No HP

7. Enable the new volume group

vgchange -a y /dev/vgdata

Renaming a logical volume

/dev/vgdata/lvol1 -> /dev/vgdata/data_lv

umount /dev/vgdata/lvol1 ll /dev/vgdata/lvol1 take note of the minor ( e.g 0x010001 ) brw-r----- 1 root root 64 0x010001 Dec 31 17:59 lvol1

mknod /dev/vgdata/data_lv b 64 0x010001 create new logical volume name mknod /dev/vgdata/rdata_lv c 64 0x010001

vi /etc/fstab { reflect the new logical volume } mount -a

rmsf /dev/vgdata/lvol1 rmsf /dev/vgdata/rlvol1

Page 18: Procedimento Para Gerenciar a LVM No HP

Linux Logical Volume Manager (LVM) on Software RAID

Logical Volume Manager is now included with most Linux distributions. The RedHat 8.0 installer even allows you to create LVM volumes during initial install. LVM offers capabilities previously only found in expensive products like Veritas.

If you plan on using LVM, I really recommend doing so on a RAID system, either hardware or software. Disks are dirt cheap nowadays, so there's really no excuse not to have mirroring (or RAID 5 if that's better for your usage). The RedHat installer will let you create LVM volumes on top of RAID volumes (it's a bit confusing, but it works), or you can do it later. Also remember that raid is not a substitute for regular and reliable backup!

Before we get to how you'd do this, let's go over what LVM gives you. First, LVM combines physical devices (partitions on disks in this case) into what it calls Volume Groups. Filesystems are then built on the Volume Group or groups. You can have a Volume Group that has only one disk partition in it, or several partitions on one or more disks. Each Volume Group can contain multiple filesystems. With this, you gain a lot of new capabilities.

o Increase or decrease filesystem size

Decreasing the size of a filesystem returns space to the Volume Group. Increasing draws space from it. If you have too much space allocated for a file system, you can decrease it, and use that space somewhere else that needs it.

Yes, you can do that with "parted", but it's not at all the same. You aren't dealing with contiguous disk blocks with LVM - all you need is free space in the Volume Group.

o Add more physical storage

You can add more physical drives to an existing Volume Group, which of course immediately gives you more room to extend file systems.

o Create "snapshots" of filesystems.

This is a great feature, but it requires a bit of explanation, so we'll leave the details for later. The use of snapshots is to freeze a filesystem in time, and let you go on using it while you leisurely back up the frozen data. What's wonderful about this is that it is NOT necessarily a full copy of your original file system - more on that later.

o Move Volume Groups to new physical storage

I'm not going to cover this here, but it's a great feature, and you can even do it while the filesystems are in use!

o Striping

Page 19: Procedimento Para Gerenciar a LVM No HP

I'm not going to cover that here (there are some references at the bottom of this article that do cover it), but you can get the performance benefit of striping as part of LVM. If you do this, it is even more critical that you mirror your drives. If you used RAID 5, there wouldn't be any point in striping in LVM as you already would have that benefit (see Raidif you don't understand that).

Configuring LVM on mirrored drives during RedHat Install

You might want to review Software Mirroring if you have never done that. Software mirroring is where we start by creating raid devices upon which we will create LVM volumes. For this test machine, I created a layout like this:

Primary disk Size Filesystem type

/dev/hda1 102 MB primary partition Software RAID

/dev/hda2 128 MB Swap

/dev/hda3 (rest of disk) Software Raid

Secondary disk Size Partition type

/dev/hdb1 102 MB primary partition Software RAID

/dev/hdb2 128 MB Swap

/dev/hdb3 (rest of disk) Software Raid

Note that there are two swap partitions, and that they will not be mirrored.

Page 20: Procedimento Para Gerenciar a LVM No HP

I then made two raid devices, choosing "Physical Volume (LVM)" as the filesystem type for the second.

Raid device Partitions used Filesystem type Mount point

/dev/md0 /dev/hda1 and /dev/hdb1 ext3 /boot

/dev/md1 /dev/hda3 and /dev/hdb3Physical Volume

(LVM)N/A

Let's stop for a second and go over this carefully because it can be confusing. We've created mirrors of our boot partition and what would ordinarily become root. But there is no root partion yet. The place where it will go is mirrored, but we aren't creating a file system just yet. The next step is to click LVM to create a Volume Group. A volume group needs one or more Physical Volumes, and we have one. Note that is very different from Raid where you need at least two Software Raid partitions to do anything. For a LVM volume group, one physical volume is enough. It is here, in the Volume Group, that we create filesystems. Note that is plural. With raid, your partition is one filesystem, but with LVM you can create multiple filesystems within one Volume Group. To do that, just click the LVM button and it will bring up a new Volume Group. As we only have one Physical Volume here, that's what it will use, and it's ready to let you add file systems.

Note: although I put / into the LVM for this test setup, it may not be a good idea to do so because emergency boot media probably won't understand LVM filesystems. Supposedly RedHat 8.0 does support / on LVM (but not /boot).

So I added two filesystems, each 4GB in size, and had one mount at / and the other at /var. I had much more space available (this was a 30GB drive), but I didn't bother to use it at this time. I then proceeded with the install as usual. Well, almost as usual. Several times in testing I had the problem of not getting focus when it was time to put in the root password. The solution is to right click over the field, choose "Select All" and then click in the field again.

Extending File Systems

After booting up, I had the expected 4GB / and 4GB /var. As you will remember, the actual disk is much larger, so let's add more filesystems to it:

lvcreate -L 4G -n mylv Volume00mkfs -t ext3 /dev/Volume00/mylvmkdir /mylvmount /dev/Volume00/mylv /mylv

That added a 4GB filesystem. Unfortunately, I made a mistake - I needed 6 GB. Well, at this point I could just blow it away (lvremove /dev/Volume00/mylv), but suppose I'd already added a lot of data? No problem, just unmount it and extend it:

Page 21: Procedimento Para Gerenciar a LVM No HP

umount /mylve2fsadm -L+2G /dev/Volume00/mylvmount /dev/Volume00/mylv /mylv

The "ef2fsadm" actually runs lower level commands for you: it fscks the file system, runs lvextend to extend the logical volume, and then resizes the filesystem to fit. Much easier to let e2fsadm handle the whole job.

Adding more disks

If I really needed a lot more space, I could add a hard drive and use "pvcreate" to add it as a physical volume, and then "vgextend" picks up that space:

pvcreate /dev/sda1vgextend Volume00 /dev/sda1

It just can't get much easier! Remember though: those disks should be mirrored too.

Snapshots

This is a very useful feature. Many of us have the situation where important data needs to be backed up, but it cannot be used while the backup is running because then the backed up files would be out of sync with each other. For example, you have an accounting system that is recording orders. The accounts receivable file gets backed up now, and you take an order. Both a/r and the customer file get updated to reflect the new order, but a/r has already been backed up. When the customer file finally makes it to tape, it's not consistent with a/r, and of course it needs to be. Without snapshots, your only recourse is to stop taking orders while the backup runs. If you have lots of disk space, you could copy the whole accounting system and backup the copy, but that can take a lot of time too, and you may not have the space. Snapshots are the solution. Before you do the next step, make sure you've put a few files in /little, and make at least one of them unimportant. Then create the snapshot.

lvcreate --size 200M --snapshot -n mysnap /dev/Volume00/mylvmkdir /mylvsnapmount /dev/Volume00/mysnap /mylvsnapdf

Right off the bat you should have noticed something strange. We created mysnap very specifically with a size of 200MB, and trust me, that's all it took away from us, but df shows it being the same size (6GB) as mylv. We'll get back to why this is in a minute, but first take a look at the files in /snap. They are identical to the files in /mylv, right? OK, now go edit a file in /mylv. Does it change in /snap? No, it does not. Remove a file in /mylv - it's still there in /snap. Add a new file to /mylv, and that does NOT appear in /snap. How is this done, and most especially how is it done in 200MB?

Page 22: Procedimento Para Gerenciar a LVM No HP

It's not magic

OK, it is magic. What is going on is that /snap contains absolutely nothing UNLESS something changes back at /mylv. If you ask for a file from /snap that has not changed, the data is read right from /mylv. But if a file IS changed, before the change is written, the data blocks that don't yet have the changes are written to /snap. Note that entire files are NOT written, just data blocks that are about to change. So, as long as we don't change more than 200MB worth of data in /mylv, we can have our cake and eat it too. Our procedure will be:

o Stop using the filesystem, shut down any databases that need to be shutdown etc.

o Create the snapshoto Start up our databases, go back to work.o Start backing up /snap

Our time without access is minutes or seconds - just however long it takes to stop the processes and restart them, basically. The backup can take its sweet time. Well it can if it doesn't take so long that we need more than 200 MB to store our data that is changing. That does mean that the size of mysnap does have to be a bit of an educated guess. It also means that as soon as you are done with the backup, mysnap should be removed:

umount /snaplvremove /dev/Volume00/msnap

If you don't remove it, it will go on copying data as it is changed and eventually it will run out of room. You can't just leave it there for next time!

Some other helpful links:

http://tldp.org/HOWTO/LVM-HOWTO/index.htmlhttp://ds9a.nl/lvm-howto/HOWTO/cvs/lvm-howto/output/lvm-howto.html

Page 23: Procedimento Para Gerenciar a LVM No HP

Multipathing on HP-UX (LVM vs. VxVM)

14 February 2008 by ddouthitt 6 Comments

A few versions back, HP started including Veritas VxVM (Veritas Volume Manager) with HP-UX 11i. There was some consternation that VxVM was a third-party non-HP product, and that it would mean the demise of LVM.

However, now in HP-UX 11i v3 HP has turned the tables on Veritas (now Symantec) so to speak. In essence, this is another replay of the operating system vendor shooting down the third-party vendor.

In the past, HP-UX did not support load balancing on HP-UX with the native LVM disks; only VxVM supported multipathing with fail-over and load balancing. Now, in HP-UX 11i v3, the native drivers support full load balancing and failover with multipathing, and VxVM has been eviscerated: under 11i v3, VxVM’s multipathing DMP is put into straight-through mode (that is, no failover, no load balancing) and the new 11i native multipathing takes over.

When the disks are presented to HP-UX 11i v3 properly, the following will be output for the ioscan -m dsf command:

# ioscan -m dsfPersistent DSF Legacy DSF(s)========================================.../dev/rdisk/disk16 /dev/rdsk/c7t0d0 /dev/rdsk/c6t0d0/dev/rdisk/disk17 /dev/rdsk/c7t0d1 /dev/rdsk/c6t0d1/dev/rdisk/disk18 /dev/rdsk/c7t0d2 /dev/rdsk/c6t0d2/dev/rdisk/disk19 /dev/rdsk/c7t0d3 /dev/rdsk/c6t0d3/dev/rdisk/disk20 /dev/rdsk/c7t0d4 /dev/rdsk/c6t0d4

With the proper multipathing in place, the “persistent DSFs” (DSFs are Device Special Files) are matched to multiple paths (which are reflected in the legacy DSFs). If you see this output from ioscan -m dsf, then multipathing is enabled for the disks as shown.

If ioscan -m dsf reports a syntax error, then you are not running on HP-UX 11i v3 – 11i v2 and below did not support the -m option.

It would appear that HP was serious about supporting LVM on HP-UX after all.