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
Nigel Kukard
IDMS Linux Installer
Commits
4a32346b
Commit
4a32346b
authored
Jun 17, 2019
by
Nigel Kukard
Browse files
Generate grub.cfg
parent
ebf6f555
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/idmslinux_installer/plugins/config_system/grub.py
View file @
4a32346b
...
...
@@ -45,8 +45,6 @@ class ConfigSystemGrub(Plugin):
if
'lvm2'
in
ili_state
.
base_packages
:
kwargs
[
'lvm'
]
=
True
sysgrub
.
configure
(
ili_state
.
target_root
)
# Loop with each disk we must install an MBR on
for
device
in
ili_state
.
boot_mbrs
:
ili_state
.
output_callback
(
f
'Installing grub MBR on
{
device
}
'
)
...
...
@@ -56,3 +54,7 @@ class ConfigSystemGrub(Plugin):
if
ili_state
.
fstab
[
'efi'
]:
ili_state
.
output_callback
(
'Installing grub EFI in %s'
%
ili_state
.
fstab
[
'efi'
][
'mount_point'
])
sysgrub
.
install_efi
(
ili_state
.
target_root
,
ili_state
.
fstab
[
'efi'
][
'mount_point'
],
ili_state
.
output_callback
)
# We configure grub after the installation becaues this is when the /boot/grub dir exists
sysgrub
.
configure
(
ili_state
.
target_root
,
ili_state
.
output_callback
)
src/idmslinux_installer/util/sysgrub.py
View file @
4a32346b
...
...
@@ -17,6 +17,7 @@
import
os
import
re
from
typing
import
Optional
from
.asyncsubprocess
import
AsyncSubprocess
,
OutputCallback
...
...
@@ -27,14 +28,20 @@ class SysGrub:
def
__init__
(
self
):
"""Initialize our class."""
def
configure
(
self
,
system_path
:
str
,
**
kwargs
):
def
configure
(
self
,
system_path
:
str
,
output_callback
:
Optional
[
OutputCallback
]
=
None
,
**
kwargs
):
"""Configure grub."""
sys_grub_conf
=
f
'
{
system_path
}
/etc/default/grub'
sys_grub_conf_new
=
f
'
{
sys_grub_conf
}
.new'
sys_grub_conf
=
'/boot/grub/grub.cfg'
sys_default_grub
=
f
'
{
system_path
}
/etc/default/grub'
sys_default_grub_new
=
f
'
{
sys_default_grub
}
.new'
# 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
# Open the config files and process
with
open
(
sys_
grub_conf
,
'r'
)
as
conf_file
,
open
(
sys_
grub_conf
_new
,
'w'
)
as
conf_file_new
:
with
open
(
sys_
default_grub
,
'r'
)
as
conf_file
,
open
(
sys_
default_grub
_new
,
'w'
)
as
conf_file_new
:
# Loop with lines
for
line
in
conf_file
:
# Check if we can pull out the modules
...
...
@@ -59,7 +66,16 @@ class SysGrub:
conf_file_new
.
close
()
# Move new file ontop of old one
os
.
replace
(
sys_grub_conf_new
,
sys_grub_conf
)
os
.
replace
(
sys_default_grub_new
,
sys_default_grub
)
# Run grub-mkconfig
proc
=
AsyncSubprocess
([
'arch-chroot'
,
system_path
,
'grub-mkconfig'
,
'-o'
,
sys_grub_conf
],
output_callback
=
output_callback
)
proc
.
run
()
# Raise an exception if we didn't get a positive response back
if
proc
.
retcode
!=
0
:
raise
OSError
(
f
'Failed to run grub-mkconfig on the target system, return code
{
proc
.
retcode
}
'
)
def
install_mbr
(
self
,
system_path
:
str
,
device
:
str
,
output_callback
:
OutputCallback
=
None
):
"""Install grub on the MBR."""
...
...
Write
Preview
Supports
Markdown
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