From 034ef92643ae8f79febae4cb5f61d654b970cc54 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 19 Mar 2014 10:56:24 -0400 Subject: [PATCH] Add "targetSysroot" which differs from ROOT_PATH For OSTree, the location of the OS checkout (and e.g. /etc/fstab) is really in /ostree/deploy/$osname/deploy/$revision/etc/fstab. In order to properly support OSTree, Blivet will need to gain an understanding of the separation between the physical system / and the target root. This patch will be used in Anaconda, which will set the targetSysroot attribute after the root being installed is laid out. After that, when we call write(), the fstab data will be correctly written into the target root. --- blivet/__init__.py | 50 +++++++++++++++++++++++++++----------------------- blivet/util.py | 4 ++-- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/blivet/__init__.py b/blivet/__init__.py index 068c310..9ca661e 100644 --- a/blivet/__init__.py +++ b/blivet/__init__.py @@ -31,6 +31,7 @@ __version__ = '0.18.32' ## isys = None ROOT_PATH = '/' +targetSysroot = ROOT_PATH shortProductName = 'blivet' productName = 'blivet' bootLoaderError = Exception @@ -100,6 +101,7 @@ log = logging.getLogger("blivet") def enable_installer_mode(): global isys global ROOT_PATH + global targetSysroot global shortProductName global productName global get_bootloader @@ -116,6 +118,8 @@ def enable_installer_mode(): from pyanaconda.errors import errorHandler from pyanaconda.errors import ERROR_RAISE + targetSysroot = ROOT_PATH + from pyanaconda.anaconda_log import program_log_lock util.program_log_lock = program_log_lock @@ -202,7 +206,7 @@ def writeEscrowPackets(storage): backupPassphrase = generateBackupPassphrase() try: - escrowDir = ROOT_PATH + "/root" + escrowDir = targetSysroot + "/root" log.debug("escrow: writing escrow packets to %s", escrowDir) util.makedirs(escrowDir) for device in escrowDevices: @@ -1665,22 +1669,22 @@ class Blivet(object): return list(pkgs) def write(self): - if not os.path.isdir("%s/etc" % ROOT_PATH): - os.mkdir("%s/etc" % ROOT_PATH) + if not os.path.isdir("%s/etc" % targetSysroot): + os.mkdir("%s/etc" % targetSysroot) self.fsset.write() self.makeMtab() - self.iscsi.write(ROOT_PATH, self) - self.fcoe.write(ROOT_PATH) - self.zfcp.write(ROOT_PATH) - write_dasd_conf(self.dasd, ROOT_PATH) + self.iscsi.write(targetSysroot, self) + self.fcoe.write(targetSysroot) + self.zfcp.write(targetSysroot) + write_dasd_conf(self.dasd, targetSysroot) def turnOnSwap(self, upgrading=None): - self.fsset.turnOnSwap(rootPath=ROOT_PATH, + self.fsset.turnOnSwap(rootPath=targetSysroot, upgrading=upgrading) def mountFilesystems(self, raiseErrors=None, readOnly=None, skipRoot=False): - self.fsset.mountFilesystems(rootPath=ROOT_PATH, + self.fsset.mountFilesystems(rootPath=targetSysroot, raiseErrors=raiseErrors, readOnly=readOnly, skipRoot=skipRoot) @@ -1797,7 +1801,7 @@ class Blivet(object): def makeMtab(self): path = "/etc/mtab" target = "/proc/self/mounts" - path = os.path.normpath("%s/%s" % (ROOT_PATH, path)) + path = os.path.normpath("%s/%s" % (targetSysroot, path)) if os.path.islink(path): # return early if the mtab symlink is already how we like it @@ -2130,7 +2134,7 @@ def mountExistingSystem(fsset, rootDevice, allowDirty=None, dirtyCB=None, readOnly=None): """ Mount filesystems specified in rootDevice's /etc/fstab file. """ - rootPath = ROOT_PATH + rootPath = targetSysroot if dirtyCB is None: dirtyCB = lambda l: False @@ -2172,7 +2176,7 @@ def mountExistingSystem(fsset, rootDevice, if dirtyDevs and (not allowDirty or dirtyCB(dirtyDevs)): raise DirtyFSError("\n".join(dirtyDevs)) - fsset.mountFilesystems(rootPath=ROOT_PATH, readOnly=readOnly, skipRoot=True) + fsset.mountFilesystems(rootPath=targetSysroot, readOnly=readOnly, skipRoot=True) class BlkidTab(object): @@ -2529,7 +2533,7 @@ class FSSet(object): loop mounts? """ if not chroot or not os.path.isdir(chroot): - chroot = ROOT_PATH + chroot = targetSysroot path = "%s/etc/fstab" % chroot if not os.access(path, os.R_OK): @@ -2727,10 +2731,10 @@ class FSSet(object): def mkDevRoot(self): root = self.rootDevice - dev = "%s/%s" % (ROOT_PATH, root.path) - if not os.path.exists("%s/dev/root" %(ROOT_PATH,)) and os.path.exists(dev): + dev = "%s/%s" % (targetSysroot, root.path) + if not os.path.exists("%s/dev/root" %(targetSysroot,)) and os.path.exists(dev): rdev = os.stat(dev).st_rdev - os.mknod("%s/dev/root" % (ROOT_PATH,), stat.S_IFBLK | 0600, rdev) + os.mknod("%s/dev/root" % (targetSysroot,), stat.S_IFBLK | 0600, rdev) @property def swapDevices(self): @@ -2742,7 +2746,7 @@ class FSSet(object): @property def rootDevice(self): - for path in ["/", ROOT_PATH]: + for path in ["/", ROOT_PATH, targetSysroot]: for device in self.devices: try: mountpoint = device.format.mountpoint @@ -2755,19 +2759,19 @@ class FSSet(object): def write(self): """ write out all config files based on the set of filesystems """ # /etc/fstab - fstab_path = os.path.normpath("%s/etc/fstab" % ROOT_PATH) + fstab_path = os.path.normpath("%s/etc/fstab" % targetSysroot) fstab = self.fstab() open(fstab_path, "w").write(fstab) # /etc/crypttab - crypttab_path = os.path.normpath("%s/etc/crypttab" % ROOT_PATH) + crypttab_path = os.path.normpath("%s/etc/crypttab" % targetSysroot) crypttab = self.crypttab() origmask = os.umask(0077) open(crypttab_path, "w").write(crypttab) os.umask(origmask) # /etc/mdadm.conf - mdadm_path = os.path.normpath("%s/etc/mdadm.conf" % ROOT_PATH) + mdadm_path = os.path.normpath("%s/etc/mdadm.conf" % targetSysroot) mdadm_conf = self.mdadmConf() if mdadm_conf: open(mdadm_path, "w").write(mdadm_conf) @@ -2900,11 +2904,11 @@ def getReleaseString(): relVer = None try: - relArch = util.capture_output(["arch"], root=ROOT_PATH).strip() + relArch = util.capture_output(["arch"], root=targetSysroot).strip() except: relArch = None - filename = "%s/etc/redhat-release" % ROOT_PATH + filename = "%s/etc/redhat-release" % targetSysroot if os.access(filename, os.R_OK): with open(filename) as f: try: @@ -3000,7 +3004,7 @@ class Root(object): def parseFSTab(devicetree, chroot=None): """ parse /etc/fstab and return a tuple of a mount dict and swap list """ if not chroot or not os.path.isdir(chroot): - chroot = ROOT_PATH + chroot = targetSysroot mounts = {} swaps = [] diff --git a/blivet/util.py b/blivet/util.py index d43b252..179823b 100644 --- a/blivet/util.py +++ b/blivet/util.py @@ -277,13 +277,13 @@ def makedirs(path): def copy_to_system(source): # do the import now because enable_installer_mode() has finally been called. - from . import ROOT_PATH + from . import targetSysroot if not os.access(source, os.R_OK): log.info("copy_to_system: source '%s' does not exist." % source) return False - target = ROOT_PATH + source + target = targetSysroot + source target_dir = os.path.dirname(target) log.debug("copy_to_system: '%s' -> '%s'." % (source, target)) if not os.path.isdir(target_dir): -- 1.8.3.1