]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: add --noauto-pt
authorKarel Zak <kzak@redhat.com>
Tue, 24 Mar 2020 10:17:34 +0000 (11:17 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 24 Mar 2020 10:17:34 +0000 (11:17 +0100)
The default partition table depends on system arch, for example on
Sparc it's SUN and on x86_64 it's MBR. This option forces fdisk to
keep the device empty and allow user to create non-default PT in more
elegant way.

Addresses: https://github.com/karelzak/util-linux/pull/994
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fdisk.8
disk-utils/fdisk.c

index d0ac3bd975b043a61fadd8e945ae6b4742f5fcf2..0e0d96324a01b5ecd22599bbc8dd578d7149ac1b 100644 (file)
@@ -83,9 +83,13 @@ If no devices are given, those mentioned in
 .I /proc/partitions
 (if that file exists) are used.
 .TP
-\fB\-x\fR, \fB\-\-list-details\fR
+\fB\-x\fR, \fB\-\-list\-details\fR
 Like \fB\-\-list\fR, but provides more details.
 .TP
+\fB\-n\fR, \fB\-\-noauto\-pt\fR
+Don't automatically create a default partition table on empty device.  The partition table
+has to be explicitly created by user (by command like 'o', 'g', etc.).
+.TP
 .BR \-o , " \-\-output " \fIlist\fP
 Specify which output columns to print.  Use
 .B \-\-help
index 17d60b1a9470d3c1cd043b050e6406ba408f80d5..457509cd3499a87e74178af053696969b289bc76 100644 (file)
@@ -867,6 +867,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -l, --list                    display partitions and exit\n"), out);
        fputs(_(" -x, --list-details            like --list but with more details\n"), out);
 
+       fputs(_(" -n, --noauto-pt               don't create default partition table on empty devices\n"), out);
        fputs(_(" -o, --output <list>           output columns\n"), out);
        fputs(_(" -t, --type <type>             recognize specified partition table type only\n"), out);
        fputs(_(" -u, --units[=<unit>]          display units: 'cylinders' or 'sectors' (default)\n"), out);
@@ -901,7 +902,7 @@ enum {
 
 int main(int argc, char **argv)
 {
-       int rc, i, c, act = ACT_FDISK;
+       int rc, i, c, act = ACT_FDISK, noauto_pt = 0;
        int colormode = UL_COLORMODE_UNDEF;
        struct fdisk_context *cxt;
        char *outarg = NULL;
@@ -919,6 +920,7 @@ int main(int argc, char **argv)
                { "help",           no_argument,       NULL, 'h' },
                { "list",           no_argument,       NULL, 'l' },
                { "list-details",   no_argument,       NULL, 'x' },
+               { "noauto-pt",      no_argument,       NULL, 'n' },
                { "sector-size",    required_argument, NULL, 'b' },
                { "type",           required_argument, NULL, 't' },
                { "units",          optional_argument, NULL, 'u' },
@@ -945,7 +947,7 @@ int main(int argc, char **argv)
 
        fdisk_set_ask(cxt, ask_callback, NULL);
 
-       while ((c = getopt_long(argc, argv, "b:Bc::C:hH:lL::o:sS:t:u::vVw:W:x",
+       while ((c = getopt_long(argc, argv, "b:Bc::C:hH:lL::no:sS:t:u::vVw:W:x",
                                longopts, NULL)) != -1) {
                switch (c) {
                case 'b':
@@ -1008,6 +1010,9 @@ int main(int argc, char **argv)
                                colormode = colormode_or_err(optarg,
                                                _("unsupported color mode"));
                        break;
+               case 'n':
+                       noauto_pt = 1;
+                       break;
                case 'o':
                        outarg = optarg;
                        break;
@@ -1135,7 +1140,8 @@ int main(int argc, char **argv)
 
                if (!fdisk_has_label(cxt)) {
                        fdisk_info(cxt, _("Device does not contain a recognized partition table."));
-                       fdisk_create_disklabel(cxt, NULL);
+                       if (!noauto_pt)
+                               fdisk_create_disklabel(cxt, NULL);
 
                } else if (fdisk_is_label(cxt, GPT) && fdisk_gpt_is_hybrid(cxt))
                        fdisk_warnx(cxt, _(