85
85
lockFile string = filepath .Join ("/tmp" , "ABSystem.Upgrade.lock" )
86
86
stageFile string = filepath .Join ("/tmp" , "ABSystem.Upgrade.stage" )
87
87
userLockFile string = filepath .Join ("/tmp" , "ABSystem.Upgrade.user.lock" )
88
- mountUnitDir = "/etc/systemd/system"
89
88
90
89
// Errors
91
90
ErrNoUpdate error = errors .New ("no update available" )
@@ -135,166 +134,6 @@ func (s *ABSystem) CheckUpdate() (string, bool) {
135
134
return s .Registry .HasUpdate (s .CurImage .Digest )
136
135
}
137
136
138
- // GenerateFstab generates a fstab file for the future root
139
- func (s * ABSystem ) GenerateFstab (rootPath string , root ABRootPartition ) error {
140
- PrintVerboseInfo ("ABSystem.GenerateFstab" , "generating fstab" )
141
-
142
- template := `# /etc/fstab: static file system information.
143
- # Generated by ABRoot
144
- #
145
- # <file system> <mount point> <type> <options> <dump> <pass>
146
- UUID=%s / %s defaults 0 0
147
- /.system/usr /.system/usr none bind,ro
148
- %s /var auto defaults 0 0
149
- `
150
- varSource := ""
151
- if s .RootM .VarPartition .IsDevMapper () {
152
- varSource = fmt .Sprintf ("/dev/mapper/%s" , s .RootM .VarPartition .Device )
153
- } else {
154
- varSource = fmt .Sprintf ("UUID=%s" , s .RootM .VarPartition .Uuid )
155
- }
156
-
157
- fstab := fmt .Sprintf (
158
- template ,
159
- root .Partition .Uuid ,
160
- root .Partition .FsType ,
161
- varSource ,
162
- )
163
-
164
- err := os .WriteFile (filepath .Join (rootPath , "/etc/fstab" ), []byte (fstab ), 0o644 )
165
- if err != nil {
166
- PrintVerboseErr ("ABSystem.GenerateFstab" , 0 , err )
167
- return err
168
- }
169
-
170
- PrintVerboseInfo ("ABSystem.GenerateFstab" , "fstab generated" )
171
- return nil
172
- }
173
-
174
- // GenerateCrypttab identifies which devices are encrypted and generates
175
- // the /etc/crypttab file for the specified root
176
- func (s * ABSystem ) GenerateCrypttab (rootPath string ) error {
177
- PrintVerboseInfo ("ABSystem.GenerateCrypttab" , "generating crypttab" )
178
-
179
- cryptEntries := [][]string {}
180
-
181
- // Check for encrypted roots
182
- for _ , rootDevice := range s .RootM .Partitions {
183
- if strings .HasPrefix (rootDevice .Partition .Device , "luks-" ) {
184
- parent := rootDevice .Partition .Parent
185
- PrintVerboseInfo ("ABSystem.GenerateCrypttab" , "Adding" , parent .Device , "to crypttab" )
186
-
187
- cryptEntries = append (cryptEntries , []string {
188
- fmt .Sprintf ("luks-%s" , parent .Uuid ),
189
- fmt .Sprintf ("UUID=%s" , parent .Uuid ),
190
- "none" ,
191
- "luks,discard" ,
192
- })
193
- }
194
- }
195
-
196
- // Check for encrypted /var
197
- if strings .HasPrefix (s .RootM .VarPartition .Device , "luks-" ) {
198
- parent := s .RootM .VarPartition .Parent
199
- PrintVerboseInfo ("ABSystem.GenerateCrypttab" , "Adding" , parent .Device , "to crypttab" )
200
-
201
- cryptEntries = append (cryptEntries , []string {
202
- fmt .Sprintf ("luks-%s" , parent .Uuid ),
203
- fmt .Sprintf ("UUID=%s" , parent .Uuid ),
204
- "none" ,
205
- "luks,discard" ,
206
- })
207
- }
208
-
209
- crypttabContent := ""
210
- for _ , entry := range cryptEntries {
211
- fmtEntry := strings .Join (entry , " " )
212
- crypttabContent += fmtEntry + "\n "
213
- }
214
-
215
- err := os .WriteFile (rootPath + "/etc/crypttab" , []byte (crypttabContent ), 0o644 )
216
- if err != nil {
217
- PrintVerboseErr ("ABSystem.GenerateCrypttab" , 3 , err )
218
- return err
219
- }
220
-
221
- return nil
222
- }
223
-
224
- // GenerateSystemdUnits generates systemd units that mount the mutable parts
225
- // of the system to their respective mountpoints
226
- func (s * ABSystem ) GenerateSystemdUnits (rootPath string , root ABRootPartition ) error {
227
- PrintVerboseInfo ("ABSystem.GenerateSystemdUnits" , "generating units" )
228
-
229
- extraDepends := ""
230
- if root .Partition .IsEncrypted () || s .RootM .VarPartition .IsEncrypted () {
231
- extraDepends = "cryptsetup.target"
232
- }
233
-
234
- type varmount struct {
235
- source string
236
- destination string
237
- fsType string
238
- options string
239
- }
240
-
241
- mounts := []varmount {
242
- {"/var/home" , "/home" , "none" , "bind" },
243
- {"/var/opt" , "/opt" , "none" , "bind" },
244
- {"overlay" , "/.system/etc" , "overlay" , "lowerdir=/.system/etc,upperdir=/var/lib/abroot/etc/" + root .Label + ",workdir=/var/lib/abroot/etc/" + root .Label + "-work" },
245
- }
246
-
247
- afterVarTemplate := `[Unit]
248
- Description=Mounts %s from var
249
- After=local-fs-pre.target %s
250
- Before=local-fs.target nss-user-lookup.target
251
- RequiresMountsFor=/var
252
-
253
- [Mount]
254
- What=%s
255
- Where=%s
256
- Type=%s
257
- Options=%s
258
- `
259
-
260
- for _ , mount := range mounts {
261
- PrintVerboseInfo ("ABSystem.GenerateSystemdUnits" , "generating unit for" , mount .destination )
262
-
263
- unit := fmt .Sprintf (afterVarTemplate , mount .destination , extraDepends , mount .source , mount .destination , mount .fsType , mount .options )
264
-
265
- // the unit file needs to have the escaped mount point as its name
266
- out , err := exec .Command ("systemd-escape" , "--path" , mount .destination ).Output ()
267
- if err != nil {
268
- PrintVerboseErr ("ABSystem.GenerateSystemdUnits" , 0 , "failed to determine escaped path" , err )
269
- return err
270
- }
271
- mountUnitFile := "/" + strings .ReplaceAll (string (out ), "\n " , "" ) + ".mount"
272
-
273
- err = os .WriteFile (filepath .Join (rootPath , mountUnitDir , mountUnitFile ), []byte (unit ), 0o644 )
274
- if err != nil {
275
- PrintVerboseErr ("ABSystem.GenerateSystemdUnits" , 1 , err )
276
- return err
277
- }
278
-
279
- const targetRequires string = "/local-fs-pre.target.requires"
280
-
281
- err = os .MkdirAll (filepath .Join (rootPath , mountUnitDir , targetRequires ), 0o755 )
282
- if err != nil {
283
- PrintVerboseErr ("ABSystem.GenerateSystemdUnits" , 2 , err )
284
- return err
285
- }
286
-
287
- err = os .Symlink (filepath .Join ("../" , mountUnitFile ), filepath .Join (rootPath , mountUnitDir , targetRequires , mountUnitFile ))
288
- if err != nil {
289
- PrintVerboseErr ("ABSystem.GenerateSystemdUnits" , 3 , "failed to create symlink" , err )
290
- return err
291
- }
292
- }
293
-
294
- PrintVerboseInfo ("ABSystem.GenerateSystemdUnits" , "units generated" )
295
- return nil
296
- }
297
-
298
137
func (s * ABSystem ) CreateRootSymlinks (systemNewPath string ) error {
299
138
PrintVerboseInfo ("ABSystem.CreateRootSymlinks" , "creating symlinks" )
300
139
links := []string {"mnt" , "proc" , "run" , "dev" , "media" , "root" , "sys" , "tmp" , "var" }
@@ -602,29 +441,6 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
602
441
return err
603
442
}
604
443
605
- // Stage 6: Generate /etc/fstab, /etc/crypttab, and the
606
- // SystemD units to setup mountpoints
607
- // ------------------------------------------------
608
- PrintVerboseSimple ("[Stage 6] -------- ABSystemRunOperation" )
609
-
610
- err = s .GenerateFstab (systemNew , partFuture )
611
- if err != nil {
612
- PrintVerboseErr ("ABSystem.RunOperation" , 6 , err )
613
- return err
614
- }
615
-
616
- err = s .GenerateCrypttab (systemNew )
617
- if err != nil {
618
- PrintVerboseErr ("ABSystem.RunOperation" , 6.1 , err )
619
- return err
620
- }
621
-
622
- err = s .GenerateSystemdUnits (systemNew , partFuture )
623
- if err != nil {
624
- PrintVerboseErr ("ABSystem.RunOperation" , 6.2 , "Failed to Generate SystemdUnits" , err )
625
- return err
626
- }
627
-
628
444
// Stage (dry): If dry-run, exit here before writing to disk
629
445
// ------------------------------------------------
630
446
switch operation {
@@ -633,9 +449,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
633
449
return nil
634
450
}
635
451
636
- // Stage 7 : Update the bootloader
452
+ // Stage 6 : Update the bootloader
637
453
// ------------------------------------------------
638
- PrintVerboseSimple ("[Stage 7 ] -------- ABSystemRunOperation" )
454
+ PrintVerboseSimple ("[Stage 6 ] -------- ABSystemRunOperation" )
639
455
640
456
partPresent , err := s .RootM .GetPresent ()
641
457
if err != nil {
@@ -762,9 +578,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
762
578
return err
763
579
}
764
580
765
- // Stage 8 : Sync /etc
581
+ // Stage 7 : Sync /etc
766
582
// ------------------------------------------------
767
- PrintVerboseSimple ("[Stage 8 ] -------- ABSystemRunOperation" )
583
+ PrintVerboseSimple ("[Stage 7 ] -------- ABSystemRunOperation" )
768
584
769
585
oldEtc := "/.system/sysconf" // The current etc WITHOUT anything overlayed
770
586
presentEtc , err := s .RootM .GetPresent ()
@@ -786,9 +602,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
786
602
return err
787
603
}
788
604
789
- // Stage 9 : Mount boot partition
605
+ // Stage 8 : Mount boot partition
790
606
// ------------------------------------------------
791
- PrintVerboseSimple ("[Stage 9 ] -------- ABSystemRunOperation" )
607
+ PrintVerboseSimple ("[Stage 8 ] -------- ABSystemRunOperation" )
792
608
793
609
uuid := uuid .New ().String ()
794
610
tmpBootMount := filepath .Join ("/tmp" , uuid )
@@ -808,9 +624,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
808
624
return partBoot .Unmount ()
809
625
}, nil , 100 , & goodies.NoErrorHandler {}, false )
810
626
811
- // Stage 10 : Atomic swap the rootfs and abimage.abr
627
+ // Stage 9 : Atomic swap the rootfs and abimage.abr
812
628
// ------------------------------------------------
813
- PrintVerboseSimple ("[Stage 10 ] -------- ABSystemRunOperation" )
629
+ PrintVerboseSimple ("[Stage 9 ] -------- ABSystemRunOperation" )
814
630
815
631
err = AtomicSwap (systemOld , systemNew )
816
632
if err != nil {
@@ -842,9 +658,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
842
658
return os .RemoveAll (newABImage )
843
659
}, nil , 30 , & goodies.NoErrorHandler {}, false )
844
660
845
- // Stage 11 : Atomic swap the bootloader
661
+ // Stage 10 : Atomic swap the bootloader
846
662
// ------------------------------------------------
847
- PrintVerboseSimple ("[Stage 11 ] -------- ABSystemRunOperation" )
663
+ PrintVerboseSimple ("[Stage 10 ] -------- ABSystemRunOperation" )
848
664
849
665
grub , err := NewGrub (partBoot )
850
666
if err != nil {
@@ -862,7 +678,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
862
678
grubCfgCurrent := filepath .Join (tmpBootMount , "grub/grub.cfg" )
863
679
grubCfgFuture := filepath .Join (tmpBootMount , "grub/grub.cfg.future" )
864
680
865
- // Just like in Stage 10 , tmpBootMount/grub/grub.cfg.future may not exist.
681
+ // Just like in Stage 9 , tmpBootMount/grub/grub.cfg.future may not exist.
866
682
if _ , err = os .Stat (grubCfgFuture ); os .IsNotExist (err ) {
867
683
PrintVerboseInfo ("ABSystem.RunOperation" , "Creating grub.cfg.future" )
868
684
@@ -897,7 +713,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
897
713
}
898
714
}
899
715
900
- // Stage 12 : Cleanup old kernel images
716
+ // Stage 11 : Cleanup old kernel images
901
717
// ------------------------------------------------
902
718
// If Thin-Provisioning set, we have to remove the old kernel images
903
719
// from the init partition since it is too small to hold multiple kernels.
@@ -907,7 +723,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
907
723
switch operation {
908
724
case DRY_RUN_UPGRADE , DRY_RUN_APPLY , DRY_RUN_INITRAMFS :
909
725
default :
910
- PrintVerboseSimple ("[Stage 12 ] -------- ABSystemRunOperation" )
726
+ PrintVerboseSimple ("[Stage 11 ] -------- ABSystemRunOperation" )
911
727
912
728
// since we did the swap, the init partition is now mounted in
913
729
// .system instead of .system.new, so we need to update the path
@@ -997,7 +813,7 @@ func (s *ABSystem) Rollback(checkOnly bool) (response ABRollbackResponse, err er
997
813
grubCfgCurrent := filepath .Join (tmpBootMount , "grub/grub.cfg" )
998
814
grubCfgFuture := filepath .Join (tmpBootMount , "grub/grub.cfg.future" )
999
815
1000
- // Just like in Stage 10 , tmpBootMount/grub/grub.cfg.future may not exist.
816
+ // Just like in Stage 9 , tmpBootMount/grub/grub.cfg.future may not exist.
1001
817
if _ , err = os .Stat (grubCfgFuture ); os .IsNotExist (err ) {
1002
818
PrintVerboseInfo ("ABSystem.Rollback" , "Creating grub.cfg.future" )
1003
819
0 commit comments