[parted-devel] Partition move function

Curtis Gedak gedakc at gmail.com
Thu Apr 29 20:22:20 UTC 2010


Phillip Susi wrote:
> On 4/29/2010 9:52 AM, Jim Meyering wrote:
>   
>> I presume that moving a file system may require knowledge of the internals
>> of that file system, and Parted is getting rid of its FS-manipulation
>> functionality (which includes "move", "check", "mkfs", etc.)  Note that
>> any FS-aware code in parted is probably broken when it comes to operating
>> on a system with >512-byte sectors.
>>     
>
> Generally no, you don't need specific knowledge of the fs to move it.
> NTFS is an exception since it encodes the location of the boot sector in
> the boot sector, so that needs fixed after a move ( if you want Windows
> to still boot that is ).  As I said before, having some knowledge of the
> fs can help speed the process since you can skip moving free blocks, but
> isn't required.
>
> Getting rid of the fs creation and checking is all well and good, but
> being able to copy and move partitions seems like it should still be
> something that parted can do, since those are about manipulating
> partitions, rather than the filesystems in them.
>
>   
>> If you can come up with reliable FS-independent code
>> to move a partition and its file system, please post it.
>>     
>
> The non optimized version is just dd.  To move a partition x sectors to
> the left, you move the start position of the partition in the partition
> table, then dd if=/dev/sda1 of=/dev/sda1 skip=x.  It sounds like gparted
> used to just run this, but now has a bit better internal implementation,
> possibly smart enough to skip unused blocks, and transfer larger chunks
> at a time to reduce seeks, and handle moving the partition slightly to
> the right by starting at the end and working backwards.  Hopefully
> Curtis can shed some more light on this.
>
>   
I wish to begin my response by stating that I did not develop the move 
code in GParted.  However, I have read through it extensively in order 
to adapt it to support sector sizes > 512 bytes.  Credit for the initial 
move idea goes to Jan Claeys, code was developed by Bart Hakvoort, and 
significant testing and bug hunting was performed by Laurent de 
Trogoff.  Hence these gentlemen might have a much better understanding 
of this area than I do.

Following are my discoveries regarding move actions in GParted. 


ARE PARTITION MOVES FILE SYSTEM SPECIFIC?

For the most part one can ignore file system specifics when moving a 
partition.  This is not a hard and fast rule though, as Phillip 
correctly points out in the case of NTFS.  The NTFS file system contains 
a count of the number of sectors proceeding the partition start.  This 
count is stored at offset 0x1C from the beginning of the partition.

Details on the NTFS file system structure can be found at the following 
link:
http://mirror.href.com/thestarman/asm/mbr/NTFSBR.htm

A utility to correct this value after moving an NTFS file system is 
available at the following link:
http://www.linux-ntfs.org/doku.php?id=contrib:ntfsreloc


HOW DOES GPARTED PERFORM FILE SYSTEM MOVES?

For FAT16 / FAT32 file systems, GParted does use the libparted library 
to move the partition.

For all other file systems, GParted has implemented a block by block 
copy operation.  Please note that I believe early releases of GParted 
used 'dd' only for copying partitions, not _moving_ partitions.

There is an important reason for this that occurs when moving a 
partition from near the start of the disk to nearer the end of the disk 
and there is an overlap in disk space.  In this situation, one must 
perform the copy starting with the end of the partition first.  
Otherwise data needed from the source partition in the overlap section 
will be overwritten before it can be moved to the new location.

When moving a partition, GParted cannot use the path to the partition 
(/dev/sda1) because only one view of the partition table is available at 
any one time.  By this I mean that /dev/sda1 cannot have a start sector 
of 63 for the source partition, while at the same time having a 
different start sector for the new destination of the partition.  
Instead GParted accesses the disk device directly (/dev/sda) to perform 
the move operation.

The GParted move code does not contain intelligence regarding the file 
system.  While performing a move GParted copies each and every block in 
the partition regardless of whether the block contains data.

The block copy code within GParted is used for both partition moves and 
copies, and provides feedback on the block copy progress.  The relevant 
code can be found in the src/GParted_Core.cc file in the methods 
copy_block, copy_blocks, and copy_filesystem.

GParted first performs a read of the entire partition, prior to moving 
the partition in an attempt to avoid moving a partition containing bad 
blocks.

Hope that helps describe how GParted performs partition moves.  :-)




More information about the parted-devel mailing list