github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/boot/debug.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2019 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package boot 21 22 import ( 23 "fmt" 24 "io" 25 26 "github.com/snapcore/snapd/bootloader" 27 ) 28 29 // DumpBootVars writes a dump of the snapd bootvars to the given writer 30 func DumpBootVars(w io.Writer, dir string, uc20 bool) error { 31 bloader, err := bootloader.Find(dir, nil) 32 if err != nil { 33 return err 34 } 35 var allKeys []string 36 if uc20 { 37 // TODO:UC20: what about snapd_recovery_kernel, snapd_recovery_mode, and 38 // snapd_recovery_system? 39 allKeys = []string{"kernel_status"} 40 } else { 41 allKeys = []string{ 42 "snap_mode", 43 "snap_core", 44 "snap_try_core", 45 "snap_kernel", 46 "snap_try_kernel", 47 } 48 } 49 50 bootVars, err := bloader.GetBootVars(allKeys...) 51 if err != nil { 52 return err 53 } 54 for _, k := range allKeys { 55 fmt.Fprintf(w, "%s=%s\n", k, bootVars[k]) 56 } 57 return nil 58 }