]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: add -t <type> to enable only specified type
authorKarel Zak <kzak@redhat.com>
Wed, 9 Oct 2013 14:02:42 +0000 (16:02 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 9 Oct 2013 14:11:31 +0000 (16:11 +0200)
In some cases (for example hybrid GPT) it's useful to force fdisk to
read only specified disk label and ignore everything else.

For example:

# fdisk -l /dev/sda

Disk /dev/sda: 149.1 GiB, 160041885696 bytes, 312581808 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3549290F-417C-4941-8503-F7835109B821

Device           Start          End   Size Type
/dev/sda1         2048      2050047  1000M EFI System
/dev/sda2      2050048      6146047     2G Microsoft basic data
/dev/sda3      6146048     26462207   9.7G Linux swap
/dev/sda4     26462208     98142207  34.2G Microsoft basic data
/dev/sda5     98142208    230662143  63.2G Microsoft basic data
/dev/sda6    230662144    312580095  39.1G Microsoft basic data

but when GPT is disabled we can access PMBR:

# fdisk -l -t dos /dev/sda

Disk /dev/sda: 149.1 GiB, 160041885696 bytes, 312581808 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device    Boot Start       End    Blocks  Id System
/dev/sda1          1 312581807 156290903+ ee GPT

Reported-by: Craig <util-linux_contact@magister.com.au>
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.8
fdisks/fdisk.c

index d36318d484ef3756074f93e946b0e55b3667d64a..d1979821fb8409589c9cdb675f64309d9a60acd7 100644 (file)
@@ -92,6 +92,11 @@ Print the size (in blocks) of each given partition. This option is DEPRECATED
 in favour of
 .B blockdev (1).
 .TP
+.BI "\-t " type
+Disable support for all disklabels and enable support only for specified \fItype\fP.
+This is necessary for example to access protective or hybrid MBR on devices
+with GPT.
+.TP
 .BI "\-u"[=unit]
 When listing partition tables, show sizes in 'sectors' or in 'cylinders'.  The
 default is to show sizes in sectors.  For backward compatibility, it is possible
index 50f3d412ab6113f5ddbae190ed2e1167c7cd3519..5df78f6a5b8ff4e3c4d7c1c85209b58187254b7c 100644 (file)
@@ -60,6 +60,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
        fputs(_(" -h                print this help text\n"), out);
        fputs(_(" -c[=<mode>]       compatible mode: 'dos' or 'nondos' (default)\n"), out);
        fputs(_(" -L[=<when>]       colorize output (auto, always or never)\n"), out);
+       fputs(_(" -t <type>         force fdisk to recognize specified partition table type only\n"), out);
        fputs(_(" -u[=<unit>]       display units: 'cylinders' or 'sectors' (default)\n"), out);
        fputs(_(" -v                print program version\n"), out);
        fputs(_(" -C <number>       specify the number of cylinders\n"), out);
@@ -410,7 +411,7 @@ int main(int argc, char **argv)
 
        fdisk_context_set_ask(cxt, ask_callback, NULL);
 
-       while ((c = getopt(argc, argv, "b:c::C:hH:lL::sS:u::vV")) != -1) {
+       while ((c = getopt(argc, argv, "b:c::C:hH:lL::sS:t:u::vV")) != -1) {
                switch (c) {
                case 'b':
                {
@@ -465,6 +466,18 @@ int main(int argc, char **argv)
                case 's':
                        act = ACT_SHOWSIZE;
                        break;
+               case 't':
+               {
+                       struct fdisk_label *lb = NULL;
+
+                       while (fdisk_context_next_label(cxt, &lb) == 0)
+                               fdisk_label_set_disabled(lb, 1);
+
+                       lb = fdisk_context_get_label(cxt, optarg);
+                       if (!lb)
+                               errx(EXIT_FAILURE, _("unsupported disklabel: %s"), optarg);
+                       fdisk_label_set_disabled(lb, 0);
+               }
                case 'u':
                        if (optarg && *optarg == '=')
                                optarg++;