elementary / os

The OS build system
https://elementary.io
GNU General Public License v3.0
990 stars 131 forks source link

RPi Build Script: Fix loopback device setup on system with >10 devices #662

Closed nbering closed 1 year ago

nbering commented 1 year ago

This is a minor fix for the Raspberry Pi build script, where the loop device name was overly-constrained in a regular expression.

loop9p1 - matched
loop10p1 - not a match

I changed the regular expression slightly so that more than one digit in the loop device name would be accepted.

- .*(loop[0-9])p.*
+ .*(loop[0-9]+)p.*
loop9p1 - matched
loop10p1 - matched

On host systems with more than 10 loop devices already present, the existing regular expression wouldn't match the newly-created loop device. The failed match resulted in the entire kpartx command output ending-up in the device variable, causing mkfs commands to fail. Here's an example mkfs command in a failed build:

mkfs.vfat -n system-boot '/dev/mapper/add map loop31p1 (253:0): 0 500000 linear 7:31 1p1'

Results in the error message:

mkfs.vfat: unable to open /dev/mapper/add map loop31p1 (253:0): 0 500000 linear 7:31 1p1: No such file or directory

Why would someone have so many loop devices? With Snap packages installed under Ubuntu, it seems to be mounting them from images on a loopback device, similar to the way Docker mounts filesystems for images.

nbering commented 1 year ago

I've edited the title and description to make it easier to understand what's going on here. I hope that will make it easier to review.