github.com/stolowski/snapd@v0.0.0-20210407085831-115137ce5a22/boot/initramfs20dirs.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2020 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 "path/filepath" 24 25 "github.com/snapcore/snapd/dirs" 26 ) 27 28 var ( 29 // InitramfsRunMntDir is the directory where ubuntu partitions are mounted 30 // during the initramfs. 31 InitramfsRunMntDir string 32 33 // InitramfsDataDir is the location of system-data role partition 34 // (typically a partition labeled "ubuntu-data") during the initramfs. 35 InitramfsDataDir string 36 37 // InitramfsHostUbuntuDataDir is the location of the host ubuntu-data 38 // during the initramfs, typically used in recover mode. 39 InitramfsHostUbuntuDataDir string 40 41 // InitramfsHostWritableDir is the location of the host writable 42 // partition during the initramfs, typically used in recover mode. 43 InitramfsHostWritableDir string 44 45 // InitramfsUbuntuBootDir is the location of ubuntu-boot during the 46 // initramfs. 47 InitramfsUbuntuBootDir string 48 49 // InitramfsUbuntuSeedDir is the location of ubuntu-seed during the 50 // initramfs. 51 InitramfsUbuntuSeedDir string 52 53 // InitramfsUbuntuSaveDir is the location of ubuntu-save during the 54 // initramfs. 55 InitramfsUbuntuSaveDir string 56 57 // InitramfsWritableDir is the location of the writable partition during the 58 // initramfs. Note that this may refer to a temporary filesystem or a 59 // physical partition depending on what system mode the system is in. 60 InitramfsWritableDir string 61 62 // InstallHostWritableDir is the location of the writable partition of the 63 // installed host during install mode. This should always be on a physical 64 // partition. 65 InstallHostWritableDir string 66 67 // InstallHostFDEDataDir is the location of the FDE data during install mode. 68 InstallHostFDEDataDir string 69 70 // InstallHostFDESaveDir is the directory of the FDE data on the 71 // ubuntu-save partition during install mode. For other modes, 72 // use dirs.SnapSaveFDEDirUnder(). 73 InstallHostFDESaveDir string 74 75 // InitramfsSeedEncryptionKeyDir is the location of the encrypted partition 76 // keys during the initramfs on ubuntu-seed. 77 InitramfsSeedEncryptionKeyDir string 78 79 // InitramfsBootEncryptionKeyDir is the location of the encrypted partition 80 // keys during the initramfs on ubuntu-boot. 81 InitramfsBootEncryptionKeyDir string 82 ) 83 84 func setInitramfsDirVars(rootdir string) { 85 InitramfsRunMntDir = filepath.Join(rootdir, "run/mnt") 86 InitramfsDataDir = filepath.Join(InitramfsRunMntDir, "data") 87 InitramfsHostUbuntuDataDir = filepath.Join(InitramfsRunMntDir, "host", "ubuntu-data") 88 InitramfsHostWritableDir = filepath.Join(InitramfsHostUbuntuDataDir, "system-data") 89 InitramfsUbuntuBootDir = filepath.Join(InitramfsRunMntDir, "ubuntu-boot") 90 InitramfsUbuntuSeedDir = filepath.Join(InitramfsRunMntDir, "ubuntu-seed") 91 InitramfsUbuntuSaveDir = filepath.Join(InitramfsRunMntDir, "ubuntu-save") 92 InstallHostWritableDir = filepath.Join(InitramfsRunMntDir, "ubuntu-data", "system-data") 93 InstallHostFDEDataDir = dirs.SnapFDEDirUnder(InstallHostWritableDir) 94 InstallHostFDESaveDir = filepath.Join(InitramfsUbuntuSaveDir, "device/fde") 95 InitramfsWritableDir = filepath.Join(InitramfsDataDir, "system-data") 96 InitramfsSeedEncryptionKeyDir = filepath.Join(InitramfsUbuntuSeedDir, "device/fde") 97 InitramfsBootEncryptionKeyDir = filepath.Join(InitramfsUbuntuBootDir, "device/fde") 98 } 99 100 func init() { 101 setInitramfsDirVars(dirs.GlobalRootDir) 102 // register to change the values of Initramfs* dir values when the global 103 // root dir changes 104 dirs.AddRootDirCallback(setInitramfsDirVars) 105 }