Chapter 5. The commands of parted_server

Table of Contents

5.1. Open a new device
5.2. Close a device
5.3. Does the partition exist on the disk?
5.4. Remember the partition table as unchanged
5.5. Report whether the partition table is changed
5.6. Dump the partitions
5.7. Write partitioning to the disk
5.8. Undo the changes
5.9. Get the partitions
5.10. Getting info about a partition
5.11. Getting cylinder/head/sector geometry of a partition/free space
5.12. Getting the supported partition table types
5.13. Get the type of the disk label
5.14. Create a new empty partition table
5.15. Getting the meaningful flags for a partition
5.16. Getting the active flags of a partition
5.17. Set the flags of a partition
5.18. Check if partition names are supported
5.19. Set the name of a partition
5.20. Get the maximum number of primary partitions
5.21. Check if extended and logical partitions are supported
5.22. Get the known to parted_server file systems
5.23. Try to detect the file system in a partition
5.24. Change the filesystem of a partition
5.25. Create a new partition
5.26. Delete a partition
5.27. Resize a partition
5.28. Get resize range

You should be very careful when you communicate with the parted_server. If parted_server detects any error it will exit immediately. This is safer approach then to try to resolve somehow the error. However this also means that the user will not be shown any information about what happened and why the installer freezed. The log-file /var/log/partman can be used to see the reasons why parted_server exited.

5.1. Open a new device

Synopsis:

cd device_directory
open_dialog OPEN device_name
read_line status
close_dialog
case $status in
    OK)
        # The device has been opened successfully
        ;;
    failed)
        # We wasn't able to open the device
        ;;
esac

Here device_name can be for example /dev/ide/host0/bus0/target0/lun0/disc.

5.2. Close a device

Synopsis:

cd device_directory
open_dialog CLOSE
close_dialog

After this command you may not issue commands regarding the device of device_directory. This command does not invoke the command COMMIT.

5.3. Does the partition exist on the disk?

Synopsis:

cd device_directory
open_dialog VIRTUAL partition_id
read_line virtuality
close_dialog
case $virtuality in
    yes)
        # the partition does not exist on the disk
        # probably because it is newly created
        ;;
    no)
        # the partition exists on the disk
        ;;
esac

5.4. Remember the partition table as unchanged

Synopsis:

cd device_directory
open_dialog DISK_UNCHANGED
close_dialog

After this command parted_server will know that the partition table in its onw internal data structures is the same as the partition table actualy existing on the device. The main purpose of this command is to be used for partition tables with type loop.

5.5. Report whether the partition table is changed

Synopsis:

cd device_directory
open_dialog IS_CHANGED
read_line changed
close_dialog
case $changed in
    yes)
        # the partition table is changed
        ;;
    no)
        # the partition table is not changed
        ;;
esac

5.6. Dump the partitions

Synopsis:

cd device_directory
open_dialog DUMP
close_dialog

This command prints in /var/log/partition_dump all the data regarding the device. It is used for debugging.

5.7. Write partitioning to the disk

Synopsis:

cd device_directory
open_dialog COMMIT
close_dialog

This command transfers the partitions in the device of device_directory from the internal structures of parted_server to the disk.

5.8. Undo the changes

Synopsis:

cd device_directory
open_dialog UNDO
close_dialog

This command destroys the internal data structures in parted_server for a device and then rereads them from the device.

5.9. Get the partitions

Synopsis:

cd device_directory
open_dialog PARTITIONS
while { read_line num id size type fs path name; [ "$id" ]; }; do
    # do something for this partition
done
close_dialog

