Package: parted Version: 1.6.25.1-1 Severity: grave I overwrote a USB disk with shred, created an EFI GPT disk label and two partitions with parted, used the partitions, shredded the second of them again, made a new file system there, and copied data to it. The next time I reconnected the disk, I was surprised by this warning from Linux:
Jan 24 20:13:49 [kernel] SCSI device sda: 312581808 512-byte hdwr sectors (160042 MB) - Last output repeated twice - Jan 24 20:13:50 [kernel] Alternate GPT is invalid, using primary GPT. Jan 24 20:13:50 [kernel] p1 p2 I then renamed the second partition with parted, in order to make it rewrite the disk label and partition tables. This got rid of the warning, but when I looked at the end of /dev/sda2, I saw that the end of the partition had become overwritten with the partition table. Because I was using ReiserFS with a 4096-byte blocksize, the overwritten part was fortunately not part of the file system. However, if this had been an MD or LVM partition, important metadata could have been overwritten. Next, I studied linux-2.6/fs/partitions/efi.h and examined the on-disk structures with dd | hd | less. In the following listing, the numbers at the left margin are LBA:byterange in hexadecimal; all other numbers are in C syntax. 00000001:000-007 __le64 signature = "EFI PART"; 00000001:008-00B __le32 revision = 0x00010000; 00000001:00C-00F __le32 header_size = 0x0000005c; 00000001:010-013 __le32 header_crc32 = 0x97529bc4; 00000001:014-017 __le32 reserved1 = 0; 00000001:018-01F __le64 my_lba = 1; 00000001:020-027 __le64 alternate_lba = 0x0000000012a19eaf; 00000001:028-02F __le64 first_usable_lba = 0x0000000000000022; 00000001:030-037 __le64 last_usable_lba = 0x0000000012a19e8e; 00000001:038-047 efi_guid_t disk_guid; 00000001:048-04F __le64 partition_entry_lba = 2; 00000001:050-053 __le32 num_partition_entries = 0x00000080; 00000001:054-057 __le32 sizeof_partition_entry = 0x00000080; 00000001:058-05B __le32 partition_entry_array_crc32 = 0x85c3221e; 00000002:000-00F efi_guid_t partition_type_guid = PARTITION_BASIC_DATA_GUID; 00000002:010-01F efi_guid_t unique_partition_guid; 00000002:020-027 __le64 starting_lba = 0x0000000000000022; 00000002:028-02F __le64 ending_lba = 0x000000000003d090; 00000002:030-037 gpt_entry_attributes attributes = 0; 00000002:038-07F efi_char16_t[36] partition_name = L"USB~2 clear"; 00000002:080-08F efi_guid_t partition_type_guid = PARTITION_BASIC_DATA_GUID; 00000002:090-09F efi_guid_t unique_partition_guid; 00000002:0A0-0A7 __le64 starting_lba = 0x000000000003d091; 00000002:0A8-0AF __le64 ending_lba = 0x0000000012a19e8e; 00000002:0B0-0B7 gpt_entry_attributes attributes = 0; 00000002:0B8-0FF efi_char16_t[] partition_name = L"USB~2 cipher"; 12a19e8e:000-00F efi_guid_t partition_type_guid = PARTITION_BASIC_DATA_GUID; 12a19e8e:010-01F efi_guid_t unique_partition_guid; 12a19e8e:020-027 __le64 starting_lba = 0x0000000000000022; 12a19e8e:028-02F __le64 ending_lba = 0x000000000003d090; 12a19e8e:030-037 gpt_entry_attributes attributes = 0; 12a19e8e:038-07F efi_char16_t[36] partition_name = L"USB~2 clear"; 12a19e8e:080-08F efi_guid_t partition_type_guid = PARTITION_BASIC_DATA_GUID; 12a19e8e:090-09F efi_guid_t unique_partition_guid; 12a19e8e:0A0-0A7 __le64 starting_lba = 0x000000000003d091; 12a19e8e:0A8-0AF __le64 ending_lba = 0x0000000012a19e8e; 12a19e8e:0B0-0B7 gpt_entry_attributes attributes = 0; 12a19e8e:0B8-0FF efi_char16_t[36] partition_name = L"USB~2 cipher"; 12a19e8e:100-1FF = 0; 12a19e8f:000-12a19ead:1FF = 0; 12a19eae:000-1FF = garbage; 12a19eaf:000 __le64 signature = "EFI PART"; 12a19eaf:008 __le32 revision = 0x00010000; 12a19eaf:00C __le32 header_size = 0x0000005c; 12a19eaf:010 __le32 header_crc32 = 0x6de2756c; 12a19eaf:014 __le32 reserved1 = 0; 12a19eaf:018 __le64 my_lba = 0x0000000012a19eaf; 12a19eaf:020 __le64 alternate_lba = 1; 12a19eaf:028 __le64 first_usable_lba = 0x0000000000000022; 12a19eaf:030 __le64 last_usable_lba = 0x0000000012a19e8e; 12a19eaf:038 efi_guid_t disk_guid; 12a19eaf:048 __le64 partition_entry_lba = 0x0000000012a19e8e; 12a19eaf:050 __le32 num_partition_entries = 0x00000080; 12a19eaf:054 __le32 sizeof_partition_entry = 0x00000080; 12a19eaf:058 __le32 partition_entry_array_crc32 = 0x85c3221e; Note that: * last_usable_lba = 0x12a19e8e in both the primary and alternate gpt_header structures. * ending_lba = 0x12a19e8e for the second partition in both the primary and alternate partition table. * partition_entry_lba = 0x12a19e8e in the alternate gpt_header structure. * LBA 0x12a19e8e actually contains the beginning of the alternate partition table. The table is 0x80*0x80 = 0x4000 bytes long, so it needs 0x20 blocks (each 0x200 bytes). * LBA 0x12a19eae between the alternative partition table and the alternative gpt_header is random garbage, presumably from the whole-disk shred run. I think this means parted should have placed the alternative partition table at the LBA range 0x12a19e8f-0x12a19eae, rather than 0x12a19e8e-0x12a19ead. I have now shrunk the partition by one block, so it'll be safe regardless of which file system I may use in the future. The last_usable_lba fields are still dangerously wrong, though. -- System Information: Debian Release: testing/unstable APT prefers unstable APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.12-1-k7 Locale: LANG=fi_FI.UTF-8, LC_CTYPE=fi_FI.UTF-8 (charmap=UTF-8) Versions of packages parted depends on: ii libc6 2.3.5-6 GNU C Library: Shared libraries an ii libncurses5 5.4-3 Shared libraries for terminal hand ii libparted1.6-13 1.6.25.1-1 The GNU Parted disk partitioning s ii libreadline5 5.0-10 GNU readline and history libraries parted recommends no packages. -- no debconf information
pgp6JgKTGC0vo.pgp
Description: PGP signature