Created
March 25, 2020 15:04
-
-
Save fepitre/a6f450c225077d786d589a13b9d0d11d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import blivet | |
from blivet.size import Size | |
from blivet.util import set_up_logging, create_sparse_tempfile | |
set_up_logging() | |
b = blivet.Blivet() # create an instance of Blivet (don't add system devices) | |
# create a disk image file on which to create new devices | |
disk1_file = create_sparse_tempfile("disk1", Size("100GiB")) | |
b.disk_images["disk1"] = disk1_file | |
b.reset() | |
try: | |
disk1 = b.devicetree.get_device_by_name("disk1") | |
b.initialize_disk(disk1) | |
pv = b.new_partition(size=Size("1GiB"), grow=True, fmt_type="lvmpv") | |
b.create_device(pv) | |
# allocate the partitions (decide where and on which disks they'll reside) | |
blivet.partitioning.do_partitioning(b) | |
vg = b.new_vg(parents=[pv]) | |
b.create_device(vg) | |
# pool root | |
pool00 = b.new_lv(parents=[vg], thin_pool=True, size=Size("16GiB"), grow=False) | |
b.create_device(pool00) | |
root = b.new_lv(parents=[pool00], thin_volume=True, name="root", size=Size("1GiB"), grow=True, fmt_type="ext4") | |
b.create_device(root) | |
# new lv with a fixed size of 2GiB formatted as swap space | |
swap = b.new_lv(fmt_type="swap", size=Size("2GiB"), parents=[vg]) | |
b.create_device(swap) | |
# pool vm | |
pool01 = b.new_lv(parents=[vg], thin_pool=True, grow=True, size=Size("1GiB")) | |
b.create_device(pool01) | |
# allocate the growable lvs | |
blivet.partitioning.grow_lvm(b) | |
print(b.devicetree) | |
# write the new partitions to disk and format them as specified | |
b.do_it() | |
print(b.devicetree) | |
finally: | |
b.devicetree.teardown_disk_images() | |
os.unlink(disk1_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment