Skip to content

Commit

Permalink
elbepack: hdimg: simplify grub device.map handling
Browse files Browse the repository at this point in the history
Use some helper functions to simplify the code.

Signed-off-by: Thomas Weißschuh <[email protected]>
  • Loading branch information
t-8ch committed May 10, 2024
1 parent 5c5954f commit eaa431d
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions elbepack/hdimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,9 @@ def install(self, target, user_args):
stack.enter_context(
mount(bindmnt, imagemntfs.fname(bindmnt), bind=True))

do(f'mkdir -p "{imagemntfs.fname("boot/grub")}"')

devmap = open(imagemntfs.fname('boot/grub/device.map'), 'w')
devmap.write(f'(hd0) {loopdev}\n')
devmap.close()
imagemntfs.mkdir_p('boot/grub')
imagemntfs.write_file('boot/grub/device.map', 0o644, f'(hd0) {loopdev}\n')
stack.callback(imagemntfs.remove, 'boot/grub/device.map')

chroot(imagemnt, ['update-grub2'])

Expand All @@ -188,9 +186,6 @@ def install(self, target, user_args):
except subprocess.CalledProcessError as E:
logging.error('Fail installing grub device: %s', E)

finally:
os.unlink(imagemntfs.fname('boot/grub/device.map'))


class grubinstaller97(grubinstaller_base):

Expand Down Expand Up @@ -221,11 +216,9 @@ def install(self, target, user_args):
stack.enter_context(
mount(bindmnt, imagemntfs.fname(bindmnt), bind=True))

do(f'mkdir -p "{imagemntfs.fname("boot/grub")}"')

devmap = open(imagemntfs.fname('boot/grub/device.map'), 'w')
devmap.write(f'(hd0) {loopdev}\n')
devmap.close()
imagemntfs.mkdir_p('boot/grub')
imagemntfs.write_file('boot/grub/device.map', 0o644, f'(hd0) {loopdev}\n')
stack.callback(imagemntfs.remove, 'boot/grub/device.map')

# Replace groot and kopt because else they will be given
# bad values
Expand All @@ -241,9 +234,6 @@ def install(self, target, user_args):
except subprocess.CalledProcessError as E:
logging.error('Fail installing grub device: %s', E)

finally:
os.unlink(imagemntfs.fname('boot/grub/device.map'))


class simple_fstype:
def __init__(self, typ):
Expand Down

0 comments on commit eaa431d

Please sign in to comment.