Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Software
idms-linux-installer
Commits
164ea07a
Commit
164ea07a
authored
Jul 13, 2020
by
Nigel Kukard
Browse files
Create EFI loader stubs instead of modifying the system EFIVARS
parent
454a0ccd
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/idmslinux_installer/util/sysgrub.py
View file @
164ea07a
...
...
@@ -15,14 +15,16 @@
"""Support class for grub on the target system."""
import
distutils.dir_util
import
os
import
re
import
shutil
from
typing
import
Optional
from
.asyncsubprocess
import
AsyncSubprocess
,
OutputCallback
# pylama:ignore=R0201,R091
4
# pylama:ignore=R0201,R091
3,R0914,C901
class
SysGrub
:
"""The SysGrub class handles configuring and installing grub on the target system."""
...
...
@@ -121,19 +123,49 @@ class SysGrub:
if
proc
.
retcode
!=
0
:
raise
OSError
(
f
'Failed to run grub-install on the target device
{
device
}
, return code
{
proc
.
retcode
}
'
)
def
install_efi
(
self
,
system_path
:
str
,
efi_dir
:
str
,
output_callback
:
OutputCallback
=
None
):
# pylama:ignore=R0913
def
install_efi
(
self
,
system_path
:
str
,
efi_dir
:
str
,
boot_uuid
:
str
,
boot_hint
:
str
,
output_callback
:
OutputCallback
=
None
):
"""Install grub on the EFI."""
# If we didn't get an output_callback, set it to our own class method
if
not
output_callback
:
output_callback
=
self
.
_default_output_callback
# Run grub-install
proc
=
AsyncSubprocess
([
'arch-chroot'
,
system_path
,
'grub-install'
,
'--target'
,
'x86_64-efi'
,
'--efi-directory'
,
efi_dir
,
'--bootloader-id'
,
'IDMS Linux'
],
# Make EFI boot directory
efi_path
=
f
'
{
system_path
}{
efi_dir
}
/EFI/BOOT'
if
not
os
.
path
.
exists
(
efi_path
):
os
.
makedirs
(
efi_path
)
# Copy grub modules
efi_path_grub
=
f
'
{
system_path
}{
efi_dir
}
/boot/grub/x86_64-efi'
distutils
.
dir_util
.
copy_tree
(
'/usr/lib/grub/x86_64-efi'
,
efi_path_grub
)
grub_fontdir
=
f
'
{
system_path
}{
efi_dir
}
/boot/grub/fonts'
grub_font
=
f
'
{
system_path
}
/usr/share/grub/unicode.pf2'
# Make font dir and copy in the unicode.pf2 font
if
not
os
.
path
.
exists
(
grub_fontdir
):
os
.
makedirs
(
grub_fontdir
)
shutil
.
copy
(
grub_font
,
grub_fontdir
)
grub_modules_extra
=
[]
if
boot_hint
and
boot_hint
.
startswith
(
'mduuid'
):
grub_modules_extra
.
append
(
'mdraid1x'
)
# Run grub-mkimage
proc
=
AsyncSubprocess
([
'arch-chroot'
,
system_path
,
'grub-mkimage'
,
'--format'
,
'x86_64-efi'
,
'--prefix'
,
'/boot/grub'
,
'--output'
,
f
'
{
efi_dir
}
/EFI/BOOT/BOOTX64.EFI'
,
'part_gpt'
,
'part_msdos'
,
'fat'
,
*
grub_modules_extra
],
output_callback
=
output_callback
)
proc
.
run
()
# Write out our stub grub.cfg to locate the main /boot grub.cfg and load it
with
open
(
f
'
{
system_path
}{
efi_dir
}
/boot/grub/grub.cfg'
,
'w'
)
as
grubcfg
:
hint
=
''
if
boot_hint
:
hint
=
f
'--hint=
\'
{
boot_hint
}
\'
'
grubcfg
.
write
(
f
'search --no-floppy --fs-uuid --set=bootfs
{
hint
}{
boot_uuid
}
\n
'
)
grubcfg
.
write
(
'configfile ($bootfs)/grub/grub.cfg
\n
'
)
# Raise an exception if we didn't get a positive response back
if
proc
.
retcode
!=
0
:
raise
OSError
(
f
'Failed to run grub-install on the efi directory
{
efi_dir
}
, return code
{
proc
.
retcode
}
'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment