@@ -518,92 +518,34 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, deleteBeforeCopy bo
518518 }
519519 }
520520
521- var rootUuid string
522- // If Thin-Provisioning set, mount init partition and move linux and initrd
523- // images to it.
524- var initMountpoint string
525- if settings .Cnf .ThinProvisioning {
526- initPartition , err := s .RootM .GetInit ()
527- if err != nil {
528- PrintVerboseErr ("ABSystem.RunOperation" , 7.3 , err )
529- return err
530- }
531-
532- initMountpoint = filepath .Join (futureRoot , "boot" , "init" )
533- err = initPartition .Mount (initMountpoint )
534- if err != nil {
535- PrintVerboseErr ("ABSystem.RunOperation" , 7.4 , err )
536- return err
537- }
538-
539- cq .Add (func (args ... interface {}) error {
540- return initPartition .Unmount ()
541- }, nil , 80 , & goodies.NoErrorHandler {}, false )
542-
543- futureInitDir := filepath .Join (initMountpoint , partFuture .Label )
544-
545- if ! dryRun {
546- err = os .RemoveAll (futureInitDir )
547- if err != nil {
548- PrintVerboseWarn ("ABSystem.RunOperation" , 7.44 )
549- }
550- err = os .MkdirAll (futureInitDir , 0o755 )
551- if err != nil {
552- PrintVerboseWarn ("ABSystem.RunOperation" , 7.47 , err )
553- }
554-
555- err = MoveFile (
556- filepath .Join (futureRoot , "boot" , "vmlinuz-" + newKernelVer ),
557- filepath .Join (futureInitDir , "vmlinuz-" + newKernelVer ),
558- )
559- if err != nil {
560- PrintVerboseErr ("ABSystem.RunOperation" , 7.5 , err )
561- return err
562- }
563- err = MoveFile (
564- filepath .Join (futureRoot , "boot" , "initrd.img-" + newKernelVer ),
565- filepath .Join (futureInitDir , "initrd.img-" + newKernelVer ),
566- )
567- if err != nil {
568- PrintVerboseErr ("ABSystem.RunOperation" , 7.6 , err )
569- return err
570- }
571- err = MoveFile (
572- filepath .Join (futureRoot , "boot" , "config-" + newKernelVer ),
573- filepath .Join (futureInitDir , "config-" + newKernelVer ),
574- )
575- if err != nil {
576- PrintVerboseErr ("ABSystem.RunOperation" , 7.7 , err )
577- return err
578- }
579- err = MoveFile (
580- filepath .Join (futureRoot , "boot" , "System.map-" + newKernelVer ),
581- filepath .Join (futureInitDir , "System.map-" + newKernelVer ),
582- )
583- if err != nil {
584- PrintVerboseErr ("ABSystem.RunOperation" , 7.8 , err )
585- return err
586- }
587-
588- }
521+ tmpBootMount := "/run/abroot/tmp-boot-mount-1/"
522+ err = os .MkdirAll (tmpBootMount , 0o755 )
523+ if err != nil {
524+ PrintVerboseErr ("ABSystem.RunOperation" , 9 , err )
525+ return err
526+ }
589527
590- rootUuid = initPartition .Uuid
591- } else {
592- rootUuid = partFuture .Partition .Uuid
528+ err = partBoot .Mount (tmpBootMount )
529+ if err != nil {
530+ PrintVerboseErr ("ABSystem.RunOperation" , 9.1 , err )
531+ return err
593532 }
594533
595- if ! dryRun {
596- err = generateABGrubConf (
597- newKernelVer ,
598- futureRoot ,
599- rootUuid ,
600- partFuture .Label ,
601- generatedGrubConfigPath ,
602- )
603- if err != nil {
604- PrintVerboseErr ("ABSystem.RunOperation" , 7.9 , err )
605- return err
606- }
534+ cq .Add (func (args ... interface {}) error {
535+ return partBoot .Unmount ()
536+ }, nil , 100 , & goodies.NoErrorHandler {}, false )
537+
538+ err = createABSpecificGrub (
539+ newKernelVer ,
540+ partFuture .Partition .Uuid ,
541+ partFuture .Label ,
542+ filepath .Join (futureRoot , generatedGrubConfigPath ),
543+ tmpBootMount ,
544+ filepath .Join (futureRoot , "/boot/" ),
545+ )
546+ if err != nil {
547+ PrintVerboseErr ("ABSystem.RunOperation" , 7.9 , err )
548+ return err
607549 }
608550
609551 // Stage 7: Sync /etc
@@ -627,31 +569,10 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, deleteBeforeCopy bo
627569 }
628570 }
629571
630- // Stage 8: Mount boot partition
572+ // Stage 8: Atomic swap the bootloader
631573 // ------------------------------------------------
632574 PrintVerboseSimple ("[Stage 8] -------- ABSystemRunOperation" )
633575
634- tmpBootMount := "/run/abroot/tmp-boot-mount-1/"
635- err = os .MkdirAll (tmpBootMount , 0o755 )
636- if err != nil {
637- PrintVerboseErr ("ABSystem.RunOperation" , 9 , err )
638- return err
639- }
640-
641- err = partBoot .Mount (tmpBootMount )
642- if err != nil {
643- PrintVerboseErr ("ABSystem.RunOperation" , 9.1 , err )
644- return err
645- }
646-
647- cq .Add (func (args ... interface {}) error {
648- return partBoot .Unmount ()
649- }, nil , 100 , & goodies.NoErrorHandler {}, false )
650-
651- // Stage 9: Atomic swap the bootloader
652- // ------------------------------------------------
653- PrintVerboseSimple ("[Stage 9] -------- ABSystemRunOperation" )
654-
655576 grub , err := NewGrub (partBoot )
656577 if err != nil {
657578 PrintVerboseErr ("ABSystem.RunOperation" , 11 , err )
@@ -668,34 +589,53 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, deleteBeforeCopy bo
668589 grubCfgCurrent := filepath .Join (tmpBootMount , "grub/grub.cfg" )
669590 grubCfgFuture := filepath .Join (tmpBootMount , "grub/grub.cfg.future" )
670591
671- // Just like in Stage 9, tmpBootMount/grub/grub.cfg.future may not exist.
672- if _ , err = os .Stat (grubCfgFuture ); os .IsNotExist (err ) {
673- PrintVerboseInfo ("ABSystem.RunOperation" , "Creating grub.cfg.future" )
592+ _ = os .Remove (grubCfgFuture )
674593
675- grubCfgContents , err := os .ReadFile (grubCfgCurrent )
676- if err != nil {
677- PrintVerboseErr ("ABSystem.RunOperation" , 11.2 , err )
678- }
594+ const preamble string = `set timeout=5
679595
680- var replacerPairs []string
681- if grub .FutureRoot == "a" {
682- replacerPairs = []string {
683- "default=1" , "default=0" ,
684- "Previous State (A)" , "Current State (A)" ,
685- "Current State (B)" , "Previous State (B)" ,
686- }
687- } else {
688- replacerPairs = []string {
689- "default=0" , "default=1" ,
690- "Current State (A)" , "Previous State (A)" ,
691- "Previous State (B)" , "Current State (B)" ,
692- }
693- }
596+ # Load video support
597+ insmod gfxterm
598+ insmod all_video
599+
600+ # Set graphics mode
601+ set gfxmode=1024x768,auto
602+ terminal_output gfxterm
603+
604+ `
605+
606+ const state_a string = `
607+ set default=0
608+
609+ menuentry "Current State (A)" --class abroot-a {
610+ configfile "/abroot/%s/abroot.cfg"
611+ }
612+
613+ menuentry "Previous State (B)" --class abroot-b {
614+ configfile "/abroot/%s/abroot.cfg"
615+ }
616+ `
694617
695- replacer := strings .NewReplacer (replacerPairs ... )
696- os .WriteFile (grubCfgFuture , []byte (replacer .Replace (string (grubCfgContents ))), 0o644 )
618+ const state_b string = `
619+ set default=1
620+ menuentry "Previous State (A)" --class abroot-a {
621+ configfile "/abroot/%s/abroot.cfg"
622+ }
623+
624+ menuentry "Current State (B)" --class abroot-b {
625+ configfile "/abroot/%s/abroot.cfg"
626+ }
627+ `
628+
629+ configFile := ""
630+
631+ if grub .FutureRoot == "a" {
632+ configFile = preamble + fmt .Sprintf (state_a , partFuture .Label , partPresent .Label )
633+ } else {
634+ configFile = preamble + fmt .Sprintf (state_b , partFuture .Label , partPresent .Label )
697635 }
698636
637+ os .WriteFile (grubCfgFuture , []byte (configFile ), 0o644 )
638+
699639 err = AtomicSwap (grubCfgCurrent , grubCfgFuture )
700640 if err != nil {
701641 PrintVerboseErr ("ABSystem.RunOperation" , 11.3 , err )
0 commit comments