Disklayout
j.sal.disklayout
helps you to gather a lot of information about the disks and partitions.
- List of all available disks on machine
j.sal.disklayout.getDisks()
Disk API
Each disk holds the following attributes:
disk.partitions
: lists of partitions on that diskdisk.name
: device name (ex: /dev/sda)disk.size
: disk size in bytesdisk.type
: type of disk
Each disk has the following methods:
disk.erase(force=True)
cleans up the disk by by deleting all non protected partitions and if force=True, deletes all partitions included protecteddisk.format(size, hrd)
creates new partition and formats it as configured in the HRD file
Note: the HRD file must contain the following:
filesystem = '<fs-type>' mountpath = '<mount-path>' protected = 0 or 1 type = data or root or tmp
Example:
disk = j.sal.disklayout.getDisks()[0]
disk.paritions
disk.name
disk.size
disk.type
disk.erase(force=True)
disk.format(size, hrd)
Partition API
Each disk has a list of attached partitions. The only way to create a new partition is to call disk.format()
as explained above.
Each partition holds the following attributes:
partition.name
: device name (ex: /dev/sda1)partition.size
: partition size in bytespartition.fstype
: file system typepartition.uuid
: file system UUIDpartition.mountpoint
: get the mount point of partitionpartition.hrd
: HRD instance used when creating the partition or Nonepartition.delete(force=False)
: deletes the partition and deletes protected partitions if force = Truepartition.format()
: formats the partition according to HRDpartition.mount()
: mounts partition to mountpath defined in HRDpartition.setAutoMount(options='defaults', _dump=0, _pass=0)
: which configures partition auto mountfstab
onmountpath
defined in HRDpartition.unsetAutoMount()
: remotes partition from fstab
partition.hrd can be None
, in that case partition is considered unmanaged
which means partition is not created by the SAL. This type of partitions is considered 'protected' by default.
Partition attributes reflects the real state of the partition. For example, mountpoint
will be set if the partition is actually mounted, and is not related to the mountpath
defined in the HRD file.
Example:
disk = j.sal.disklayout.getDisks()[0]
partition = disk.partitions[0]
partition.name
partition.size
partition.fstype
partition.uuid
partition.mountpoint
partition.hrd
partition.delete(force=False)
partition.mount()
partition.format()
partition.setAutoMount(options='defaults', _dump=0, _pass=0)
partition.unsetAutoMount()