bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cloning a partition table


From: Jim Meyering
Subject: Re: Cloning a partition table
Date: Sat, 04 Sep 2010 23:52:22 +0200

Serge Wroclawski wrote:
> In my environment, we have large disks and for simplicity, use GPT on
> all our machines.
>
> Occasionally a disk fails and we must replace it. Using cfdisk and MBR
> this would be a simple matter of doing a:
>
> sfdisk -d DISK1 | sfdisk DISK2
>
> in order to copy the disk's partition table from one disk to the
> other, and then we can use the RAID tools to put the disk back in
> service.
>
> sfdisk doesn't know GPT, but luckily parted does.
>
> Unfortunately, this functionality of being able to copy the partition
> table from one device to the other appears missing, as does the
> workaround (as above) of being able to spit out and consume the same
> format of output in order to achieve the same result.
>
> Can someone please suggest either a way to accomplish the same result
> or add this to the list of enhancements to the next version?

This would be useful indeed.

You can do part of this already.

Print the state of the partition table in a
mostly-machine-readable format.  Here are two examples.
First gpt, then msdos.
Note that I've used units of "sectors" (s):

    $ parted -s /dev/sdb u s p free                                         :
    Model: xxxxxxxxxxxxxxx (scsi)
    Disk /dev/sdb: 3907029168s
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt

    Number  Start      End          Size         File system  Name     Flags
     1      34s        2047s        2014s                     slop     hidden
     2      2048s      1048575s     1046528s     ext4         r6-boot  boot
     3      1048576s   62914559s    61865984s    ext4         r6-root
            62914560s  3907029134s  3844114575s  Free Space


    $ parted -s /dev/sda u s p free
    Model: ATA ST3320620AS (scsi)
    Disk /dev/sda: 625142448s
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos

    Number  Start       End         Size        Type      File system     Flags
     1      63s         122881184s  122881122s  primary   ext3            boot
     2      122881185s  249858944s  126977760s  primary   ext4
     3      249858945s  280768000s  30909056s   primary   ext3
            280768001s  280768004s  4s                    Free Space
     4      280768005s  625137344s  344369340s  extended
     5      280768068s  284864579s  4096512s    logical   linux-swap(v1)
     6      284864643s  605184614s  320319972s  logical   ext3
     7      605184678s  613184984s  8000307s    logical   linux-swap(v1)
     8      613185048s  615353759s  2168712s    logical   reiserfs
     9      615353823s  615385889s  32067s      logical   ext3
            615385890s  625137344s  9751455s              Free Space
            625137345s  625142447s  5103s                 Free Space

Parsing the above (or using some internal representation)
to derive parted commands that would create an identical partition
table on some other device would not be very hard.
For GPT partition tables, it's particularly easy since
you don't have to worry about partition types.

Above, I've used the default output format.
If you really want to parse parted output,
use the --script (-m) option:

    $ parted -m -s /dev/sdb u s p free                                      :
    BYT;
    /dev/sdb:3907029168s:scsi:512:4096:gpt:xxxxxxxxxxxxxxx;
    1:34s:2047s:2014s::slop:hidden;
    2:2048s:1048575s:1046528s:ext4:r6-boot:boot;
    3:1048576s:62914559s:61865984s:ext4:r6-root:;
    1:62914560s:3907029134s:3844114575s:free;

That would make an interesting project.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]