Table of Contents
The GNU Parted disk partitioning library provides high-level, architecture
independent functions for operations such as creating, deleting, resizing and
moving of partitions. Most of the functions of libparted work in a
nondestructive way. The partition table is written in data structures and any
change in the partition table happens only in these data structures rather than
directly on the disk. This makes possible to implement partitioning tools
based on libparted that support undoing
of the editing operations.
However we have to solve two problems. The first is that we want to use as much as possible shell scripts rather than C programs. The second is that different programs have to operate with same instance of libparted structures. For example the user can use some tool for automatic partitioning, then correct or customise the automatic partitioning, perform some other arbitrary operations being still allowed to undo everything.
There is one obvious solution of these two problems – we keep the data
structures of libparted in a daemon process and communicate with it in order to
make changes in these data structures. This process is
/bin/parted_server from the package partman-base.
The scripts from /lib/partman/init.d/ are executed before
all partitioning operations. They can be used to initialise the partitioning
system. The scripts may be invoked more than once in which case they should
behave properly. For example this directory can contain a script to discover
the existing hard drives. If invoked for second time the script must either do
nothing or check if there is some new kernel module giving access to new still
undiscovered device.
Any udeb may install a script in this directory. For example the script
/lib/partman/init.d/30parted from the package partman-base is responsible for running
parted_server. Notice that the scripts are prefixed by a
two-digit number. This number determines the order the scripts are executed.
If any of the scripts exit with non-zero exit code the partitioning will be
aborted. This means that in almost all cases these scripts must end with
exit-code 0.
When the initialisation completes, the scripts from
/lib/partman/display.d are executed. These scripts are
supposed to make the actual partitioning interactively or non-interactively.
The exit code code of these scripts is interpreted
as follows:
code = 0The script did nothing, move to the next script in display.d.
code <= 99Restart the partitioning (move again to the first script in display.d).
code <= 254The script successfully partitioned the disks, do not execute the following scripts in display.d.
code = 255Abort the partitioning.
When the disks become ready, the scripts in
/lib/partman/check.d are executed. They have to check if
everything is OK to proceed with commiting the changes on the disks, mounting
file systems, etc. For example the package partman-target installs there a script to check if
there is a root file system. If a script in check.d exits
with non-zero exit code then the scripts in display.d are
executed again and as a result the user is allowed to fix the partitioning.
The directory check.d is remarkable with the fact that some of the scripts in it are installed by non-partman packages. The packages for the various bootloaders (lilo, grub, palo, etc.) install there scripts to ensure the partitioning scheme conforms to their requirements.
While the user is modifying the partitions this happens only in the memory of
the computer and not in the edited devices. This is because almost all changes
happen either in the data-structures of parted_server or in
files in the installer's ram-disk. That's why we can provide the user with the
option to undo everything. When the user chooses to undo the scripts in the
directory /lib/partman/undo.d/ are executed. Any udeb may
install a script in this directory. For example the script
/lib/partman/undo.d/30parted is responsible for restoring
the contents of the data structures of parted_server. In
most cases the scripts from undo.d must exit with exit-code
0. If any of the scripts exit with non-zero exit code the partitioning will be
aborted.
In order to perform the editing operations on the storage devices (and in
particular to transfer the partitions from the internal data-structures of
parted_server to the hard disks) the scripts from the
directory