informatica:linux:discos:lvm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
informatica:linux:discos:lvm [2014/01/09 06:59] – javi | informatica:linux:discos:lvm [2023/10/05 00:27] (current) – jose | ||
---|---|---|---|
Line 13: | Line 13: | ||
Tenemos un disco duro con dos particiones: | Tenemos un disco duro con dos particiones: | ||
- | / | + | | / |
- | / | + | | / |
Hemos trasteado el LVM y no arranca. Para montar LVM desde una live-cd: | Hemos trasteado el LVM y no arranca. Para montar LVM desde una live-cd: | ||
Line 297: | Line 297: | ||
Tenemos 80 Gb en home y queremos pasar 20 a una unidad de apoyo | Tenemos 80 Gb en home y queremos pasar 20 a una unidad de apoyo | ||
- | Reducimos tamaño del primer LV: | + | 1. Siempre es mejor desmontar |
- | lvreduce -L60G / | + | |
- | Creamos el LV de apoyo: | + | |
- | lvcreate vol64 --name apoyo --size=20G | + | |
- | Formatemos el LV: | + | |
- | mkfs.ext3 / | + | |
- | Ya está listo para montar | + | umount / |
+ | |||
+ | 2. Achichar espacio en disco, en este caso el nuevo tamanyo sera 60G | ||
+ | |||
+ | resize2fs / | ||
+ | |||
+ | 3. Achicar Logical Volume: | ||
+ | |||
+ | lvreduce -L60G / | ||
+ | |||
+ | 4. Crear el nuevo LV con todo el espacio libre: | ||
+ | |||
+ | lvcreate -n lv_iso -l 100%FREE vg_manager2 | ||
+ | |||
+ | 5. Formatear el nuevo LV | ||
+ | |||
+ | mkfs.ext4 / | ||
+ | |||
+ | Ahora ya se pueden | ||
+ | |||
+ | ====== Renombrar volumenes ====== | ||
+ | |||
+ | ===== Renombrar un Grupo de Volúmenes (VG) ===== | ||
+ | |||
+ | (Creo que todo como root) | ||
+ | |||
+ | 1. Obtenemos el nombre del Grupo de Volúmenes | ||
+ | |||
+ | calero:~# vgscan | ||
+ | Reading all physical volumes. | ||
+ | Found volume group " | ||
+ | |||
+ | 2. Renombramos: | ||
+ | |||
+ | vgrename calero nuevo_nombre_vg | ||
+ | |||
+ | ===== Renombrar un Volumen Lógico (LV) ===== | ||
+ | |||
+ | (Creo que todo como root) | ||
+ | |||
+ | 1. Obtenemos el nombre de todos los Volúmenes Lógicos del Grupo de Volúmenes: | ||
+ | |||
+ | calero:~# clear && lvdisplay | ||
+ | |||
+ | --- Logical volume --- | ||
+ | LV Name / | ||
+ | VG Name calero | ||
+ | LV UUID KopwfX-2SZG-JJNg-H0xs-6dnb-zwmB-zBUMZR | ||
+ | LV Write Access | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size 6,52 GB | ||
+ | Current LE | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | |||
+ | --- Logical volume --- | ||
+ | LV Name / | ||
+ | VG Name calero | ||
+ | LV UUID sGM4EI-QMBx-428v-B7nc-OcHB-KSnj-H9I1ze | ||
+ | LV Write Access | ||
+ | LV Status | ||
+ | # open 2 | ||
+ | LV Size 2,53 GB | ||
+ | Current LE 648 | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | |||
+ | --- Logical volume --- | ||
+ | LV Name / | ||
+ | VG Name calero | ||
+ | LV UUID jlNSaR-X2mN-l6Cs-epeu-PDRv-3iqi-izAUBP | ||
+ | LV Write Access | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size 65,24 GB | ||
+ | Current LE | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | |||
+ | |||
+ | 2. Renombramos el Volumen Lógico que queramos: | ||
+ | |||
+ | lvrename / | ||
+ | |||
+ | ====== Añadir disco físico ====== | ||
+ | |||
+ | Añadimos el disco físicamente | ||
+ | |||
+ | Al hacer un fdisk veremos que lo tenemos sin particionar | ||
+ | < | ||
+ | # fdisk -l | ||
+ | |||
+ | Disk /dev/hda: 10.7 GB, 10737418240 bytes | ||
+ | 255 heads, 63 sectors/ | ||
+ | Units = cylinders of 16065 * 512 = 8225280 bytes | ||
+ | |||
+ | | ||
+ | / | ||
+ | / | ||
+ | |||
+ | Disk /dev/hdd: 2147 MB, 2147483648 bytes | ||
+ | 16 heads, 63 sectors/ | ||
+ | Units = cylinders of 1008 * 512 = 516096 bytes | ||
+ | |||
+ | Disk /dev/hdd doesn' | ||
+ | |||
+ | </ | ||
+ | |||
+ | 1. Creamos partición LVM | ||
+ | |||
+ | Con fdisk creamos una partición en /dev/hdb1 y la creamos tipo LVM: | ||
+ | |||
+ | < | ||
+ | # fdisk /dev/hdd | ||
+ | Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel | ||
+ | Building a new DOS disklabel. Changes will remain in memory only, | ||
+ | until you decide to write them. After that, of course, the previous | ||
+ | content won't be recoverable. | ||
+ | |||
+ | |||
+ | The number of cylinders for this disk is set to 4161. | ||
+ | There is nothing wrong with that, but this is larger than 1024, | ||
+ | and could in certain setups cause problems with: | ||
+ | 1) software that runs at boot time (e.g., old versions of LILO) | ||
+ | 2) booting and partitioning software from other OSs | ||
+ | | ||
+ | Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) | ||
+ | |||
+ | Command (m for help): n | ||
+ | Command action | ||
+ | | ||
+ | | ||
+ | p | ||
+ | Partition number (1-4): 1 | ||
+ | First cylinder (1-4161, default 1): | ||
+ | Using default value 1 | ||
+ | Last cylinder or +size or +sizeM or +sizeK (1-4161, default 4161): | ||
+ | Using default value 4161 | ||
+ | |||
+ | Command (m for help): t | ||
+ | Selected partition 1 | ||
+ | Hex code (type L to list codes): 8e | ||
+ | Changed system type of partition 1 to 8e (Linux LVM) | ||
+ | |||
+ | Command (m for help): p | ||
+ | |||
+ | Disk /dev/hdd: 2147 MB, 2147483648 bytes | ||
+ | 16 heads, 63 sectors/ | ||
+ | Units = cylinders of 1008 * 512 = 516096 bytes | ||
+ | |||
+ | | ||
+ | / | ||
+ | |||
+ | Command (m for help): w | ||
+ | The partition table has been altered! | ||
+ | |||
+ | Calling ioctl() to re-read partition table. | ||
+ | Syncing disks. | ||
+ | |||
+ | </ | ||
+ | |||
+ | 2. Creación PV | ||
+ | |||
+ | # pvcreate /dev/hdd1 | ||
+ | Physical volume "/ | ||
+ | |||
+ | 3. Ampliamos VG | ||
+ | |||
+ | # vgextend VolGroup00 /dev/hdd1 | ||
+ | Volume group " | ||
+ | |||
+ | 4. Ampliamos LV | ||
+ | |||
+ | De los 2Gb añadimos solo 1Gb: | ||
+ | # lvextend -L +1G / | ||
+ | |||
+ | Extending logical volume LogVol00 to 10.12 GB | ||
+ | Logical volume LogVol00 successfully resized | ||
+ | |||
+ | Vemos que todavía queda 1Gb libre (Free PE/Size 32/ | ||
+ | # vgdisplay | ||
+ | |||
+ | --- Volume group --- | ||
+ | VG Name | ||
+ | System ID | ||
+ | Format | ||
+ | Metadata Areas 3 | ||
+ | Metadata Sequence No 6 | ||
+ | VG Access | ||
+ | VG Status | ||
+ | MAX LV 0 | ||
+ | Cur LV 2 | ||
+ | Open LV 2 | ||
+ | Max PV 0 | ||
+ | Cur PV 3 | ||
+ | Act PV 3 | ||
+ | VG Size 11.88 GB | ||
+ | PE Size 32.00 MB | ||
+ | Total PE 380 | ||
+ | Alloc PE / Size 348 / 10.88 GB | ||
+ | Free PE / Size 32 / 1.00 GB | ||
+ | VG UUID | ||
+ | |||
+ | Para ampliar al máximo de file system es sin ningún parámetro: | ||
+ | # lvextend / | ||
+ | |||
+ | Extending logical volume LogVol00 to 11.09 GB | ||
+ | Logical volume LogVol00 successfully resized | ||
+ | |||
+ | 5. Ampliamos FS | ||
+ | |||
+ | # resize2fs / | ||
+ | |||
+ | resize2fs 1.39 (29-May-2006) | ||
+ | Filesystem at / | ||
+ | Performing an on-line resize of / | ||
+ | The filesystem on / | ||
+ | |||
+ | Referencia: | ||
+ | |||
+ | http:// | ||
+ | |||
+ | ====== Añadir LV ====== | ||
+ | |||
+ | **TODAVÍA NO ESTÁ TERMINADO EL ARTÍCULO** | ||
+ | |||
+ | b) Crear un LV con el espacio libre de un VG: | ||
+ | |||
+ | 1. Obtener el espacio libre del VG en cuestión: | ||
+ | |||
+ | vgdisplay | ||
+ | |||
+ | ... | ||
+ | Free PE / Size 3839 / 15 GB | ||
+ | ... | ||
+ | |||
+ | 2. Crear el LV de nombre ' | ||
+ | |||
+ | Opción 1: | ||
+ | lvcreate -n var--size 15G nombre_VG | ||
+ | |||
+ | Opción 2: | ||
+ | |||
+ | lvcreate -n var -l 3839 nombre_VG | ||
+ | |||
+ | 4. Doy formato al nuevo volumen (sistema de ficheros EXT3) | ||
+ | |||
+ | mke2fs -j / | ||
+ | |||
+ | 5. Si es menester, lo meto en el / | ||
+ | |||
+ | 6. Arranca ok, pero no lo monta. Para ver el resultado: | ||
+ | |||
+ | lvdisplay | ||
+ | |||
+ | Aparece el nuevo volumen, con el valor '# open' a ' | ||
+ | |||
+ | ====== Crear VG ====== | ||
+ | |||
+ | ****Antecedentes**** | ||
+ | |||
+ | La secuencia es: | ||
+ | |||
+ | 1º crear un PV (Volumen Físico) | ||
+ | |||
+ | 2º crear 1 VG (Grupo de Volúmenes) para ese PV | ||
+ | |||
+ | 3º crear 1/+ LV (Volúmenes Lógicos) para ese VG | ||
+ | |||
+ | 5. Crear un PV (Volumen Físico) en una partición: | ||
+ | |||
+ | pvcreate /dev/sda7 | ||
+ | |||
+ | 6. Crear un VG (Grupo de Volúmenes) | ||
+ | |||
+ | vgcreate vg /dev/sda7 | ||
+ | |||
+ | 7. Activarlo | ||
+ | |||
+ | vgchange -a y vg | ||
+ | |||
+ | |||
+ | ======= Achicar LV swap ======= | ||
+ | |||
+ | 1. Desactivar todas la swap (se podría especificar la que usa el LV): | ||
+ | |||
+ | swapoff -a | ||
+ | |||
+ | 2. Reducir 1 GB el tamaño del LV que usamos para swap | ||
+ | |||
+ | lvreduce / | ||
+ | |||
+ | < | ||
+ | WARNING: Reducing active logical volume to 4.00 GiB. | ||
+ | THIS MAY DESTROY YOUR DATA (filesystem etc.) | ||
+ | Do you really want to reduce vg/swap? [y/n] | ||
+ | </ | ||
+ | |||
+ | Pulsar ' | ||
+ | |||
+ | < | ||
+ | Size of logical volume vg/swap changed from 5.00 GiB (1280 extents) to 4.00 GiB (1024 extents). | ||
+ | Logical volume vg/swap successfully resized. | ||
+ | </ | ||
+ | |||
+ | 3. Formatear como swap el dispositivo del LV | ||
+ | |||
+ | mkswap / | ||
+ | |||
+ | < | ||
+ | Setting up swapspace version 1, size = 4 GiB (4294963200 bytes) | ||
+ | no label, UUID=1c3bd974-d6c4-46e4-9f64-bc2445f9e200 | ||
+ | </ | ||
+ | |||
+ | 4. Montar swap (previsamente ya tiene su entrada en '/ | ||
+ | |||
+ | swapon -va | ||
+ | |||
+ | < | ||
+ | swapon: / | ||
+ | swapon: / | ||
+ | swapon / | ||
+ | </ | ||
+ | |||
+ | 5. Comprobar | ||
+ | |||
+ | cat / | ||
+ | |||
+ | < | ||
+ | Filename Type Size Used Priority | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | free -h | ||
+ | |||
+ | < | ||
+ | total used free shared | ||
+ | Mem: | ||
+ | Swap: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Debian 12 ====== | ||
+ | Tenemos que desmontar /home | ||
+ | |||
+ | Miramos las particiones: | ||
+ | < | ||
+ | root@debian: | ||
+ | Filesystem | ||
+ | udev | ||
+ | tmpfs 783M 688K 783M 1% /run | ||
+ | / | ||
+ | tmpfs 3.9G | ||
+ | tmpfs 5.0M | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | tmpfs 783M | ||
+ | tmpfs 783M | ||
+ | </ | ||
+ | |||
+ | Miramos LVM | ||
+ | < | ||
+ | root@debian: | ||
+ | --- Logical volume --- | ||
+ | LV Path / | ||
+ | LV Name root | ||
+ | VG Name debian-vg | ||
+ | LV UUID sM1VB5-QkRX-BXM1-No2F-S23M-YwQU-Cg5351 | ||
+ | LV Write Access | ||
+ | LV Creation host, time debian, 2023-10-04 18:21:09 -0400 | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size 22.25 GiB | ||
+ | Current LE | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | |||
+ | --- Logical volume --- | ||
+ | LV Path / | ||
+ | LV Name var | ||
+ | VG Name debian-vg | ||
+ | LV UUID u5Hxq6-k9eJ-25WS-AK02-afVC-o76u-vlYnyd | ||
+ | LV Write Access | ||
+ | LV Creation host, time debian, 2023-10-04 18:21:09 -0400 | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size <7.73 GiB | ||
+ | Current LE | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | |||
+ | --- Logical volume --- | ||
+ | LV Path / | ||
+ | LV Name swap_1 | ||
+ | VG Name debian-vg | ||
+ | LV UUID r88cII-vYx4-aAmF-85yJ-vjq6-8jkR-vS5JtK | ||
+ | LV Write Access | ||
+ | LV Creation host, time debian, 2023-10-04 18:21:09 -0400 | ||
+ | LV Status | ||
+ | # open 2 | ||
+ | LV Size 976.00 MiB | ||
+ | Current LE 244 | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | |||
+ | --- Logical volume --- | ||
+ | LV Path / | ||
+ | LV Name tmp | ||
+ | VG Name debian-vg | ||
+ | LV UUID mZHGHj-VUxN-QQhR-q8Lb-DAvW-E9sn-8ZuZ15 | ||
+ | LV Write Access | ||
+ | LV Creation host, time debian, 2023-10-04 18:21:09 -0400 | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size 1.37 GiB | ||
+ | Current LE 351 | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | |||
+ | --- Logical volume --- | ||
+ | LV Path / | ||
+ | LV Name home | ||
+ | VG Name debian-vg | ||
+ | LV UUID 69Y7rL-hzIr-21jn-KV3R-8qP5-XLdg-arYSL7 | ||
+ | LV Write Access | ||
+ | LV Creation host, time debian, 2023-10-04 18:21:10 -0400 | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size <86.43 GiB | ||
+ | Current LE | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | </ | ||
+ | Quitamos 40Gbs a /home: | ||
+ | lvreduce -L -40G / | ||
+ | < | ||
+ | WARNING: Reducing active and open logical volume to <46.43 GiB. | ||
+ | THIS MAY DESTROY YOUR DATA (filesystem etc.) | ||
+ | Do you really want to reduce debian-vg/ | ||
+ | Size of logical volume debian-vg/ | ||
+ | Logical volume debian-vg/ | ||
+ | </ | ||
+ | Vemos que hay 40Gb libres: | ||
+ | < | ||
+ | root@debian: | ||
+ | --- Volume group --- | ||
+ | VG Name | ||
+ | System ID | ||
+ | Format | ||
+ | Metadata Areas 1 | ||
+ | Metadata Sequence No 7 | ||
+ | VG Access | ||
+ | VG Status | ||
+ | MAX LV 0 | ||
+ | Cur LV 5 | ||
+ | Open LV 5 | ||
+ | Max PV 0 | ||
+ | Cur PV 1 | ||
+ | Act PV 1 | ||
+ | VG Size | ||
+ | PE Size 4.00 MiB | ||
+ | Total PE 30403 | ||
+ | Alloc PE / Size 20156 / 78.73 GiB | ||
+ | Free PE / Size 10247 / <40.03 GiB | ||
+ | VG UUID | ||
+ | </ | ||
+ | |||
+ | Se las añadimos a /var | ||
+ | lvextend -L +40G / | ||
+ | < | ||
+ | Size of logical volume debian-vg/ | ||
+ | Logical volume debian-vg/ | ||
+ | </ | ||
+ | Vemos que todavía no lo ha añadido: | ||
+ | < | ||
+ | df -h | ||
+ | Filesystem | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | Pero con lvdisplay si aparece: | ||
+ | < | ||
+ | --- Logical volume --- | ||
+ | LV Path / | ||
+ | LV Name var | ||
+ | VG Name debian-vg | ||
+ | LV UUID jud91P-5LXr-t0KI-5KSM-nim3-Xhvk-oSwkw5 | ||
+ | LV Write Access | ||
+ | LV Creation host, time debian, 2023-10-04 19:47:42 -0400 | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size <47.73 GiB | ||
+ | Current LE | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | </ | ||
+ | Hay que extender el FS: | ||
+ | resize2fs / | ||
+ | |||
+ | resize2fs 1.47.0 (5-Feb-2023) | ||
+ | Filesystem at / | ||
+ | old_desc_blocks = 1, new_desc_blocks = 6 | ||
+ | The filesystem on / | ||
+ | Ahora si que aparece: | ||
+ | < | ||
+ | root@debian: | ||
+ | Filesystem | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | </ |
informatica/linux/discos/lvm.1389250779.txt.gz · Last modified: 2015/04/13 20:19 (external edit)