From: David Lehman dlehman@redhat.com
Related: rhbz#1113207 --- blivet/autopart.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
diff --git a/blivet/autopart.py b/blivet/autopart.py index 1359ba0..206e179 100644 --- a/blivet/autopart.py +++ b/blivet/autopart.py @@ -25,8 +25,10 @@
from . import util from .size import Size +from .devices.btrfs import BTRFSSnapShotDevice from .devices.partition import PartitionDevice, FALLBACK_DEFAULT_PART_SIZE from .devices.luks import LUKSDevice +from .devices.lvm import LVMThinSnapShotDevice from .errors import NoDisksError, NotEnoughFreeSpaceError from .formats import getFormat from .partitioning import doPartitioning, getFreeRegions, growLVM @@ -509,3 +511,42 @@ def doAutoPartition(storage, data, min_luks_entropy=0): # only newly added swaps should appear in the fstab new_swaps = (dev for dev in storage.swaps if not dev.format.exists) storage.setFstabSwaps(new_swaps) + +def setUpRootSnapShot(storage): + """ Snapshot the root device and remount with the snapshot as root. """ + log.info("makeRootThinPSnapShot: autopart type is %s", storage.autoPartType) + try: + make_snapshot = (storage.ksdata.autopart.autopart and + storage.ksdata.autopart.snapshot) + except AttributeError: + make_snapshot = False + + if not make_snapshot: + return + + # set up the snapshot + root = storage.rootDevice + parent = getattr(root, "pool", root.container) + name = storage.suggestDeviceName(parent=parent, prefix="rootsnap") + + if storage.ksdata.autopart.type == AUTOPART_TYPE_BTRFS: + snapshot = BTRFSSnapShotDevice(name, parents=[parent], source=root) + elif storage.ksdata.autopart.type == AUTOPART_TYPE_LVM_THINP: + snapshot = LVMThinSnapShotDevice(name, parents=[parent], origin=root) + else: + log.error("invalid autopart type for root snapshot: %s", + storage.ksdata.autopart.type) + return + + # create the snapshot + storage.createDevice(snapshot) + storage.devicetree.processActions() + + # remount the system with the snapshot as the root device + storage.umountFilesystems() + + root.format.mountpoint = "" + snapshot.format.mountpoint = "/" + + storage.write() + storage.mountFilesystems()