The default is 128 partitions (entries in partitions array). The size
of the entry is 128 bytes, it means 32 sectors (512-byte) for the
array. The default is too large for tiny devices and it seems better to
dynamically reduce the number to fix the device size.
The reduction is reported to user.
Example:
$ dd if=/dev/zero of=8-sectors.img count=8 bs=512
$ fdisk 8-sectors.img
...
Command (m for help): g
Created a new GPT disklabel (GUID: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2).
The maximal number of partitions is 8 (default is 128).
Command (m for help): x
Expert command (m for help): p
Disk 8-sectors.img: 4 KiB, 4096 bytes, 8 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: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2
First LBA: 4
Last LBA: 4
Alternative LBA: 7
Partition entries LBA: 2
Allocated partition entries: 8
In this case, sectors:
0 - PMBR
1 - GPT header
2-3 - GPT array of partitions (8 entries, 128 bytes each)
4 - partition data
5-6 - backup GPT array of partitions
7 - backup GPT header
The smallest image is 6 sectors with 4 entries in array of partitions.
Note that Linux kernel has no problem to accept 4K image with 1
512-bytes GPT partition.
# losetup -P -f 4K.img
# lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 4K 0 loop
└─loop0p1 259:5 0 512B 0 part
... but we need to fix libblkid, it ignores so small devices to probe for GPT :)
Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
The current code creates GPT header and partitions arrays (with 128
entries ...) although there is no space for all the stuff. This patch
forces fdisk_create_disklabel() to return -ENOSPC if the last and first
usable LBA calculation is out of device size.
Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
When the partition table is present **but** empty, the existing code would output fields followed by a `,` , on the assumption that the list of partitions would follow. But if the list of partitions is empty, it is skipped, leading to output like this:
```
{
"partitiontable": {
"label":"gpt",
"id":"1F9E80D9-DD78-024F-94A3-B61EC82B18C8",
"device":"/dev/sdb",
"unit":"sectors",
"firstlba":2048,
"lastlba":30949342,
"sectorsize":512,
}
}
```
Note the `512,` on the *sectorsize* line.
This is invalid JSON for some parsers, which choke on it.
Avoid this, by checking when outputting the last separator: if there's no table, or there is a table but it is empty, then just put a newline, otherwise use the old path of comma-newline and assume there's going to be a list of partitions after.
We need to skip useless gaps between partition if the gap is no large
enough for a new partition. Unfortunately, the current code checks
size of the gap, but does not care for location of the gap -- this is
good enough for dialog driven partitioning, but it's pretty bad if
start of the partition is explicitly specified (e.g. sfdisk).
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1860461
Signed-off-by: Karel Zak <kzak@redhat.com>
Linux kernel assumes only 1KiB extended partition to avoid overlapping
with nested logical partitions. We need to follow this rule for
BLKPG_ADD_PARTITION.
Addresses: https://github.com/karelzak/util-linux/issues/1112
Signed-off-by: Karel Zak <kzak@redhat.com>
Let's print number of detected errors or "No errors detected." for
MBR. We already use the same for GPT.
The patch also modifies fdisk_verify_disklabel() return code to inform
caller about number of issues.
Addresses: https://github.com/karelzak/util-linux/issues/1051
Signed-off-by: Karel Zak <kzak@redhat.com>
The current code implements the default start as first free space, but
it does not check if the space is large enough.
Addresses: https://github.com/karelzak/util-linux/issues/1044
Signed-off-by: Karel Zak <kzak@redhat.com>
It seems the previous MAXIMUM_PARTS bug fix has not been generic
enough. Let's use the check for all dos_add_partition().
This patch also remove libfdisk attempt to be smart and search for
unused primary partition. If you need more than 60 partition in MBR
than you have a different problem that cannot be solved by libfdisk
...
References: b80fb30a5b
Addresses: https://github.com/karelzak/util-linux/issues/1022
Signed-off-by: Karel Zak <kzak@redhat.com>
The include/partx.h interface we use in util-linux uses 512-byte
sectors, but libfdisk uses real sector sizes.
Signed-off-by: Karel Zak <kzak@redhat.com>
Now, the type shortcuts are supported for sfdisk scripts only.
Unfortunately, the current implementation is not generic enough
and it's also fragile as 'E' shortcut is in collision with 0x0E
type for MBR. The another issue is 'L' which makes shortcuts useless
for fdisk where 'L' is used for another purpose in dialogs.
This patch introduces partition type aliases as extension to
shortcuts. The definition of the shortcut is part of the label
definition and it's not more hardcoded in sfdisk script code.
This patch also introduces 'Ex' shortcut as replacement for (now
deprecated) 'E'.
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c:1713:6: warning: assuming pointer wraparound does not
occur when comparing P +- C1 with P +- C2 [-Wstrict-overflow]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
- add fdisk_gpt_disable_relocation() to disable move backup header to standard location
- add fdisk_gpt_enable_minimize() to move backup header behind last partition
Note that fdisk_gpt_disable_relocation() has to be used before fdisk_assign_device(),
because automatic relocation is done when libfdisk reads the header from the device.
For example:
lb = fdisk_get_label(cxt, "gpt");
fdisk_gpt_disable_relocation(lb, 1);
fdisk_assign_device(cxt, devname, 0);
For fdisk_gpt_enable_minimize() it's not important as recalculation is
done before write, for example:
fdisk_assign_device(cxt, devname, 0);
fdisk_gpt_enable_minimize(fdisk_get_label(cxt, NULL), 1);
... add partition, etc ...
fdisk_write_disklabel(cxt);
Signed-off-by: Karel Zak <kzak@redhat.com>
- add sector-size between supported headers (already in --dump output)
- report unknown headers by -ENOTSUP
- ignore ENOTSUP in sfdisk (but print warning) and in fdisk_script_read_file()
Addresses: https://github.com/karelzak/util-linux/issues/949
Signed-off-by: Karel Zak <kzak@redhat.com>
- move all calculations to inline functions
- remove duplicate code
- keep the same names for the same stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
We have fdisk_set_disklabel_id(), but it's old ask-API based function.
It's not comfortable if you want to avoid dialog or template.
Addresses: https://github.com/karelzak/util-linux/issues/916
Signed-off-by: Karel Zak <kzak@redhat.com>