@@ -531,83 +531,30 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
531531 return err
532532 }
533533
534- var rootUuid string
535- // If Thin-Provisioning set, mount init partition and move linux and initrd
536- // images to it.
537- var initMountpoint string
538- if settings .Cnf .ThinProvisioning {
539- initPartition , err := s .RootM .GetInit ()
540- if err != nil {
541- PrintVerboseErr ("ABSystem.RunOperation" , 7.3 , err )
542- return err
543- }
544-
545- initMountpoint = filepath .Join (systemNew , "boot" , "init" )
546- err = initPartition .Mount (initMountpoint )
547- if err != nil {
548- PrintVerboseErr ("ABSystem.RunOperation" , 7.4 , err )
549- return err
550- }
551-
552- cq .Add (func (args ... interface {}) error {
553- return initPartition .Unmount ()
554- }, nil , 80 , & goodies.NoErrorHandler {}, false )
555-
556- futureInitDir := filepath .Join (initMountpoint , partFuture .Label )
557-
558- err = os .RemoveAll (futureInitDir )
559- if err != nil {
560- PrintVerboseWarn ("ABSystem.RunOperation" , 7.44 )
561- }
562- err = os .MkdirAll (futureInitDir , 0o755 )
563- if err != nil {
564- PrintVerboseWarn ("ABSystem.RunOperation" , 7.47 , err )
565- }
566-
567- err = MoveFile (
568- filepath .Join (systemNew , "boot" , "vmlinuz-" + newKernelVer ),
569- filepath .Join (futureInitDir , "vmlinuz-" + newKernelVer ),
570- )
571- if err != nil {
572- PrintVerboseErr ("ABSystem.RunOperation" , 7.5 , err )
573- return err
574- }
575- err = MoveFile (
576- filepath .Join (systemNew , "boot" , "initrd.img-" + newKernelVer ),
577- filepath .Join (futureInitDir , "initrd.img-" + newKernelVer ),
578- )
579- if err != nil {
580- PrintVerboseErr ("ABSystem.RunOperation" , 7.6 , err )
581- return err
582- }
583- err = MoveFile (
584- filepath .Join (systemNew , "boot" , "config-" + newKernelVer ),
585- filepath .Join (futureInitDir , "config-" + newKernelVer ),
586- )
587- if err != nil {
588- PrintVerboseErr ("ABSystem.RunOperation" , 7.7 , err )
589- return err
590- }
591- err = MoveFile (
592- filepath .Join (systemNew , "boot" , "System.map-" + newKernelVer ),
593- filepath .Join (futureInitDir , "System.map-" + newKernelVer ),
594- )
595- if err != nil {
596- PrintVerboseErr ("ABSystem.RunOperation" , 7.8 , err )
597- return err
598- }
534+ tmpBootMount := "/run/abroot/tmp-boot-mount-1/"
535+ err = os .MkdirAll (tmpBootMount , 0o755 )
536+ if err != nil {
537+ PrintVerboseErr ("ABSystem.RunOperation" , 9 , err )
538+ return err
539+ }
599540
600- rootUuid = initPartition .Uuid
601- } else {
602- rootUuid = partFuture .Partition .Uuid
541+ err = partBoot .Mount (tmpBootMount )
542+ if err != nil {
543+ PrintVerboseErr ("ABSystem.RunOperation" , 9.1 , err )
544+ return err
603545 }
604546
605- err = generateABGrubConf (
547+ cq .Add (func (args ... interface {}) error {
548+ return partBoot .Unmount ()
549+ }, nil , 100 , & goodies.NoErrorHandler {}, false )
550+
551+ err = createABSpecificGrub (
606552 newKernelVer ,
607- systemNew ,
608- rootUuid ,
553+ partFuture .Partition .Uuid ,
609554 partFuture .Label ,
610- generatedGrubConfigPath ,
555+ filepath .Join (systemNew , generatedGrubConfigPath ),
556+ tmpBootMount ,
557+ filepath .Join (systemNew , "/boot/" ),
611558 )
612559 if err != nil {
613560 PrintVerboseErr ("ABSystem.RunOperation" , 7.9 , err )
@@ -633,31 +580,10 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
633580 return err
634581 }
635582
636- // Stage 8: Mount boot partition
583+ // Stage 8: Apply the new rootfs
637584 // ------------------------------------------------
638585 PrintVerboseSimple ("[Stage 8] -------- ABSystemRunOperation" )
639586
640- tmpBootMount := "/run/abroot/tmp-boot-mount-1/"
641- err = os .MkdirAll (tmpBootMount , 0o755 )
642- if err != nil {
643- PrintVerboseErr ("ABSystem.RunOperation" , 9 , err )
644- return err
645- }
646-
647- err = partBoot .Mount (tmpBootMount )
648- if err != nil {
649- PrintVerboseErr ("ABSystem.RunOperation" , 9.1 , err )
650- return err
651- }
652-
653- cq .Add (func (args ... interface {}) error {
654- return partBoot .Unmount ()
655- }, nil , 100 , & goodies.NoErrorHandler {}, false )
656-
657- // Stage 9: Apply the new rootfs
658- // ------------------------------------------------
659- PrintVerboseSimple ("[Stage 9] -------- ABSystemRunOperation" )
660-
661587 err = ClearDirectory (partFuture .Partition .MountPoint , []string {"new" })
662588 if err != nil {
663589 PrintVerboseErr ("ABSystem.RunOperation" , 10.1 , err )
@@ -687,9 +613,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
687613 return err
688614 }
689615
690- // Stage 10 : Atomic swap the bootloader
616+ // Stage 9 : Atomic swap the bootloader
691617 // ------------------------------------------------
692- PrintVerboseSimple ("[Stage 10 ] -------- ABSystemRunOperation" )
618+ PrintVerboseSimple ("[Stage 9 ] -------- ABSystemRunOperation" )
693619
694620 grub , err := NewGrub (partBoot )
695621 if err != nil {
@@ -707,34 +633,53 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation, freeSpace bool) err
707633 grubCfgCurrent := filepath .Join (tmpBootMount , "grub/grub.cfg" )
708634 grubCfgFuture := filepath .Join (tmpBootMount , "grub/grub.cfg.future" )
709635
710- // Just like in Stage 9, tmpBootMount/grub/grub.cfg.future may not exist.
711- if _ , err = os .Stat (grubCfgFuture ); os .IsNotExist (err ) {
712- PrintVerboseInfo ("ABSystem.RunOperation" , "Creating grub.cfg.future" )
636+ _ = os .Remove (grubCfgFuture )
713637
714- grubCfgContents , err := os .ReadFile (grubCfgCurrent )
715- if err != nil {
716- PrintVerboseErr ("ABSystem.RunOperation" , 11.2 , err )
717- }
638+ const preamble string = `set timeout=5
718639
719- var replacerPairs []string
720- if grub .FutureRoot == "a" {
721- replacerPairs = []string {
722- "default=1" , "default=0" ,
723- "Previous State (A)" , "Current State (A)" ,
724- "Current State (B)" , "Previous State (B)" ,
725- }
726- } else {
727- replacerPairs = []string {
728- "default=0" , "default=1" ,
729- "Current State (A)" , "Previous State (A)" ,
730- "Previous State (B)" , "Current State (B)" ,
731- }
732- }
640+ # Load video support
641+ insmod gfxterm
642+ insmod all_video
643+
644+ # Set graphics mode
645+ set gfxmode=1024x768,auto
646+ terminal_output gfxterm
647+
648+ `
649+
650+ const state_a string = `
651+ set default=0
652+
653+ menuentry "Current State (A)" --class abroot-a {
654+ configfile "/abroot/%s/abroot.cfg"
655+ }
733656
734- replacer := strings .NewReplacer (replacerPairs ... )
735- os .WriteFile (grubCfgFuture , []byte (replacer .Replace (string (grubCfgContents ))), 0o644 )
657+ menuentry "Previous State (B)" --class abroot-b {
658+ configfile "/abroot/%s/abroot.cfg"
659+ }
660+ `
661+
662+ const state_b string = `
663+ set default=1
664+ menuentry "Previous State (A)" --class abroot-a {
665+ configfile "/abroot/%s/abroot.cfg"
666+ }
667+
668+ menuentry "Current State (B)" --class abroot-b {
669+ configfile "/abroot/%s/abroot.cfg"
670+ }
671+ `
672+
673+ configFile := ""
674+
675+ if grub .FutureRoot == "a" {
676+ configFile = preamble + fmt .Sprintf (state_a , partFuture .Label , partPresent .Label )
677+ } else {
678+ configFile = preamble + fmt .Sprintf (state_b , partFuture .Label , partPresent .Label )
736679 }
737680
681+ os .WriteFile (grubCfgFuture , []byte (configFile ), 0o644 )
682+
738683 err = AtomicSwap (grubCfgCurrent , grubCfgFuture )
739684 if err != nil {
740685 PrintVerboseErr ("ABSystem.RunOperation" , 11.3 , err )
0 commit comments