Cum să… micșorați un volum fizic LVM fără pierderi de date, în timp ce sistemul rulează
Se đă următoarea configurație:
# fdisk -l
Disk /dev/cciss/c0d0: 440.3 GB, 440346238976 bytes
255 heads, 63 sectors/track, 53535 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 52887 424706048+ 8e Linux LVM
/dev/cciss/c0d0p3 52887 53535 5209416+ 83 Linux
- prima partiție este o partiție ext3 montată în /boot
- a doua este un volum LVM
- ultima este o partiție ext3 ce nu conține date.
Volumul LVM este destul de mare:
# pvdisplay --- Physical volume --- PV Name /dev/cciss/c0d0p2 VG Name VolGroup00 PV Size 405.00 GB / not usable 31.81 MB Allocatable yes PE Size (KByte) 32768 Total PE 12959 Free PE 31 Allocated PE 12928 PV UUID F0llk1-rDcM-TZV2-Zkt2-9EWU-kr6Q-DtygTz
și conține mai multe partiții logice:
# lvdisplay --- Logical volume --- LV Name /dev/VolGroup00/root VG Name VolGroup00 LV UUID wbZ4WM-WB54-Mu30-K2jm-RodH-0v8b-QTCsFX LV Write Access read/write LV Status available # open 1 LV Size 10.00 GB Current LE 320 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Name /dev/VolGroup00/opt VG Name VolGroup00 LV UUID 2z3mgZ-WISj-jTNZ-Ij3G-0vFs-WnyE-sJAiAQ LV Write Access read/write LV Status available # open 1 LV Size 10.00 GB Current LE 320 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Name /dev/VolGroup00/var VG Name VolGroup00 LV UUID vwsHHV-kaQG-riC3-Nk8D-Z0jl-BSoP-hcDkjY LV Write Access read/write LV Status available # open 1 LV Size 35.00 GB Current LE 1120 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Name /dev/VolGroup00/asm VG Name VolGroup00 LV UUID qesUZc-n19h-6qTM-Fox9-2yqG-yHf2-6Upr13 LV Write Access read/write LV Status available # open 0 LV Size 341.00 GB Current LE 10912 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3 --- Logical volume --- LV Name /dev/VolGroup00/swap VG Name VolGroup00 LV UUID CkhMwT-dG1d-SNE8-46mk-1pKW-E1Sd-bCPPon LV Write Access read/write LV Status available # open 1 LV Size 8.00 GB Current LE 256 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:4
Vrem să creem partiția /dev/VolGroup00/asm în afara VG-ului, fără a pierde datele de pe partițiile din fața ei. Pentru asta va trebui să o ștergem din VG, să micșorăm VG-ul și să creem partiția separat, direct pe disk. Deci…
- vom distruge /dev/VolGroup00/asm și tot ce este după ea în VG (în cazul de față /dev/VolGroup00/swap)
- vom distruge partiția de după VG și în spațiul rămas vom re-crea partiția asm
Deci… distrugem partiția de swap. Mai întâi vom opri swapping-ul și vom comenta linia aferentă lui din fstab:
# free -m
total used free shared buffers cached
Mem: 7985 911 7074 0 215 571
-/+ buffers/cache: 124 7860
Swap: 8191 0 8191
# swapoff /dev/VolGroup00/swap
# free -m
total used free shared buffers cached
Mem: 7985 907 7077 0 215 571
-/+ buffers/cache: 121 7864
Swap: 0 0 0
Iar în /etc/fstab linia cu swap-ul arată așa:
#/dev/VolGroup00/swap swap swap defaults 0 0
Ștergem volumul swap din VG:
# lvremove /dev/VolGroup00/swap Do you really want to remove active logical volume "swap"? [y/n]: y Logical volume "swap" successfully removed # lvdisplay --- Logical volume --- LV Name /dev/VolGroup00/root VG Name VolGroup00 LV UUID 1YqBaS-1fhW-2T91-QR1A-1CZE-77eS-BNRa0r LV Write Access read/write LV Status available # open 1 LV Size 10.00 GB Current LE 320 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Name /dev/VolGroup00/opt VG Name VolGroup00 LV UUID nMgDxu-5C3a-XJCe-3YCz-AKfe-i7sE-xWnGa9 LV Write Access read/write LV Status available # open 1 LV Size 10.00 GB Current LE 320 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Name /dev/VolGroup00/var VG Name VolGroup00 LV UUID D0tQhV-pJ69-6Pwa-GEd8-AEfU-tUxF-laUcsv LV Write Access read/write LV Status available # open 1 LV Size 35.00 GB Current LE 1120 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Name /dev/VolGroup00/asm VG Name VolGroup00 LV UUID Zxe2XS-qt6t-lHHP-8blo-Gxxe-hW89-VkUksT LV Write Access read/write LV Status available # open 0 LV Size 341.00 GB Current LE 10912 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3
Vom șterge și volumul /dev/VolGroup00/asm! ATENȚIE: această ștergere implică pierderea datelor, deci să faceți backup înainte!
# lvremove /dev/VolGroup00/asm Do you really want to remove active logical volume "asm"? [y/n]: y Logical volume "asm" successfully removed # lvdisplay --- Logical volume --- LV Name /dev/VolGroup00/root VG Name VolGroup00 LV UUID 1YqBaS-1fhW-2T91-QR1A-1CZE-77eS-BNRa0r LV Write Access read/write LV Status available # open 1 LV Size 10.00 GB Current LE 320 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Name /dev/VolGroup00/opt VG Name VolGroup00 LV UUID nMgDxu-5C3a-XJCe-3YCz-AKfe-i7sE-xWnGa9 LV Write Access read/write LV Status available # open 1 LV Size 10.00 GB Current LE 320 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Name /dev/VolGroup00/var VG Name VolGroup00 LV UUID D0tQhV-pJ69-6Pwa-GEd8-AEfU-tUxF-laUcsv LV Write Access read/write LV Status available # open 1 LV Size 35.00 GB Current LE 1120 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
Deja avem spațiu liber în VG:
# pvscan
PV /dev/cciss/c0d0p2 VG VolGroup00 lvm2 [405.00 GB / 350.00 GB free]
Total: 1 [405.00 GB] / in use: 1 [405.00 GB] / in no VG: 0 [0 ]
# pvdisplay --maps
--- Physical volume ---
PV Name /dev/cciss/c0d0p2
VG Name VolGroup00
PV Size 405.03 GB / not usable 31.81 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 12960
Free PE 11200
Allocated PE 1760
PV UUID husThP-AJsD-0XhH-WIVM-c7fO-XP10-m68sXO
--- Physical Segments ---
Physical extent 0 to 319:
Logical volume /dev/VolGroup00/root
Logical extents 0 to 319
Physical extent 320 to 639:
Logical volume /dev/VolGroup00/opt
Logical extents 0 to 319
Physical extent 640 to 1759:
Logical volume /dev/VolGroup00/var
Logical extents 0 to 1119
Physical extent 1760 to 12959:
FREE
Vom încerca să micșorăm PV-ul de la 405 GB la 405 – 350 = 55 GB:
# pvresize --setphysicalvolumesize 55G /dev/cciss/c0d0p2 /dev/cciss/c0d0p2: cannot resize to 1759 extents as 1760 are allocated. 0 physical volume(s) resized / 1 physical volume(s) not resized
Se pare că 55 GB e cam puțin. Se vede importanța utilizării comenzii
pvdisplay --maps
pentru afișarea extent-urilor.
Să fim mai îngăduitori:
# pvresize --setphysicalvolumesize 55.01G /dev/cciss/c0d0p2 Physical volume "/dev/cciss/c0d0p2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized
Să vedem ce-a ieșit
# pvdisplay --maps
--- Physical volume ---
PV Name /dev/cciss/c0d0p2
VG Name VolGroup00
PV Size 55.01 GB / not usable 10.05 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 1760
Free PE 0
Allocated PE 1760
PV UUID husThP-AJsD-0XhH-WIVM-c7fO-XP10-m68sXO
--- Physical Segments ---
Physical extent 0 to 319:
Logical volume /dev/VolGroup00/root
Logical extents 0 to 319
Physical extent 320 to 639:
Logical volume /dev/VolGroup00/opt
Logical extents 0 to 319
Physical extent 640 to 1759:
Logical volume /dev/VolGroup00/var
Logical extents 0 to 1119
# pvscan
PV /dev/cciss/c0d0p2 VG VolGroup00 lvm2 [55.00 GB / 0 free]
Total: 1 [55.00 GB] / in use: 1 [55.00 GB] / in no VG: 0 [0 ]
# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 22
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 55.00 GB
PE Size 32.00 MB
Total PE 1760
Alloc PE / Size 1760 / 55.00 GB
Free PE / Size 0 / 0
VG UUID JWYHii-1wUz-NR7n-Ieeb-jucn-wHBx-Yn61Gb
# lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/root
VG Name VolGroup00
LV UUID 1YqBaS-1fhW-2T91-QR1A-1CZE-77eS-BNRa0r
LV Write Access read/write
LV Status available
# open 1
LV Size 10.00 GB
Current LE 320
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/VolGroup00/opt
VG Name VolGroup00
LV UUID nMgDxu-5C3a-XJCe-3YCz-AKfe-i7sE-xWnGa9
LV Write Access read/write
LV Status available
# open 1
LV Size 10.00 GB
Current LE 320
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Name /dev/VolGroup00/var
VG Name VolGroup00
LV UUID D0tQhV-pJ69-6Pwa-GEd8-AEfU-tUxF-laUcsv
LV Write Access read/write
LV Status available
# open 1
LV Size 35.00 GB
Current LE 1120
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
Acum vine partea complicată. Va trebui să restrângem spațiul partiției LVM la aproximativ 55 GB.
Mai întâi să vedem dimensiunea PV-ului în sectoare:
# lvm pvs --units s PV VG Fmt Attr PSize PFree /dev/cciss/c0d0p2 VolGroup00 lvm2 a- 115343360S 0S
Acum sa vedem dimensiunea partițiilor în sectoare:
# parted /dev/cciss/c0d0 unit s print Model: Compaq Smart Array (cpqarray) Disk /dev/cciss/c0d0: 860051247s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 63s 208844s 208782s primary ext3 boot 2 208845s 849620941s 849412097s primary lvm 3 849620942s 860039774s 10418833s primary Information: Don't forget to update /etc/fstab, if necessary.
ATENȚIE: Asigurați-vă că aveți backup înainte să mergeți mai departe. Vom șterge partiția 2 și o vom recrea cu același sector de Start dar un sector de End mai scurt. Sectorul de End se va calcula adunând sectorul de Start cu PSize și cu 131072 sectoare (aproximativ 64 MB). În cazul nostru, noul sector de End va fi 115683277:
# parted /dev/cciss/c0d0 rm 2 # parted /dev/cciss/c0d0 mkpart primary 208845s 115683277s # parted /dev/cciss/c0d0 set 2 lvm on # parted /dev/cciss/c0d0 unit s print Model: Compaq Smart Array (cpqarray) Disk /dev/cciss/c0d0: 860051247s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 63s 208844s 208782s primary ext3 boot 2 208845s 115683277s 115474433s primary lvm 3 849620942s 860039774s 10418833s primary Information: Don't forget to update /etc/fstab, if necessary.
Eu am șters, apoi, partiția de după LVM și am recreat-o acolo, împreună cu partiția de swap și partiția asm:
# fdisk -l
Disk /dev/cciss/c0d0: 440.3 GB, 440346238976 bytes
255 heads, 63 sectors/track, 53535 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 7201 57737216+ 8e Linux LVM
/dev/cciss/c0d0p3 52887 53535 5209416+ 83 Linux
# fdisk /dev/cciss/c0d0
The number of cylinders for this disk is set to 53535.
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
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): d
Partition number (1-4): 3
Command (m for help): p
Disk /dev/cciss/c0d0: 440.3 GB, 440346238976 bytes
255 heads, 63 sectors/track, 53535 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 7201 57737216+ 8e Linux LVM
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (7201-53535, default 7201):
Using default value 7201
Last cylinder or +size or +sizeM or +sizeK (7201-53535, default 53535): +8192M
Command (m for help): p
Disk /dev/cciss/c0d0: 440.3 GB, 440346238976 bytes
255 heads, 63 sectors/track, 53535 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 7201 57737216+ 8e Linux LVM
/dev/cciss/c0d0p3 7201 8197 8000763+ 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (8198-53535, default 8198):
Using default value 8198
Last cylinder or +size or +sizeM or +sizeK (8198-53535, default 53535):
Using default value 53535
Command (m for help): n
First cylinder (8198-53535, default 8198):
Using default value 8198
Last cylinder or +size or +sizeM or +sizeK (8198-53535, default 53535): +5120M
Command (m for help): n
First cylinder (8821-53535, default 8821):
Using default value 8821
Last cylinder or +size or +sizeM or +sizeK (8821-53535, default 53535):
Using default value 53535
Command (m for help): p
Disk /dev/cciss/c0d0: 440.3 GB, 440346238976 bytes
255 heads, 63 sectors/track, 53535 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 7201 57737216+ 8e Linux LVM
/dev/cciss/c0d0p3 7201 8197 8000763+ 83 Linux
/dev/cciss/c0d0p4 8198 53535 364177485 5 Extended
/dev/cciss/c0d0p5 8198 8820 5004216 83 Linux
/dev/cciss/c0d0p6 8821 53535 359173206 83 Linux
Command (m for help): t
Partition number (1-6): 3
Hex code (type L to list codes): 82
Changed system type of partition 3 to 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.
Syncing disks.
# fdisk -l
Disk /dev/cciss/c0d0: 440.3 GB, 440346238976 bytes
255 heads, 63 sectors/track, 53535 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 7201 57737216+ 8e Linux LVM
/dev/cciss/c0d0p3 7201 8197 8000763+ 82 Linux swap / Solaris
/dev/cciss/c0d0p4 8198 53535 364177485 5 Extended
/dev/cciss/c0d0p5 8198 8820 5004216 83 Linux
/dev/cciss/c0d0p6 8821 53535 359173206 83 Linux
Am editat apoi /etc/fstab și linia cu swap a fost modificată în felul acesta:
/dev/cciss/c0d0p3 swap swap defaults 0 0
Apoi am creat efectiv swap-ul:
mkswap /dev/cciss/c0d0p3
După un reboot ar trebui să puteți răsufla ușurat.






Recent Comments