#NEWLINE# @ contextmanager #NEWLINE# def grub2_prepare( kernel_params = '' , chroot = '' , grub_timeout = 5 , lvm_boot = False ) : #NEWLINE# #INDENT# old_env = os . environ . copy ( ) #NEWLINE# os . environ [ 'GRUB_DISABLE_SUBMENU' ] = 'y' #NEWLINE# os . environ [ 'GRUB_CMDLINE_LINUX_DEFAULT' ] = kernel_params #NEWLINE# os . environ [ 'GRUB_CMDLINE_LINUX' ] = kernel_params #NEWLINE# os . environ [ 'GRUB_HIDDEN_TIMEOUT' ] = str ( grub_timeout ) #NEWLINE# os . environ [ 'GRUB_RECORDFAIL_TIMEOUT' ] = str ( grub_timeout ) #NEWLINE# os . environ [ 'GRUB_DISABLE_OS_PROBER' ] = 'true' #NEWLINE# os . environ [ 'GRUB_DISABLE_LINUX_UUID' ] = 'true' #NEWLINE# os . environ [ 'GRUB_DISABLE_RECOVERY' ] = 'true' #NEWLINE# if lvm_boot : #NEWLINE# #INDENT# os . environ [ 'GRUB_PRELOAD_MODULES' ] = 'lvm' #NEWLINE# #UNINDENT# if os . path . isfile ( os . path . join ( chroot , 'boot/grub/grub.conf' ) ) : #NEWLINE# #INDENT# os . remove ( os . path . join ( chroot , 'boot/grub/grub.conf' ) ) #NEWLINE# #UNINDENT# ( yield ) #NEWLINE# os . environ = old_env