LVM¶
This section documents the Logical Volume Management (LVM) functionality.
sts.lvm
¶
LVM device management.
This module provides functionality for managing LVM devices: - Physical Volume (PV) operations - Volume Group (VG) operations - Logical Volume (LV) operations
LVM (Logical Volume Management) provides flexible disk space management: 1. Physical Volumes (PVs): Physical disks or partitions 2. Volume Groups (VGs): Pool of space from PVs 3. Logical Volumes (LVs): Virtual partitions from VG space
Key benefits: - Resize filesystems online - Snapshot and mirror volumes - Stripe across multiple disks - Move data between disks
LogicalVolume
dataclass
¶
Bases: LvmDevice
Logical Volume device.
A Logical Volume (LV) is a virtual partition created from VG space. LVs appear as block devices that can be formatted and mounted.
Key features: - Flexible sizing - Online resizing - Snapshots - Striping and mirroring - Thin provisioning
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str | None
|
Device name (optional) |
None
|
path
|
Path | str | None
|
Device path (optional, defaults to /dev/ |
None
|
size
|
int | None
|
Device size in bytes (optional, discovered from device) |
None
|
model
|
str | None
|
Device model (optional) |
None
|
yes
|
bool
|
Automatically answer yes to prompts |
True
|
force
|
bool
|
Force operations without confirmation |
False
|
vg
|
str | None
|
Volume group name (optional, discovered from device) |
None
|
Example
lv = LogicalVolume(name='lv0') # Discovers other values
lv = LogicalVolume.create('lv0', 'vg0', size='1G') # Creates new LV
Source code in sts_libs/src/sts/lvm.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
|
__post_init__()
¶
Initialize Logical Volume.
- Sets device path from name and VG
- Discovers VG membership
Source code in sts_libs/src/sts/lvm.py
521 522 523 524 525 526 527 528 529 |
|
change(*args, **options)
¶
Create Logical Volume.
Change a general LV attribute:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
str
|
LV options (see LVMOptions) |
()
|
**options
|
str
|
LV options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Example
lv = LogicalVolume(name='lv0', vg='vg0')
lv.change('-an', 'vg0/lv0')
True
Source code in sts_libs/src/sts/lvm.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
|
create(**options)
¶
Create Logical Volume.
Creates a new LV in the specified VG: - Allocates space from VG - Creates device mapper device - Initializes LV metadata
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**options
|
str
|
LV options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Example
lv = LogicalVolume(name='lv0', vg='vg0')
lv.create(size='1G')
True
Source code in sts_libs/src/sts/lvm.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
|
discover_vg()
¶
Discover VG if name is available.
Source code in sts_libs/src/sts/lvm.py
531 532 533 534 535 536 537 538 |
|
extend(pvs, **options)
¶
Extend Volume Group with additional Physical Volumes.
Adds one or more PVs to an existing VG: - PVs must be initialized (using pvcreate) - PVs must not belong to another VG - Updates VG metadata and extent allocation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pvs
|
list[str]
|
List of PV device paths to add |
required |
**options
|
str
|
VG options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Example
vg = VolumeGroup(name='vg0')
vg.extend(['/dev/sdb1', '/dev/sdc1'])
True
Source code in sts_libs/src/sts/lvm.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
|
remove(**options)
¶
Remove Logical Volume.
Removes LV and its data: - Data is permanently lost - Space is returned to VG - Device mapper device is removed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**options
|
str
|
LV options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Example
lv = LogicalVolume(name='lv0', vg='vg0')
lv.remove()
True
Source code in sts_libs/src/sts/lvm.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
|
LvmDevice
dataclass
¶
Bases: StorageDevice
Base class for LVM devices.
Provides common functionality for all LVM device types: - Command execution with standard options - Configuration management - Basic device operations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str | None
|
Device name (optional) |
None
|
path
|
Path | str | None
|
Device path (optional, defaults to /dev/ |
None
|
size
|
int | None
|
Device size in bytes (optional, discovered from device) |
None
|
model
|
str | None
|
Device model (optional) |
None
|
yes
|
bool
|
Automatically answer yes to prompts |
True
|
force
|
bool
|
Force operations without confirmation |
False
|
The yes and force options are useful for automation: - yes: Skip interactive prompts - force: Ignore warnings and errors
Source code in sts_libs/src/sts/lvm.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
__post_init__()
¶
Initialize LVM device.
Source code in sts_libs/src/sts/lvm.py
122 123 124 125 126 127 128 129 |
|
create(**options)
abstractmethod
¶
Create LVM device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**options
|
str
|
Device options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Source code in sts_libs/src/sts/lvm.py
159 160 161 162 163 164 165 166 167 168 |
|
remove(**options)
abstractmethod
¶
Remove LVM device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**options
|
str
|
Device options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Source code in sts_libs/src/sts/lvm.py
170 171 172 173 174 175 176 177 178 179 |
|
LvmOptions
¶
Bases: TypedDict
LVM command options.
Common options: - size: Volume size (e.g. '1G', '500M') - extents: Volume size in extents (e.g. '100%FREE') - permission: Volume permission (rw/r) - persistent: Make settings persistent across reboots - monitor: Monitor volume for events - autobackup: Auto backup metadata after changes
Size can be specified in: - Absolute size (1G, 500M) - Percentage of VG (80%VG) - Percentage of free space (100%FREE) - Physical extents (100)
Source code in sts_libs/src/sts/lvm.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
PVInfo
dataclass
¶
Physical Volume information.
Stores key information about a Physical Volume: - Volume group membership - Format type (lvm2) - Attributes (allocatable, exported, etc) - Size information (total and free space)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vg
|
str | None
|
Volume group name (None if not in a VG) |
required |
fmt
|
str
|
PV format (usually 'lvm2') |
required |
attr
|
str
|
PV attributes (e.g. 'a--' for allocatable) |
required |
psize
|
str
|
PV size (e.g. '1.00t') |
required |
pfree
|
str
|
PV free space (e.g. '500.00g') |
required |
Source code in sts_libs/src/sts/lvm.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
PhysicalVolume
dataclass
¶
Bases: LvmDevice
Physical Volume device.
A Physical Volume (PV) is a disk or partition used by LVM. PVs provide the storage pool for Volume Groups.
Key features: - Initialize disks/partitions for LVM use - Track space allocation - Handle bad block management - Store LVM metadata
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str | None
|
Device name (optional) |
None
|
path
|
Path | str | None
|
Device path (optional, defaults to /dev/ |
None
|
size
|
int | None
|
Device size in bytes (optional, discovered from device) |
None
|
model
|
str | None
|
Device model (optional) |
None
|
yes
|
bool
|
Automatically answer yes to prompts |
True
|
force
|
bool
|
Force operations without confirmation |
False
|
vg
|
str | None
|
Volume group name (optional, discovered from device) |
None
|
fmt
|
str | None
|
PV format (optional, discovered from device) |
None
|
attr
|
str | None
|
PV attributes (optional, discovered from device) |
None
|
pfree
|
str | None
|
PV free space (optional, discovered from device) |
None
|
Example
pv = PhysicalVolume(name='sda1') # Discovers other values
pv = PhysicalVolume.create('/dev/sda1') # Creates new PV
Source code in sts_libs/src/sts/lvm.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
create(**options)
¶
Create Physical Volume.
Initializes a disk or partition for use with LVM: - Creates LVM metadata area - Prepares device for VG membership
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**options
|
str
|
PV options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Example
pv = PhysicalVolume(path='/dev/sda1')
pv.create()
True
Source code in sts_libs/src/sts/lvm.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
discover_pv_info()
¶
Discovers PV information if path is available.
Volume group membership. Format and attributes. Size information.
Source code in sts_libs/src/sts/lvm.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
get_all()
classmethod
¶
Get all Physical Volumes.
Returns:
Type | Description |
---|---|
dict[str, PVInfo]
|
Dictionary mapping PV names to their information |
Example
PhysicalVolume.get_all()
{'/dev/sda1': PVInfo(vg='vg0', fmt='lvm2', ...)}
Source code in sts_libs/src/sts/lvm.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
remove(**options)
¶
Remove Physical Volume.
Removes LVM metadata from device: - Device must not be in use by a VG - Data on device is not erased
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**options
|
str
|
PV options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Example
pv = PhysicalVolume(path='/dev/sda1')
pv.remove()
True
Source code in sts_libs/src/sts/lvm.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
VolumeGroup
dataclass
¶
Bases: LvmDevice
Volume Group device.
A Volume Group (VG) combines Physical Volumes into a storage pool. This pool can then be divided into Logical Volumes.
Key features: - Combine multiple PVs - Manage storage pool - Track extent allocation - Handle PV addition/removal
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str | None
|
Device name (optional) |
None
|
path
|
Path | str | None
|
Device path (optional, defaults to /dev/ |
None
|
size
|
int | None
|
Device size in bytes (optional, discovered from device) |
None
|
model
|
str | None
|
Device model (optional) |
None
|
yes
|
bool
|
Automatically answer yes to prompts |
True
|
force
|
bool
|
Force operations without confirmation |
False
|
pvs
|
list[str]
|
List of Physical Volumes (optional, discovered from device) |
list()
|
Example
vg = VolumeGroup(name='vg0') # Discovers other values
vg = VolumeGroup.create('vg0', ['/dev/sda1']) # Creates new VG
Source code in sts_libs/src/sts/lvm.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|
create(**options)
¶
Create Volume Group.
Creates a new VG from specified PVs: - Initializes VG metadata - Sets up extent allocation - Creates device mapper devices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**options
|
str
|
VG options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Example
vg = VolumeGroup(name='vg0', pvs=['/dev/sda1'])
vg.create()
True
Source code in sts_libs/src/sts/lvm.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
discover_pvs()
¶
Discover PVs if name is available.
Source code in sts_libs/src/sts/lvm.py
404 405 406 407 408 409 410 411 |
|
remove(**options)
¶
Remove Volume Group.
Removes VG and its metadata: - All LVs must be removed first - PVs are released but not removed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**options
|
str
|
VG options (see LvmOptions) |
{}
|
Returns:
Type | Description |
---|---|
bool
|
True if successful, False otherwise |
Example
vg = VolumeGroup(name='vg0')
vg.remove()
True
Source code in sts_libs/src/sts/lvm.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|