Skip to content

Commit 54b3dd2

Browse files
committed
feat: add support for disk partition expansion and PV resize
Add more support for disk partition expansion and pv resize based on current LV expansion implementation to ensure smooth LV growth after OS disk increased to bigger size - Add growpart-based partition expansion - Resize the PV to match respective device size via storage role after grow_to_fill is set as True JIRA: RHELHPC-150 Signed-off-by: Xuemin Li <xuli@redhat.com>
1 parent e80b290 commit 54b3dd2

2 files changed

Lines changed: 69 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ You can use variables described in this section to control the exact sizes and p
316316

317317
Whether to configure the VG from [hpc_rootvg_name](#hpc_rootvg_name) to have logical volumes [hpc_rootlv_name](#hpc_rootlv_name), [hpc_usrlv_name](#hpc_usrlv_name) and [hpc_varlv_name](#hpc_varlv_name) with indicated sizes and mounted to indicated mount points.
318318

319+
When enabled, it will also automatically handles disk expansion by resizing partitions (via `growpart`), physical volumes (via `pvresize`) besides logical volumes.
320+
319321
Note that the role configures not the exact size, but ensures that the size is at least as indicated, i.e. the role won't shrink logical volumes.
320322

321323
Default: `true`

tasks/main.yml

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,37 +152,95 @@
152152

153153
- name: Check if rootlv exists
154154
stat:
155-
path: /dev/mapper/{{ hpc_rootvg_name }}-{{ hpc_rootlv_name }}
155+
path: /dev/{{ hpc_rootvg_name }}/{{ hpc_rootlv_name }}
156156
register: __hpc_rootlv_stat
157157

158158
- name: Check if usrlv exists
159159
stat:
160-
path: /dev/mapper/{{ hpc_rootvg_name }}-{{ hpc_usrlv_name }}
160+
path: /dev/{{ hpc_rootvg_name }}/{{ hpc_usrlv_name }}
161161
register: __hpc_usrlv_stat
162162

163163
- name: Check if varlv exists
164164
stat:
165-
path: /dev/mapper/{{ hpc_rootvg_name }}-{{ hpc_varlv_name }}
165+
path: /dev/{{ hpc_rootvg_name }}/{{ hpc_varlv_name }}
166166
register: __hpc_varlv_stat
167167

168168
- name: Get current LV size of rootlv
169-
command: lvs --noheadings --units g --nosuffix -o lv_size /dev/mapper/{{ hpc_rootvg_name }}-{{ hpc_rootlv_name }}
169+
command: lvs --noheadings --units g --nosuffix -o lv_size /dev/{{ hpc_rootvg_name }}/{{ hpc_rootlv_name }}
170170
register: __hpc_rootlv_size_cmd
171171
changed_when: false
172172
when: __hpc_rootlv_stat.stat.exists
173173

174174
- name: Get current LV size of usrlv
175-
command: lvs --noheadings --units g --nosuffix -o lv_size /dev/mapper/{{ hpc_rootvg_name }}-{{ hpc_usrlv_name }}
175+
command: lvs --noheadings --units g --nosuffix -o lv_size /dev/{{ hpc_rootvg_name }}/{{ hpc_usrlv_name }}
176176
register: __hpc_usrlv_size_cmd
177177
changed_when: false
178178
when: __hpc_usrlv_stat.stat.exists
179179

180180
- name: Get current LV size of varlv
181-
command: lvs --noheadings --units g --nosuffix -o lv_size /dev/mapper/{{ hpc_rootvg_name }}-{{ hpc_varlv_name }}
181+
command: lvs --noheadings --units g --nosuffix -o lv_size /dev/{{ hpc_rootvg_name }}/{{ hpc_varlv_name }}
182182
register: __hpc_varlv_size_cmd
183183
changed_when: false
184184
when: __hpc_varlv_stat.stat.exists
185185

186+
- name: Check if volume group exists
187+
command: vgs --noheadings -o vg_name {{ hpc_rootvg_name }}
188+
register: __hpc_vg_check
189+
changed_when: false
190+
failed_when: false
191+
192+
- name: Get PV devices for volume group
193+
command: pvs --noheadings -o pv_name -S vg_name={{ hpc_rootvg_name }}
194+
register: __hpc_pv_devices
195+
changed_when: false
196+
when: __hpc_vg_check.rc == 0
197+
198+
- name: Set PV device list for storage role
199+
set_fact:
200+
__hpc_rootvg_disks: "{{ __hpc_pv_devices.stdout_lines | map('trim') | list }}"
201+
when:
202+
- __hpc_vg_check.rc == 0
203+
- __hpc_pv_devices.stdout_lines | length > 0
204+
205+
- name: Expand partitions if underlying disks have been expanded
206+
when:
207+
- __hpc_vg_check.rc == 0
208+
- __hpc_rootvg_disks is defined
209+
- __hpc_rootvg_disks | length > 0
210+
block:
211+
- name: Install cloud-utils-growpart for partition expansion
212+
package:
213+
name: cloud-utils-growpart
214+
state: present
215+
use: "{{ (__hpc_server_is_ostree | d(false)) |
216+
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
217+
218+
- name: Expand partitions via growpart
219+
vars:
220+
# From pv_device to extract parent_device and partition_number example
221+
# SCSI: /dev/sda4 -> /dev/sda and 4
222+
# NVMe: /dev/nvme0n1p4 -> /dev/nvme0n1 and 4
223+
pv_device: "{{ item }}"
224+
parent_device: "{{ pv_device | regex_replace('p?([0-9]+)$', '') }}"
225+
partition_number: "{{ pv_device | regex_search('([0-9]+)$') }}"
226+
command: growpart {{ parent_device }} {{ partition_number }}
227+
register: __hpc_growpart_result
228+
changed_when:
229+
- __hpc_growpart_result.rc == 0
230+
- "'NOCHANGE' not in __hpc_growpart_result.stdout"
231+
failed_when:
232+
- __hpc_growpart_result.rc != 0
233+
- "'NOCHANGE' not in __hpc_growpart_result.stdout"
234+
loop: "{{ __hpc_rootvg_disks }}"
235+
when:
236+
- partition_number | length > 0
237+
- parent_device != pv_device
238+
239+
# - name: Resize PVs to use expanded partition space
240+
# command: pvresize {{ item }}
241+
# changed_when: false
242+
# loop: "{{ __hpc_rootvg_disks }}"
243+
186244
- name: Initialize volumes list
187245
set_fact:
188246
__hpc_volumes: []
@@ -229,12 +287,13 @@
229287
- __hpc_varlv_stat.stat.exists
230288
- (size_expected | int) > (size_current | int)
231289

232-
- name: Configure storage
290+
- name: Configure storage via storage role
233291
include_role:
234292
name: fedora.linux_system_roles.storage
235293
vars:
236294
storage_pools:
237295
- name: "{{ hpc_rootvg_name }}"
296+
disks: "{{ __hpc_rootvg_disks | default(omit) }}"
238297
grow_to_fill: true
239298
volumes: "{{ __hpc_volumes }}"
240299
when: __hpc_volumes | length > 0
@@ -1261,7 +1320,7 @@
12611320
Skipping azurehpc-health-checks installation because aznhc-nv Docker image cannot be pulled.
12621321
To install health checks, increase /var space by:
12631322
(1) Expanding the root disk in Azure portal,
1264-
(2) Adding the new space as a PV to the volume group (e.g., pvresize /dev/sda2),
1323+
(2) Adding the new space as a PV to the volume group (e.g., pvresize /dev/sda4),
12651324
(3) Expanding the /var logical volume (e.g., lvextend -L +20G /dev/rootvg/varlv && xfs_growfs /var).
12661325
See https://learn.microsoft.com/en-us/azure/virtual-machines/linux/expand-disks?tabs=rhellvm for details.
12671326
Alternatively, configure hpc_varlv_size before running this role.

0 commit comments

Comments
 (0)