The body of the loop is executed for every partition and free space. $num is the number of the partition (for example /dev/hda6 has number 6). $id is the id of the partition. $size is the size of the partition (in bytes). If this is an active partition then $type is either `primary' or `logical'. If this is a free space then $type shows what partition can be created in it. In this case $type can be `primary', `logical', `pri/log' or `unusable'. $fs is `free' if this is a free space. Otherwise $fs is the type of the file system of this partition as known to parted_server. $path is a device name for the partition, for example /dev/ide/host0/bus0/target0/lun0/part6. $name is the name of the partition or the empty string if the partition table doesn't support partition names.

Notice that in the loop-body you may not initiate another dialog with parted_server. If you need this you can use the following construction instead:

cd device_directory
open_dialog PARTITIONS
partitions=$(read_paragraph)
close_dialog

echo "$partitions" |
while { read num id size type fs path name; [ "$id" ]; }; do
    # do something for this partition
done

5.10. Getting info about a partition

Synopsis:

cd device_directory
open_dialog PARTITION_INFO partition_id
read_line num id size type fs path name
close_dialog

Here partition_id is the id of the partition to get info. The meaning of the variables are the same as in the command PARTITIONS.

5.11. Getting cylinder/head/sector geometry of a partition/free space

Synopsis:

cd device_directory
open_dialog GET_CHS partition_id
read_line start_cyl start_head start_sector end_cyl end_head end_sector
close_dialog

5.12. Getting the supported partition table types

Synopsis:

cd device_directory
open_dialog LABEL_TYPES
supported=$(read_list)
close_dialog

For the result of this command device_directory is irrelevant. Despite this device_directory must be a valid device directory.

This command is used to read which types partition tables are supported by parted_server (i.e. by libparted). $supported is a comma-separated list of the supported types. At the time of writting the following types are supported: bsd, gpt, mac, dvh, msdos, pc98, sun and loop.

5.13. Get the type of the disk label

Synopsis:

cd device_directory
open_dialog GET_LABEL_TYPE
read_line label_type
close_dialog
if [ "$label_type" = unknown ]; then
    echo "The disk is unknown or it has no disk label
          or the disk label is unknown"
else
    echo "The type of the disk label is:" "$label_type"
fi

This command returns the type of the disk label (i.e. the partition table) of a disk. It can be used to check if there is a partition table (if not, then it is safe to create a new partition table or to use the entire disk for RAID, LVM, encrypted unit, etc).

5.14. Create a new empty partition table

Synopsis:

cd device_directory
open_dialog NEW_LABEL partition_table_type
close_dialog

This command creates in the device a new empty partition table with type partition_table_type. (Of course it won't be written to the disk if you don't use the command COMMIT.)

5.15. Getting the meaningful flags for a partition

Synopsis:

cd device_directory
open_dialog VALID_FLAGS partition_id
meaningful_flags=$(read_list)
close_dialog

$meaningful_flags is a comma-separated list of the flags that are meaningful for the partition with id partition_id.

In order to check wether some particular flag xyz is meaningful you can use this code:

cd device_directory
xyz_is_meaningful=no
open_dialog VALID_FLAGS partition_id
while { read_line flag; [ "$flag" ]; }; do
    if [ "$flag" = xyz ]; then
        xyz_is_meaningful=yes
        # you may not use break here
    fi
done
close_dialog

5.16. Getting the active flags of a partition

Synopsis:

cd device_directory
open_dialog GET_FLAGS partition_id
active_flags=$(read_list)
close_dialog

$active_flags is a comma-separated list of the flags of the partition with id partition_id that are in state 1. This is a sublist of the list returned by the command VALID_FLAGS.

In order to check if some partition is denoted as bootable you can use this code:

cd device_directory
is_bootable=no
open_dialog GET_FLAGS partition_id
while { read_line flag; [ "$flag" ]; }; do
    if [ "$flag" = boot ]; then
        is_bootable=yes
        # you may not use break here
    fi
done
close_dialog

5.17. Set the flags of a partition

Synopsis:

cd device_directory
open_dialog SET_FLAGS partition_id
for flag in $all_flags_that_should_be_active; do
    write_line $flag
done
write_line NO_MORE
close_dialog

If you want to denote some partition as non-bootable you can use the following code:

cd device_directory
open_dialog GET_FLAGS partition_id
new_flags=$(
    while { read_line flag; [ "$flag" ]; }; do
        if [ "$flag" != boot ]; then
            echo $flag
        fi
    done
) 
close_dialog

open_dialog SET_FLAGS $id
write_line "$new_flags"
write_line NO_MORE
close_dialog

5.18. Check if partition names are supported

Synopsis:

cd device_directory
open_dialog USES_NAMES
read_line supported
close_dialog
case $supported in
    yes)
        # the partition table supports partition names
        ;;
    no)
        # the partition table doesn't support partition names
        ;;
esac

5.19. Set the name of a partition

Synopsis:

cd device_directory
open_dialog SET_NAME partition_id new_name
close_dialog

After this command the name of partition_id will be new_name. It is an error to use this command with a partition table that doesn't support partition names.

5.20. Get the maximum number of primary partitions

Synopsis:

cd device_directory
open_dialog GET_MAX_PRIMARY
read_line primaries
close_dialog
logger "This disk may contain up to $primaries primary partitions"

5.21. Check if extended and logical partitions are supported

Synopsis:

cd device_directory
open_dialog USES_EXTENDED
read_line supported
close_dialog
case $supported in
    yes)
        # the partition table supports extended and logical partitions
        ;;
    no)
        # the partition table doesn't support extended and logical partitions
        ;;
esac

5.22. Get the known to parted_server file systems

Synopsis:

cd device_directory
open_dialog FILE_SYSTEM_TYPES
known_filesystems=$(read_list)
close_dialog

$known_filesystems is a comma-separated list of the file systems that are known to parted_server. You probably won't need to use this command.

5.23. Try to detect the file system in a partition

Synopsis:

cd device_directory
open_dialog GET_FILE_SYSTEM partition_id
read_line filesystem
close_dialog
if [ "$filesystem" = none ]; then
    # no known file system is detected
else
    # a file system of type $filesystem is detected 
fi

5.24. Change the filesystem of a partition

Synopsis:

cd device_directory
open_dialog CHANGE_FILE_SYSTEM partition_id new_filesystem
close_dialog

libparted assigns every partition some file system. This command can be used to change this file system. The file system assigned to the partition is not necessarily the same as the actual file system. Libparted uses it to determine automatically the type of the partition in some partition tables. For example with msdos partition tables the partitions with file system `ext2' receive type 83. The partitions that are swap spaces receive type 82.

