Пример #1
0
def test_list_partitions():
    """
    List disk partitions
    """

    from fabtools.disk import partitions

    partitions = partitions()
    for pname, ptype in partitions.items():
        puts("%s is %s" % (pname, hex(ptype)))
Пример #2
0
def require_partition():
    """
    Check if all partitions type exist and format
    """
    spart = {'Linux': 0x83, 'Swap': 0x82}
    p = disk.partitions(device=env.disk)
    r = p[env.part['/boot']['device']] == spart['Linux']
    r = r and p[env.part['swap']['device']] == spart['Swap']
    r = r and p[env.part['lvm']['device']] == spart['Linux']

    if not r:
        abort("can't continue, not found require partitions")

    # Format partition
    r = prompt(red('Please Confirm you wan (re)-format with Y'))
    if r != "Y":
        abort("You do not want to continue :)")

    # disk.mkfs(env.part['/']['device'], env.part['/']['ftype'])

    # Prepare system partition
    disk.mkfs(env.part['/boot']['device'], env.part['/boot']['ftype'])
    disk.mkswap(env.part['swap']['device'])

    # Initialize lvm parition
    run_as_root('pvcreate -yff -Z y %s' % env.part['lvm']['device'])
    run_as_root('vgcreate -yff -Z y vg %s' % env.part['lvm']['device'])

    # Create partition
    run_as_root('lvcreate -n %s -L %s' %
                (env.part['/']['device'], env.part['/']['size']))
    run_as_root('lvcreate -n %s -L %s' %
                (env.part['/home']['device'], env.part['/home']['size']))

    # Format root on LVM
    disk.mkfs(env.part['/']['device'], env.part['/']['ftype'])

    # Format home on LVM
    print(red('Encrypt home partition, manual intervention needed'))
    run_as_root('cryptsetup luksFormat %s' % env.part['/home']['device'])

    print(red('Open home partition, manual intervention needed'))
    run_as_root('cryptsetup luksOpen %s home' % env.part['/home']['device'])
    disk.mkfs('/dev/mapper/home', env.part['/home']['ftype'])
    run_as_root('tune2fs -m 0 /dev/mapper/home')
Пример #3
0
def require_partition():
    """
    Check if all partitions type exist and format
    """
    spart = {'Linux': 0x83, 'Swap': 0x82}
    p = disk.partitions(device=env.disk)
    r = p[env.part['/boot']['device']] == spart['Linux']
    r = r and p[env.part['swap']['device']] == spart['Swap']
    r = r and p[env.part['lvm']['device']] == spart['Linux']

    if not r:
        abort("can't continue, not found require partitions")

    # Format partition
    r = prompt(red('Please Confirm you wan (re)-format with Y'))
    if r != "Y":
        abort("You do not want to continue :)")

    # disk.mkfs(env.part['/']['device'], env.part['/']['ftype'])

    # Prepare system partition
    disk.mkfs(env.part['/boot']['device'], env.part['/boot']['ftype'])
    disk.mkswap(env.part['swap']['device'])

    # Initialize lvm parition
    run_as_root('pvcreate -yff -Z y %s' % env.part['lvm']['device'])
    run_as_root('vgcreate -yff -Z y vg %s' % env.part['lvm']['device'])

    # Create partition
    run_as_root('lvcreate -n %s -L %s' %
                (env.part['/']['device'], env.part['/']['size']))
    run_as_root('lvcreate -n %s -L %s' %
                (env.part['/home']['device'], env.part['/home']['size']))

    # Format root on LVM
    disk.mkfs(env.part['/']['device'], env.part['/']['ftype'])

    # Format home on LVM
    print(red('Encrypt home partition, manual intervention needed'))
    run_as_root('cryptsetup luksFormat %s' % env.part['/home']['device'])

    print(red('Open home partition, manual intervention needed'))
    run_as_root('cryptsetup luksOpen %s home' % env.part['/home']['device'])
    disk.mkfs('/dev/mapper/home', env.part['/home']['ftype'])
    run_as_root('tune2fs -m 0 /dev/mapper/home')
Пример #4
0
def init_crypted_zfs(device, partitionID, pool_name):
    """
    Prepare a crypted ZFS disk
    ex:
      fab init_crypted_zfs:/dev/sdb,1,backup
    """
    if not env.host_string:
        env.host_string = 'localhost'

    # Check a first partition is in Solaris (for security format)
    ptype = disk.partitions(device)
    partition = '%s%s' % (device, partitionID)
    if ptype[partition] != 0xBF:
        abort("The first partition is not SOLARIS type (0xBF)")

    # Prepare a crypted ZFS disk
    uppername = pool_name.upper()
    sudo('cryptsetup luksFormat -c aes-xts-plain64 -s 512 %s' % partition)
    sudo('cryptsetup luksOpen %s LUKS-%s' % (partition, uppername))
    sudo('zpool create %s /dev/mapper/LUKS-%s' % (uppername, uppername))
    sudo('zfs set compress=on %s' % uppername)
Пример #5
0
def init_crypted_zfs(device, partitionID, pool_name):
    """
    Prepare a crypted ZFS disk
    ex:
      fab init_crypted_zfs:/dev/sdb,1,backup
    """
    if not env.host_string:
        env.host_string = 'localhost'

    # Check a first partition is in Solaris (for security format)
    ptype = disk.partitions(device)
    partition = '%s%s' % (device, partitionID)
    if ptype[partition] != 0xBF:
        abort("The first partition is not SOLARIS type (0xBF)")

    # Prepare a crypted ZFS disk
    uppername = pool_name.upper()
    sudo('cryptsetup luksFormat -c aes-xts-plain64 -s 512 %s' % partition)
    sudo('cryptsetup luksOpen %s LUKS-%s' % (partition, uppername))
    sudo('zpool create %s /dev/mapper/LUKS-%s' % (uppername, uppername))
    sudo('zfs set compress=on %s' % uppername)