grub-setup failing on writing partition boot code, but dd working
Mario Limonciello
mario_limonciello@dell.com
Fri Jan 14 03:13:00 GMT 2011
Hi All:
I've been doing lots of experimentation with calling grub-setup from Windows to prepare the bootsector of a FAT32 volume. I'm finding that for some reason, the bootcode doesn't actually get written to the PBR even though grub-setup thinks the write has succeeded.
To achieve this test i'm doing the following:
1) Create the FAT32 partition using diskpart
2) mkdir -p /boot/grub
3) Drop a boot.img and core.img in /boot/grub taken from a Linux build (they're in ELF's then).
4) grub-setup.exe --verbose --force -d /cygdrive/e/boot/grub /dev/sdb1
If I dd the partition bootsector before starting and afterward to compare, it's not changing at all.
(dd if=/dev/sdb of=bootsect bs=512 skip=128 count=1)
Now conversely if I use dd to try to place the contents of a 512 byte file in that place, it works fine.
(dd if=bootsect of=/dev/sdb bs=512 seek=128 count=1)
I've tried to compare the code that dd and grub-setup both use, and even modified the open mode that grub-setup uses, but still get the same results.
If I run grub-setup under strace, a Windows error actually shows up, which makes me think this is actually a bug in cygwin1.dll. Here's the relevant output from strace on grub-setup as it's opening the drive, seeking and attempting to write it:
206 13511691 [main] grub-setup 2608 open: open (/dev/sdb, 0x10202)
52 13511743 [main] grub-setup 2608 normalize_posix_path: src /dev/sdb
52 13511795 [main] grub-setup 2608 normalize_posix_path: /dev/sdb = normalize_posix_path (/dev/sdb)
53 13511848 [main] grub-setup 2608 mount_info::conv_to_win32_path: conv_to_win32_path (/dev/sdb)
58 13511906 [main] grub-setup 2608 mount_info::conv_to_win32_path: src_path /dev/sdb, dst \Device\Harddisk1\Partition0, flags 0x2, rc 0
58 13511964 [main] grub-setup 2608 build_fh_pc: fh 0x612424E4
54 13512018 [main] grub-setup 2608 fhandler_base::open: (\Device\Harddisk1\Partition0, 0x10002)
76 13512094 [main] grub-setup 2608 fhandler_base::set_flags: flags 0x10002, supplied_bin 0x10000
58 13512152 [main] grub-setup 2608 fhandler_base::set_flags: O_TEXT/O_BINARY set in flags 0x10000
52 13512204 [main] grub-setup 2608 fhandler_base::set_flags: filemode set to binary
52 13512256 [main] grub-setup 2608 fhandler_base::open: 0 = NtCreateFile (0x224, C0100000, \Device\Harddisk1\Partition0, io, NULL, 0, 7, 1, 4020, NULL, 0)
53 13512309 [main] grub-setup 2608 fhandler_base::open: 1 = fhandler_base::open (\Device\Harddisk1\Partition0, 0x10002)
193 13512502 [main] grub-setup 2608 fhandler_dev_floppy::get_drive_info: disk geometry: (780 cyl)*(64 trk)*(63 sec)*(512 bps)
58 13512560 [main] grub-setup 2608 fhandler_dev_floppy::get_drive_info: partition info: offset 0 length 1610612736
53 13512613 [main] grub-setup 2608 fhandler_dev_floppy::get_drive_info: drive size: 1610612736
52 13512665 [main] grub-setup 2608 open: 4 = open (/dev/sdb, 0x10202)
106 13512771 [main] grub-setup 2608 lseek64: 65536 = lseek (4, 65536, 0)
52 13512823 [main] grub-setup 2608 writev: writev (4, 0x22C784, 1)
52 13512875 [main] grub-setup 2608 fhandler_base::write: binary write
287 13513162 [main] grub-setup 2608 fhandler_dev_floppy::write_file: 1 (err 0) = WriteFile (548, 13541288, write 512, written 512, 0)
67 13513229 [main] grub-setup 2608 writev: 512 = write (4, 0x22C784, 1), errno 2
66 13513295 [main] grub-setup 2608 seterrno_from_win_error: /netrel/src/cygwin-snapshot-20101229-1/winsup/cygwin/fhandler.cc:1591 windows error 1
60 13513355 [main] grub-setup 2608 geterrno_from_win_error: windows error 1 == errno 54
If I compare that to what DD is doing:
2131 391915 [main] dd 3400 open: 3 = open (/dev/sdb, 0x10202)
1183 393098 [main] dd 3400 dtable::dup3: dup3 (3, 1, 0x0)
1337 394435 [main] dd 3400 build_fh_pc: fh 0x61241884
1187 395622 [main] dd 3400 fhandler_base::dup: in fhandler_base dup
1174 396796 [main] dd 3400 dtable::dup_worker: duped '/dev/sdb' old 0x154, new 0x160
1342 398138 [main] dd 3400 dtable::dup3: newfh->io_handle 0x160, oldfh->io_handle 0x154, new win32_name 0x61242214, old win32_name 0x6124225C
1682 399820 [main] dd 3400 close: close (1)
1271 401091 [main] dd 3400 fhandler_base::close: closing '' handle 0x258
1417 402508 [main] dd 3400 close: 0 = close (1)
1157 403665 [main] dd 3400 dtable::dup3: 1 = dup3 (3, 1, 0x0)
1073 404738 [main] dd 3400 close: close (3)
1475 406213 [main] dd 3400 fhandler_base::close: closing '/dev/sdb' handle 0x154
1620 407833 [main] dd 3400 close: 0 = close (3)
1291 409124 [main] dd 3400 __set_errno: virtual int fhandler_base::ftruncate(_off64_t, bool):1558 val 22
2224 411348 [main] dd 3400 ftruncate64: -1 = ftruncate (1, 65536)
1379 412727 [main] dd 3400 fhandler_dev_raw::fstat: here
1214 413941 [main] dd 3400 fhandler_base::fstat: here
1162 415103 [main] dd 3400 time: 1294954129 = time (0)
945 416048 [main] dd 3400 fstat64: 0 = fstat (1, 0x22CC48)
673 416721 [main] dd 3400 lseek64: 65536 = lseek (1, 65536, 1)
944 417665 [main] dd 3400 readv: readv (0, 0x22CB94, 1) blocking, sigcatchers 2
1801 419466 [main] dd 3400 fhandler_base::read: returning 512, binary mode
1357 420823 [main] dd 3400 readv: 512 = readv (0, 0x22CB94, 1), errno 0
1535 422358 [main] dd 3400 fhandler_base::write: binary write
1468 423826 [main] dd 3400 fhandler_dev_floppy::write_file: 1 (err 0) = WriteFile (352, 9437184, write 512, written 512, 0)
I'm not sure why internally cygwin decided to use writev() for grub-setup and write() for writing the data out. In both cases, dd and grub-setup both use write() in their code.
I've already tried the latest snapshot of cygwin1.dll (2011-12-29 at this time), and i'm getting the same results as with the current stable version.
Any ideas?
--
*Mario Limonciello*
Linux Engineer
*Dell* | OS Engineering
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20110114/8b6975ac/attachment.sig>
More information about the Cygwin
mailing list