5.25. Create a new partition

Synopsis:

cd device_directory
open_dialog NEW_PARTITION $type $fs $freespace $position $length
read_line num id size type fs path name
close_dialog
if [ "$id" ]; then
    # the partition is successfully created
else
    # wasn't able to create the partition
fi

$type is either primary or logical. $fs is the type of the file system to be assigned to the partition. $freespace is the id of some free space. $position is either `full', `beginning' or `end' and determines where in $freespace to create the new partition. If $position is not `full' then $length is the length that the new partition should have (in bytes).

If the new file system is successfully created $num is tne number of the created partition (for example /dev/hda6 has number 6). $id is the id of the new partition. $size is the size of the new partition. $size is approximately $length but not necessarily the same. $type and $fs don't change their values. $path is a device name, for example /dev/ide/host0/bus0/target0/lun0/part6. $name is the name of the new partition or an empty string if the partition table doesn't support partition names.

5.26. Delete a partition

Synopsis:

cd device_directory
open_dialog DELETE_PARTITION partition_id
close_dialog

5.27. Resize a partition

Synopsis:

cd device_directory
name_progress_bar some/debconf/template
open_dialog RESIZE_PARTITION partition_id new_size
read_line new_id
close_dialog

This command resizes a partition. As usualy new_size is measured in bytes. $new_id is the new id that the partition receives. The resizing is not supported always. If it fails $new_id will be the same as partition_id.

If the partition exists on the storage device and contains some file system, then the data in the partition will be preserved and the new partition table will be written on the storage device. When it is impossible to resize the file system, the partition will be left unresized. When the partition doesn't exist on the storage device, the new version of the partition table will not be written to it.

This command doesn't move the start of the partition but only its end.

The command name_progress_bar may be omitted. The debconf template must have type text. It will be used to give the user information of what is being done.

5.28. Get resize range

Synopsis:

cd device_directory
open_dialog GET_RESIZE_RANGE partition_id
read_line minimal_size current_size maximal_size
close_dialog

This command returns the minimal and the maximal size that can be achieved by using the command RESIZE_PARTITION. $minimal_size, $current_size and $maximal_size are measured in bytes.