# salt.modules.parted_partition

Module for managing partitions on POSIX-like systems.

depends:

  - parted, partprobe, lsblk (usually parted and util-linux packages)

Some functions may not be available, depending on your version of parted.

Check the manpage for `parted(8)` for more information, or the online docs at:

http://www.gnu.org/software/parted/manual/html_chapter/parted_2.html

In light of parted not directly supporting partition IDs, some of this module has been written to utilize sfdisk instead. For further information, please reference the man page for `sfdisk(8)`.

salt.modules.parted_partition.align_check(device, part_type, partition)

  Check if partition satisfies the alignment constraint of part_type. Type must be "minimal" or "optimal".

  CLI Example:

      salt '*' partition.align_check /dev/sda minimal 1

salt.modules.parted_partition.check(device, minor)

  Checks if the file system on partition <minor> has any errors.

  CLI Example:

      salt '*' partition.check 1

salt.modules.parted_partition.cp(device, from_minor, to_minor)

  Copies the file system on the partition <from-minor> to partition <to-minor>, deleting the original contents of the destination partition.

  CLI Example:

      salt '*' partition.cp /dev/sda 2 3

salt.modules.parted_partition.disk_set(device, flag, state)

  Changes a flag on selected device.

  A flag can be either "on" or "off" (make sure to use proper quoting, see YAML Idiosyncrasies). Some or all of these flags will be available, depending on what disk label you are using.

  Valid flags are:

    - cylinder_alignment

    - pmbr_boot

    - implicit_partition_table

  CLI Example:

      salt '*' partition.disk_set /dev/sda pmbr_boot '"on"'

salt.modules.parted_partition.disk_toggle(device, flag)

  Toggle the state of <flag> on <device>. Valid flags are the same as the disk_set command.

  CLI Example:

      salt '*' partition.disk_toggle /dev/sda pmbr_boot

salt.modules.parted_partition.exists(device='')

  Check to see if the partition exists

  CLI Example:

      salt '*' partition.exists /dev/sdb1

salt.modules.parted_partition.get_block_device()

  Retrieve a list of disk devices

  Added in version 2014.7.0.

  CLI Example:

      salt '*' partition.get_block_device

salt.modules.parted_partition.get_id(device, minor)

  Prints the system ID for the partition. Some typical values are:

       b: FAT32 (vfat)
       7: HPFS/NTFS
      82: Linux Swap
      83: Linux
      8e: Linux LVM
      fd: Linux RAID Auto

  CLI Example:

      salt '*' partition.get_id /dev/sda 1

salt.modules.parted_partition.list_(device, unit=None)

  Prints partition information of given <device>

  CLI Examples:

      salt '*' partition.list /dev/sda
      salt '*' partition.list /dev/sda unit=s
      salt '*' partition.list /dev/sda unit=kB

salt.modules.parted_partition.mkfs(device, fs_type)

  Makes a file system <fs_type> on partition <device>, destroying all data that resides on that partition. <fs_type> must be one of "ext2", "fat32", "fat16", "linux-swap" or "reiserfs" (if libreiserfs is installed)

  CLI Example:

      salt '*' partition.mkfs /dev/sda2 fat32

salt.modules.parted_partition.mklabel(device, label_type)

  Create a new disklabel (partition table) of label_type.

  Type should be one of "aix", "amiga", "bsd", "dvh", "gpt", "loop", "mac", "msdos", "pc98", or "sun".

  CLI Example:

      salt '*' partition.mklabel /dev/sda msdos

salt.modules.parted_partition.mkpart(device, part_type, fs_type=None, start=None, end=None)

  Make a part_type partition for filesystem fs_type, beginning at start and ending at end (by default in megabytes). part_type should be one of "primary", "logical", or "extended".

  CLI Examples:

      salt '*' partition.mkpart /dev/sda primary fs_type=fat32 start=0 end=639
      salt '*' partition.mkpart /dev/sda primary start=0 end=639

salt.modules.parted_partition.mkpartfs(device, part_type, fs_type=None, start=None, end=None)

  The mkpartfs actually is an alias to mkpart and is kept for compatibility. To know the valid options and usage syntax read mkpart documentation.

  CLI Examples:

      salt '*' partition.mkpartfs /dev/sda primary fs_type=fat32 start=0 end=639
      salt '*' partition.mkpartfs /dev/sda primary start=0 end=639

salt.modules.parted_partition.name(device, partition, name)

  Set the name of partition to name. This option works only on Mac, PC98, and GPT disklabels. The name can be placed in quotes, if necessary.

  CLI Example:

      salt '*' partition.name /dev/sda 1 'My Documents'

salt.modules.parted_partition.probe(*devices)

  Ask the kernel to update its local partition data. When no args are specified all block devices are tried.

  Caution: Generally only works on devices with no mounted partitions and may take a long time to return if specified devices are in use.

  CLI Examples:

      salt '*' partition.probe
      salt '*' partition.probe /dev/sda
      salt '*' partition.probe /dev/sda /dev/sdb

salt.modules.parted_partition.rescue(device, start, end)

  Rescue a lost partition that was located somewhere between start and end. If a partition is found, parted will ask if you want to create an entry for it in the partition table.

  CLI Example:

      salt '*' partition.rescue /dev/sda 0 8056

salt.modules.parted_partition.resize(device, minor, start, end)

  Resizes the partition with number <minor>.

  The partition will start <start> from the beginning of the disk, and end <end> from the beginning of the disk. resize never changes the minor number. Extended partitions can be resized, so long as the new extended partition completely contains all logical partitions.

  CLI Example:

      salt '*' partition.resize /dev/sda 3 200 850

salt.modules.parted_partition.rm(device, minor)

  Removes the partition with number <minor>.

  CLI Example:

      salt '*' partition.rm /dev/sda 5

salt.modules.parted_partition.set_(device, minor, flag, state)

  Changes a flag on the partition with number <minor>.

  A flag can be either "on" or "off" (make sure to use proper quoting, see YAML Idiosyncrasies). Some or all of these flags will be available, depending on what disk label you are using.

  Valid flags are:

    - boot

    - root

    - swap

    - hidden

    - raid

    - lvm

    - lba

    - hp-service

    - palo

    - prep

    - msftres

    - bios_grub

    - atvrecv

    - diag

    - legacy_boot

    - msftdata

    - irst

    - esp

    - type

  CLI Example:

      salt '*' partition.set /dev/sda 1 boot '"on"'

salt.modules.parted_partition.set_id(device, minor, system_id)

  Sets the system ID for the partition. Some typical values are:

       b: FAT32 (vfat)
       7: HPFS/NTFS
      82: Linux Swap
      83: Linux
      8e: Linux LVM
      fd: Linux RAID Auto

  CLI Example:

      salt '*' partition.set_id /dev/sda 1 83

salt.modules.parted_partition.system_types()

  List the system types that are supported by the installed version of sfdisk

  CLI Example:

      salt '*' partition.system_types

salt.modules.parted_partition.toggle(device, partition, flag)
  Toggle the state of <flag> on <partition>. Valid flags are the same as

    the set command.

  CLI Example:

      salt '*' partition.toggle /dev/sda 1 boot