bug-parted
[Top][All Lists]
Advanced

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

patch to GPT mbr code overwrite


From: Christian
Subject: patch to GPT mbr code overwrite
Date: Fri, 19 Dec 2008 11:24:39 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041221

Hello.

As reported to debian bug's list (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504747) libparted overwrite the Master Boot Record code section of GUID Partiton Table.

I  work on this problem and I make libparted reuse the boot code from disk.

I would like to clarify that this patch must be tested. I test only GNU fdisk behaviour
with a plain file. All seems to be ok, but I'm not sure this is enough.
This is my test output:

* Before *
 ~/$ dd if=fakedisk bs=512 count=1 | hexdump -C -v
 1+0 records in
 1+0 records out
00000000 d4 d2 be 78 f6 a0 8d f9 45 22 4d 07 2e c2 84 0f |ÔÒ¾xö ..ùE"M..Â..| 00000010 91 4b c0 9f c6 c8 4b dd f6 8a 65 e4 91 a7 6d 5e |.KÀ.ÆÈKÝö.eä.§m^| 00000020 26 69 aa 13 9c ef 12 38 04 f2 c4 9b 4a 49 d3 dd |&iª..ï.8.òÄ.JIÓÝ| 00000030 16 f6 78 1e 06 15 65 66 b4 34 b7 53 ba 1b ab f7 |.öx...ef´4·Sº.«÷| 00000040 ec 66 67 ad 0c 1b 3c 30 64 fb 27 76 6d d2 12 2c |ìfg­..<0dû'vmÒ.,| 00000050 a6 70 c7 32 1c 33 85 cb 18 71 fc 1a 5f db 37 b4 |¦pÇ2.3.Ë.qü._Û7´| 00000060 e5 18 7d 34 5b 06 62 89 07 8e 3c 07 ea a4 d4 09 |å.}4[.b...<.ê¤Ô.| 00000070 b7 7f a7 8b 48 2c f3 f3 2a e2 f4 2a 32 7d 86 14 |·.§.H,óó*âô*2}..| 00000080 2c 50 49 0c b9 91 a0 0e 09 ef eb 21 b7 da 67 a6 |,PI.¹. ...ïë!·Úg¦| 00000090 d2 fd 68 25 9a 62 be a9 3a 75 c1 05 ae e5 59 eb |Òýh%.b¾©:uÁ.®åYë| 000000a0 ef 44 5b aa 67 90 a9 04 4f c9 76 00 a1 ec 40 7b |address@hidden| 000000b0 8f f2 7a 96 00 c5 5c 43 68 95 e3 6b c5 4d b6 3f |.òz..Å\Ch.ãkÅM¶?| 000000c0 e1 7e 98 2d 22 eb 06 d9 65 36 9a 68 b5 35 4c b4 |á~.-"ë.Ùe6.hµ5L´| 000000d0 92 ea 42 74 81 d9 8b 8d 0c 53 3e 07 80 78 67 22 |.êBt.Ù...S>..xg"| 000000e0 65 29 02 ce c4 87 c0 3b b9 99 f2 dd f2 6a 33 e3 |e).ÎÄ.À;¹.òÝòj3ã| 000000f0 8a ad d6 7d ef 22 24 86 a5 0d 69 88 79 cd fc ae |.­Ö}ï"$.¥.i.yÍü®| 00000100 bc a3 26 6b e6 a3 62 7a 9f 29 b8 19 b9 f3 1a 59 |¼£&kæ£bz.)¸.¹ó.Y| 00000110 50 6b eb 6b de 7a 13 14 85 85 ed fd 5e b7 1a 3d |PkëkÞz....íý^·.=| 00000120 62 14 48 ae 88 38 45 4d 0f eb b3 a2 12 67 26 d0 |b.H®.8EM.ë³¢.g&Ð| 00000130 8d 5b 1c 06 13 62 50 c5 ae 52 63 9b ba dc c0 9f |.[...bPÅ®Rc.ºÜÀ.| 00000140 a9 15 30 45 cb 42 32 d1 8d 03 9c 67 00 60 c4 df |©.0EËB2Ñ...g.`Äß| 00000150 0d cd 2d 89 54 ed ec 4a 7c 8d 2b fa e2 c8 de 7b |.Í-.TíìJ|.+úâÈÞ{| 00000160 c1 53 17 2b 5b 30 ac 80 1b 64 8c d9 0e 84 0e c2 |ÁS.+[0¬..d.Ù...Â| 00000170 87 7c 37 d8 c7 ea f2 18 cb dc 4f 19 56 6d 04 31 |.|7ØÇêò.ËÜO.Vm.1| 00000180 ab 82 56 eb dc 3f 40 a7 e0 0f a0 8c a5 dc d9 a0 |address@hidden .¥ÜÙ | 00000190 62 d5 b3 59 ee 13 6b 5e 32 5e 20 49 23 47 ab 81 |bÕ³Yî.k2^ I#G«.| 000001a0 cb c1 c3 7f 50 3d 1d 21 07 0a e2 7f b9 dc a2 53 |ËÁÃ.P=.!..â.¹Ü¢S| 000001b0 70 1c a7 6e e1 f3 aa 0a 00 00 00 00 00 00 00 00 |p.§náóª.........| *000001c0 01 00 ee fe ff ff 01 00 00 00 21 e4 00 00 00 00 |..îþÿÿ....!ä....|* 000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............Uª|

* Change *
 ~/$ fdisk fakedisk
 GNU Fdisk 1.1
 Copyright (C) 1998 - 2006 Free Software Foundation, Inc.
 This program is free software, covered by the GNU General Public
 License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 Using fakedisk
 Command (m for help): p

 Disk fakedisk: 29 MB, 29884416 bytes
 4 heads, 32 sectors/track, 456 cylinders
 Units = cylinders of 128 * 512 = 65536 bytes

Device Boot Start End Blocks Id System
 Command (m for help): n
 Partition name: Christian
 First cylinder  (default 0cyl):
 Last cylinder or +size or +sizeMB or +sizeKB  (default 456cyl): +1MB
 Command (m for help): w

 Writing all changes to fakedisk.

* AFTER *

 ~/$ dd if=fakedisk bs=512 count=1 | hexdump -C -v
 1+0 records in
 1+0 records out
00000000 d4 d2 be 78 f6 a0 8d f9 45 22 4d 07 2e c2 84 0f |ÔÒ¾xö ..ùE"M..Â..| 00000010 91 4b c0 9f c6 c8 4b dd f6 8a 65 e4 91 a7 6d 5e |.KÀ.ÆÈKÝö.eä.§m^| 00000020 26 69 aa 13 9c ef 12 38 04 f2 c4 9b 4a 49 d3 dd |&iª..ï.8.òÄ.JIÓÝ| 00000030 16 f6 78 1e 06 15 65 66 b4 34 b7 53 ba 1b ab f7 |.öx...ef´4·Sº.«÷| 00000040 ec 66 67 ad 0c 1b 3c 30 64 fb 27 76 6d d2 12 2c |ìfg­..<0dû'vmÒ.,| 00000050 a6 70 c7 32 1c 33 85 cb 18 71 fc 1a 5f db 37 b4 |¦pÇ2.3.Ë.qü._Û7´| 00000060 e5 18 7d 34 5b 06 62 89 07 8e 3c 07 ea a4 d4 09 |å.}4[.b...<.ê¤Ô.| 00000070 b7 7f a7 8b 48 2c f3 f3 2a e2 f4 2a 32 7d 86 14 |·.§.H,óó*âô*2}..| 00000080 2c 50 49 0c b9 91 a0 0e 09 ef eb 21 b7 da 67 a6 |,PI.¹. ...ïë!·Úg¦| 00000090 d2 fd 68 25 9a 62 be a9 3a 75 c1 05 ae e5 59 eb |Òýh%.b¾©:uÁ.®åYë| 000000a0 ef 44 5b aa 67 90 a9 04 4f c9 76 00 a1 ec 40 7b |address@hidden| 000000b0 8f f2 7a 96 00 c5 5c 43 68 95 e3 6b c5 4d b6 3f |.òz..Å\Ch.ãkÅM¶?| 000000c0 e1 7e 98 2d 22 eb 06 d9 65 36 9a 68 b5 35 4c b4 |á~.-"ë.Ùe6.hµ5L´| 000000d0 92 ea 42 74 81 d9 8b 8d 0c 53 3e 07 80 78 67 22 |.êBt.Ù...S>..xg"| 000000e0 65 29 02 ce c4 87 c0 3b b9 99 f2 dd f2 6a 33 e3 |e).ÎÄ.À;¹.òÝòj3ã| 000000f0 8a ad d6 7d ef 22 24 86 a5 0d 69 88 79 cd fc ae |.­Ö}ï"$.¥.i.yÍü®| 00000100 bc a3 26 6b e6 a3 62 7a 9f 29 b8 19 b9 f3 1a 59 |¼£&kæ£bz.)¸.¹ó.Y| 00000110 50 6b eb 6b de 7a 13 14 85 85 ed fd 5e b7 1a 3d |PkëkÞz....íý^·.=| 00000120 62 14 48 ae 88 38 45 4d 0f eb b3 a2 12 67 26 d0 |b.H®.8EM.ë³¢.g&Ð| 00000130 8d 5b 1c 06 13 62 50 c5 ae 52 63 9b ba dc c0 9f |.[...bPÅ®Rc.ºÜÀ.| 00000140 a9 15 30 45 cb 42 32 d1 8d 03 9c 67 00 60 c4 df |©.0EËB2Ñ...g.`Äß| 00000150 0d cd 2d 89 54 ed ec 4a 7c 8d 2b fa e2 c8 de 7b |.Í-.TíìJ|.+úâÈÞ{| 00000160 c1 53 17 2b 5b 30 ac 80 1b 64 8c d9 0e 84 0e c2 |ÁS.+[0¬..d.Ù...Â| 00000170 87 7c 37 d8 c7 ea f2 18 cb dc 4f 19 56 6d 04 31 |.|7ØÇêò.ËÜO.Vm.1| 00000180 ab 82 56 eb dc 3f 40 a7 e0 0f a0 8c a5 dc d9 a0 |address@hidden .¥ÜÙ | 00000190 62 d5 b3 59 ee 13 6b 5e 32 5e 20 49 23 47 ab 81 |bÕ³Yî.k2^ I#G«.| 000001a0 cb c1 c3 7f 50 3d 1d 21 07 0a e2 7f b9 dc a2 53 |ËÁÃ.P=.!..â.¹Ü¢S| 000001b0 70 1c a7 6e e1 f3 aa 0a 00 00 00 00 00 00 00 00 |p.§náóª.........| * 000001c0 01 00 ee fe ff ff 01 00 00 00 21 e4 00 00 00 00 |..îþÿÿ....!ä....| * 000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............Uª|
 00000200

As we can see data is not lost. Please test this patch and report suggestions!

To apply this patch you must:

 - download gnu parted 1.8.8;
 - unzip source code;
 - go into the top package directory (parted-1.8.8);
 - type `patch -p0 < PATH-TO/libparted-1.8.8-504747.patch'
 - configure, make and make install libparted
 - MAYBE recompile and reinstal gnu fdisk?

Christian.

------------------------------------------------------------------------

--- libparted/labels/gpt-old.c  2007-07-31 19:36:57.000000000 +0200
+++ libparted/labels/gpt.c      2008-12-14 18:30:30.000000000 +0100
@@ -935,7 +935,13 @@
{
        LegacyMBR_t pmbr;

+  /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504747 */
+
+  /* Fill `pmbr' with davece mbr so MBR code area is not lost */
+  if(ped_device_read(dev, &pmbr, 0, GPT_PMBR_SECTORS) < GPT_PMBR_SECTORS)
        memset(&pmbr, 0, sizeof(pmbr));
+
+
        pmbr.Signature = PED_CPU_TO_LE16(MSDOS_MBR_SIGNATURE);
        pmbr.PartitionRecord[0].OSType      = EFI_PMBR_OSTYPE_EFI;
        pmbr.PartitionRecord[0].StartSector = 1;

--- libparted/labels/gpt-old.c  2007-07-31 19:36:57.000000000 +0200
+++ libparted/labels/gpt.c      2008-12-14 18:30:30.000000000 +0100
@@ -935,7 +935,13 @@
 {
        LegacyMBR_t pmbr;
 
+  /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504747 */
+
+  /* Fill `pmbr' with davece mbr so MBR code area is not lost */
+  if(ped_device_read(dev, &pmbr, 0, GPT_PMBR_SECTORS) < GPT_PMBR_SECTORS)
        memset(&pmbr, 0, sizeof(pmbr));
+
+
        pmbr.Signature = PED_CPU_TO_LE16(MSDOS_MBR_SIGNATURE);
        pmbr.PartitionRecord[0].OSType      = EFI_PMBR_OSTYPE_EFI;
        pmbr.PartitionRecord[0].StartSector = 1;

reply via email to

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