99 lines
2.2 KiB
Markdown

# OS Disk Role
Manages LVM (Logical Volume Management) setup for Debian systems, including volume groups, logical volumes, filesystem creation, and mounting.
## What it does
This role:
- Installs LVM2 and parted packages
- Deploys a disk detection script (`setup_lvm_devices.sh`) for automatic device initialization
- Creates and manages volume groups (VGs) from physical devices
- Creates logical volumes (LVs) with specified sizes
- Formats logical volumes with filesystems
- Mounts logical volumes and adds entries to `/etc/fstab`
## Variables
### `disks_vg` (list)
List of volume group configurations.
**Structure:**
```yaml
disks_vg:
- vg: string # Volume group name
state: string # present (default) | absent
devices_dev: list # List of device paths (e.g., ['/dev/vda', '/dev/vdb'])
```
### `disks_lv` (list)
List of logical volume configurations.
**Structure:**
```yaml
disks_lv:
- lv: string # Logical volume name
vg: string # Volume group name (must exist in disks_vg)
size: string # Size with unit (e.g., '20G', '500M')
state: string # present (mounted) | absent (destroyed)
fstype: string # Filesystem type (default: ext4)
```
**Notes:**
- Mount path is automatically derived from LV name: `/{{ lv | replace('_', '/') }}`
- Example: LV name `var_lib_docker` mounts to `/var/lib/docker`
## Examples
### Basic LVM setup with single volume group
```yaml
disks_vg:
- vg: data
devices_dev:
- /dev/vda
- /dev/vdb
disks_lv:
- lv: var_lib_docker
vg: data
size: 20G
fstype: ext4
- lv: var_log
vg: data
size: 5G
fstype: xfs
```
### Multiple volume groups with different states
```yaml
disks_vg:
- vg: data
state: present
devices_dev:
- /dev/vda
- vg: backup
state: present
devices_dev:
- /dev/vdc
disks_lv:
- lv: var_lib_docker
vg: data
size: 20G
state: present
fstype: ext4
- lv: backup_storage
vg: backup
size: 100G
state: present
fstype: ext4
```
### Removing logical volumes
```yaml
disks_lv:
- lv: old_data
vg: data
size: 10G
state: absent # Will unmount and destroy the LV
```