Next Previous Contents

2.1 Command-line client

This client works in command-line mode. User is asked to write a command and the result is printed out. The status of operation is signalized during the operation by a progress bar.

Surprise is compiled using readline library by default, so a comfortable input line is offered (with line editing capabilities, command history,...).

When started, Surprise searches for available devices and reads all partition tables and filesystem headers. The user can browse the filesystems and operate on them. Then he could verify the final state. Is the state is correct, he could commit the changes. This would take usually a long time, but the progress bar will print out the current state.

Surprise prints all the important information to the normal output and all the debug messages to the error output. If you don't want to see them, just redirect the error output (eg. 2>/dev/null). You will see all the error messages, because they are printed to normal output.

You need not to use long names of filesystems and their discrete parameters; if you type substring of such a long name, the long name will be completed. If there are more possible completions, the first one will be chosen.

Basic commands


This command quits the client immidiately, ignoring all the changes set. It doesn't ask user for the confirmation.


It prints the version of Surprise library.


It prints a very simple help -- the list of all commands with their syntaxes and one line description.


It restarts Partition Surprise. All changes will be forgotten, the devices are scanned again and all the tables are filled. You can specify some additional devices or files (e.g. you have a copy of a disk in a file) to probe by the library.

adddevice name

It adds a specified file to the list of devices to probe when start invoked.


It prints out the list of devices to probe when start invoked.

rmdevice name

It removes a specifed file from the list of devices to probe when start invoked.


It compares the old configuration with the new one and checks for usuall errors:

If an error is found, Partition Surprise can not commit the changes and the user must take care about the error.


This commands checks the current state, if verify was not called. If everything is all right, the changes are commited to the disk.

Some operations are done very fast:

All another operations take a very long time, because a new exported filesystem is created and files from imported filesystem are copied:

Some operations can be safely interrupted. The user can press Ctrl+C any time and Surprise will decide: if the interruption of the conversion leaves the data in correct state, the operation is cancelled. If it doesn't, the operation continues. If the user really wants to interrupt it, he MUST kill -9 the process in this case and he will be responsible for the lost of the data. The operations that could be cancelled are:

After everything is done, Partition Surprise is restarted.

Viewing the original/planned state of partitions

Most commands work on a partition. The user can use 2 conventions to specify a disk/partition. He can write a complete path to a device (eg. /dev/hdc, /dev/hda3) or skip the path prefix and just specify a device name (eg. hdc, hda3).

info, info [disk], info [partition]

The first variant (typing info) just writes a list of disks found in the computer.

> info
Found 2 device(s): /dev/hda /dev/hdc

By typing info hda the user is informed about disk model, capacity, geometry, partition alignment and list of founded partitions.

> info hda
Device: /dev/hda
Model: WDC AC310100B
Size: 19807200 sectors (10141286400 bytes)
      9903600 kB
Heads/sectors/cylinders: 16/63/19650
Sectors reserved: 63
Partitions start/end aligned to 63/1008 sectors
4 partition(s): /dev/hda1 /dev/hda2 /dev/hda5 /dev/hda6

By typing info hda5 the user gets information about original partition placement (in sectors, kilobytes and disk geometry), partition type (read in partition table), detected filesystem and imported filesystem parameter values (see command detected).

> info hda6
Partition: /dev/hda6
First sector: 5134815
Distance from beginning: 2567407 kB
Length: 14672385 sectors
        7336193 kB
Partition entry:
        First sector: 63
        Length (in sectors): 14672385
        First head/sector/cylinder: 0F/FF/FF
        Last head/sector/cylinder: 0F/FF/FF
        Partition type: 83
        Partition boot flag: 00
Detected filesystem: Linux ext2
block_size: 1024
inodes_count: 1827840
bytes_per_inode: 4109
blocks_per_group: 8192
reserved_percent: 3
max_mount_count: 20
check_interval: 15552000
error_handling: continue
volume_name: LINUX
codepage [10]: ISO-8859-1
force_block_size [11]: no
force_inodes [12]: none
Data size: 5855171 kB ( 11710341 512-byte blocks)

free [disk]

This command goes through the given disk and prints all the free blocks on it (read from partition table). It works on original state of partitions (it ignores whether they have already been moved or resized). It doesn't take reserved blocks into account (the 62/63 free blocks in the following example can not be used in any way, because the partitions must be aligned).

> free hda
Device: /dev/hda
Size: 19807200 sectors (10141286400 bytes)
Sectors reserved: 63
Partitions start/end aligned to 63/1008 sectors
Free space on device:
            Start       End    Length
                1        62        62
           105840    105902        63
          4612608   4612670        63
          5134752   5134814        63

state, state [disk], state [partition]

This command reads the original and new state and compares them. The user is informed about current/planned partition placement. Without parameters, the command just informs about partition counts:

> state
2 device(s) in system
Original state                  Planned state
/dev/hda      4 partition(s)    /dev/hda      4 partition(s)
/dev/hdc      3 partition(s)    /dev/hdc      3 partition(s)

If given a disk parameter, it prints two partition tables. The positions are counted in 512b long blocks by default. If an optional -kB parameter is specified, they are counted in kilobytes.

> state hda
Device /dev/hda
63 block(s) reserved at beginning, partition start/end aligned to
multiples of 63/1008
Original state:
Partition           Start          Length       Filesystem
/dev/hda1          105903         4506705       fat
/dev/hda2              63          105777       Linux ext2
/dev/hda5         4612671          522081       Linux swap
/dev/hda6         5134815        14672385       Linux ext2
Planned state:
Partition           Start          Length       Filesystem
/dev/hda1          105903         4506705       fat
/dev/hda5         4612671          522081       Linux swap
/dev/hda6         5134815        12582801       Linux ext2
/dev/hda7         6500025         1023687       fat

