github.com/anonymouse64/snapd@v0.0.0-20210824153203-04c4c42d842d/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  	// snapBootFlagsFile is the location of the file that is used
    84  	// internally for saving the current boot flags active for this boot.
    85  	snapBootFlagsFile string
    86  )
    87  
    88  func setInitramfsDirVars(rootdir string) {
    89  	InitramfsRunMntDir = filepath.Join(rootdir, "run/mnt")
    90  	InitramfsDataDir = filepath.Join(InitramfsRunMntDir, "data")
    91  	InitramfsHostUbuntuDataDir = filepath.Join(InitramfsRunMntDir, "host", "ubuntu-data")
    92  	InitramfsHostWritableDir = filepath.Join(InitramfsHostUbuntuDataDir, "system-data")
    93  	InitramfsUbuntuBootDir = filepath.Join(InitramfsRunMntDir, "ubuntu-boot")
    94  	InitramfsUbuntuSeedDir = filepath.Join(InitramfsRunMntDir, "ubuntu-seed")
    95  	InitramfsUbuntuSaveDir = filepath.Join(InitramfsRunMntDir, "ubuntu-save")
    96  	InstallHostWritableDir = filepath.Join(InitramfsRunMntDir, "ubuntu-data", "system-data")
    97  	InstallHostFDEDataDir = dirs.SnapFDEDirUnder(InstallHostWritableDir)
    98  	InstallHostFDESaveDir = filepath.Join(InitramfsUbuntuSaveDir, "device/fde")
    99  	InitramfsWritableDir = filepath.Join(InitramfsDataDir, "system-data")
   100  	InitramfsSeedEncryptionKeyDir = filepath.Join(InitramfsUbuntuSeedDir, "device/fde")
   101  	InitramfsBootEncryptionKeyDir = filepath.Join(InitramfsUbuntuBootDir, "device/fde")
   102  
   103  	snapBootFlagsFile = filepath.Join(dirs.SnapRunDir, "boot-flags")
   104  }
   105  
   106  func init() {
   107  	setInitramfsDirVars(dirs.GlobalRootDir)
   108  	// register to change the values of Initramfs* dir values when the global
   109  	// root dir changes
   110  	dirs.AddRootDirCallback(setInitramfsDirVars)
   111  }