Skip to content

Commit 0c7c896

Browse files
praveenkumaropenshift-merge-robot
authored andcommitted
Microshift: add disk resize functionality
The way this PR works is in following steps - It grows the disk size using growpart command - Resize the physical volume using pvresize command - Get the size of whole physical volume and root logical volume then we subtract existing free volume and check how much lv can be extended. Note: This is not going to extend the free space which is used by the LVM Storage Operator for persistent local storage
1 parent 655822f commit 0c7c896

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

Diff for: pkg/crc/machine/start.go

+48-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ func (client *client) updateVMConfig(startConfig types.StartConfig, vm *virtualM
113113

114114
func growRootFileSystem(sshRunner *crcssh.Runner, preset crcPreset.Preset) error {
115115
if preset == crcPreset.Microshift {
116-
logging.Debugf("growRootFileSystem does not support LVM which is used by %s images", preset)
117-
return nil
116+
return growLVForMicroshift(sshRunner)
118117
}
119118
// With 4.7, this is quite a manual process until https://github.com/openshift/installer/pull/4746 gets fixed
120119
// See https://github.com/crc-org/crc/issues/2104 for details
@@ -165,6 +164,53 @@ func runGrowpart(sshRunner *crcssh.Runner, rootPart string) error {
165164
return nil
166165
}
167166

167+
func growLVForMicroshift(sshRunner *crcssh.Runner) error {
168+
rootPart, _, err := sshRunner.RunPrivileged("Get PV disk path", "/usr/sbin/pvs", "-S", "lv_name=root", "-o", "pv_name", "--noheadings")
169+
if err != nil {
170+
return err
171+
}
172+
rootPart = strings.TrimSpace(rootPart)
173+
if err := runGrowpart(sshRunner, rootPart); err != nil {
174+
return err
175+
}
176+
177+
if _, _, err := sshRunner.RunPrivileged("Resizing the physical volume(PV)", "/usr/sbin/pvresize", rootPart); err != nil {
178+
return err
179+
}
180+
181+
// Get the size of volume group
182+
sizeVG, _, err := sshRunner.RunPrivileged("Get the volume group size", "/usr/sbin/vgs", "--noheadings", "--nosuffix", "--units", "b", "-o", "vg_size")
183+
if err != nil {
184+
return err
185+
}
186+
vgSize, err := strconv.Atoi(strings.TrimSpace(sizeVG))
187+
if err != nil {
188+
return err
189+
}
190+
191+
// Get the size of root lv
192+
sizeLV, _, err := sshRunner.RunPrivileged("Get the size of root logical volume", "/usr/sbin/lvs", "-S", "lv_name=root", "--noheadings", "--nosuffix", "--units", "b", "-o", "lv_size")
193+
if err != nil {
194+
return err
195+
}
196+
lvSize, err := strconv.Atoi(strings.TrimSpace(sizeLV))
197+
if err != nil {
198+
return err
199+
}
200+
201+
// vgFree space as part of the bundle is default to ~15.02G (16127098880 byte)
202+
vgFree := 16127098880
203+
expectedLVSize := vgSize - vgFree
204+
sizeToIncrease := expectedLVSize - lvSize
205+
if sizeToIncrease > 1 {
206+
logging.Info("Extending and resizing '/dev/rhel/root' logical volume")
207+
if _, _, err := sshRunner.RunPrivileged("Extending and resizing the logical volume(LV)", "/usr/sbin/lvextend", "-r", "-L", fmt.Sprintf("+%db", sizeToIncrease), "/dev/rhel/root"); err != nil {
208+
return err
209+
}
210+
}
211+
return nil
212+
}
213+
168214
func configureSharedDirs(vm *virtualMachine, sshRunner *crcssh.Runner) error {
169215
logging.Debugf("Configuring shared directories")
170216
sharedDirs, err := vm.Driver.GetSharedDirs()

0 commit comments

Comments
 (0)