If given a partition parameter, it informs the user about planned partition placement and exported filesystem parameter values (the output is simillar to the info command output, but the geometry is not printed out).

Exploring the global/disk/filesystem parameters

When the user wants to explore the parameter value, he can specify the parameter in two ways:

  1. By the parameter name: just write the name, eg. block_size. This is complicated, if the parameter has a very long name, because the user must enclose the parameter in `""' (eg. "Number of bootable partition").
  2. By the parameter number: write the number enclosed in `[]', eg. [9]. This is a very simple way, but the user must list the parameters at first to read their numbers.
If the command expects the options (= parameters, but I say an option to prevent confusion), they are divided by spaces. If the option value contains spaces, you must enclose it in `""'. Surprise checks all the conditions specified for the parameter (whether it is a number from given interval/one of a few discrete numbers/one of a few discrete strings/a string of given maximal length and regular expression/...) and doesn't allow to set a nonsense value.


It explores global Partition Surprise parameters:

If gparam is called without options, the current parameters state is printed out. If you specify a parameter ID and the new value, the value will be stored into the parameter:

> gparam
On-line conversion [1]: no
Lilo support [2]: none
Empty device space [3]: no filling
Bad block testing [4]: none

> gparam [2] simple
Lilo support [2]: simple
Value of parameter "Lilo support" successfully changed

detected [partition]

It can explore imported filesystem parameters. Most of them can be viewed only (those that have no number attached to it), because they are fully detected (eg. block_size, volume_name, etc...), but some broken filesystem parameters can not be detected well in all cases (eg. fat_bits in FAT), some of them are used to fill the missing information (eg. uid, gid, mask in FAT) and some of them are not defined (eg. codepage containing the codepage of file name in FAT/ext2).

The syntax is almost the same as of gparam command:

> detected hda1
Partition: /dev/hda1
Detected filesystem: fat
cluster_size: 4096
fat_bits [2]: 32
fats: 2
rootdir_entries: 512
codepage [5]: IBM437
uid [6]: 0
gid [7]: 0
mask [8]: 420
system_id: MSWIN4.1
volume_name: WINDOWS    
fat_name: FAT32   
long_name_type [12]: vfat
force_fat_bits [13]: no
save_bootsector [14]: yes

> detected hda1 [2] 17
Partition: /dev/hda1
Detected filesystem: fat
Number parameter [2] can have only one of the following value:

> detected hda1 [2] 16
Partition: /dev/hda1
Detected filesystem: fat
fat_bits [2]: 16
Value of parameter "fat_bits" successfully changed

param [disk], param [partition]

It is used to explore exported partition/filesystem parameters. The parameters that have a number attached to it, can be modified manually, the others are computed automatically and can be only viewed (after verify command was called).

The filesystem parameters are explained in section Parameters of filesystems, the partition parameters are these:

The syntax is the same as of command detected.

The operations supported by Partition Surprise

Some commands support options. They are specified with leading minus, eg. -roundup, after the command name before all other parameters given to command.

new [-renumber] [-override] [-noalign] [-roundup] partition start length[kMG] [type] [hex]

This command creates a new partition. If a filesystem type is specified, a mkfs command is called after. The parameters of the command have the following meaning:

Primary partitions may be placed anywhere, but they must not overlap. The logical volumes must be placed continually in the extended partition. The size of the extended partition is handled automatically by Surprise, but the user must take care of placing the following logical volumes continually. A sector is reserved by Surprise for every logical volume and the partitions should be bounded, so the user shall reserve about 63 sectors (a track) for a hole between logical volumes, else a he will be warned about it.

del [-renumber] partition [partition...]

This command deletes a partitions. The space will be maked available for another partitions. If Empty device space global parameter is set, the space will be securely deleted. If -renumber option is specified, the other partitions are intelligently renumbered (eg. logical volumes). More than 1 partition can be deleted one time.

mkfs partition type

A new filesystem will be maked on the partition. The (optional) original filesystem will be destroyed -- if you wish to leave the data, use the convert command. After this command is called, the user can replace the exported filesystem parameters by the param command.

convert partition type

The original filesystem will be in-place converted into target filesystem. The current data will stay in correct state. After this command is called, the user can replace the exported filesystem parameters by the param command. The imported filesystem parameters are accessible by the detected command.

move [-override] [-noalign] partition start

The partition will be moved to another starting offset in the same physical disk. The original and planned places may overlap, Partition Surprise takes care about it. The -override, -noalign options have the same meaning as in the new command. If the user wants to move the partition to another disk, he must copy the partition at first and delete the original one.

renumber partition newnumber

The number of the partition will be changed to the specified one, e.g. renumber hda2 3 is going to change the name of the partition of hda2 to hda3; the location, the size, the data and the filesystem of the partition is preserved. The partition with the new number must not previously exist.

resize [-roundup] [-override] [-noalign] partition length[kMG]

The partition will be resized to given length. If it contains a filesystem, it will be in-place resized too (without data loss). The -roundup, -override, -noalign commands have the same meaning as in the new command.

copy source-partition destination-partition

The data from the first partition will be copied into destination partition. FIXME: the neccessary filesystem conversion is perfmormed.

Next Previous Contents