Hello again.

disklabel(8) writes its label sector outside of A6 partition, possibly into
other partitions and overwrites data there. Looks like 512-byte sectors
are silently expected somewhere here, but I didn't check the code.

In the example below the label sector has been written to offset
1000 (4096-bytes sectors, byte 0x3e8200) and overwrote data in fdisk
partition 0 (see the hexdump output below). The offset in bytes from the
beginning of the disk is the same as would be if 512-byte sectors were used instead of 4k-sectors. Filesystem /dev/sd4a starts where fdisk(8)
and disklabel(8) say, at sector 8000 (4096-bytes sectors), which is
visible from the hexdump.

Label sector is definitly not expected where it is written to.
From disklabel(5):

     The label is located in sector number LABELSECTOR of the drive, usually
     sector 0 where it may be found without any information about the disk
     geometry.  It is at an offset LABELOFFSET from the beginning of the
     sector, to allow room for the initial bootstrap.

Also note wrong number of used sectors newfs(8) reported in this example:
"100.0MB in 204800 sectors of 4096 bytes".
The number would be correct if the sectors were 512-bytes in size.

I'm not usually using mixture of OS's on a system or even a drive, but
there are people who do and this can bite them. Also don't forget service
partitions and so on.

(fxp0 MAC number and sd4 serial were modified.)

OpenBSD/i386 BOOT 3.21
boot> bsd.rd
booting hd0a:kernel/i386/bsd.rd: 
/-\|/-\|/6043500-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-+433856
 
[52+235056\|/-\|/-\|/-\|/+223307-\|/-\|/-\|/-]=0x69d650
entry point at 0x200120

Copyright (c) 1982, 1986, 1989, 1991, 1993
        The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2013 OpenBSD. All rights reserved.  http://www.OpenBSD.org

OpenBSD 5.4 (RAMDISK_CD) #25: Wed Jul 17 10:11:20 MDT 2013
    dera...@i386.openbsd.org:/usr/src/sys/arch/i386/compile/RAMDISK_CD
cpu0: Intel(R) Core(TM)2 CPU 4300 @ 1.80GHz ("GenuineIntel" 686-class) 1.80 GHz
cpu0: 
FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,NXE,LONG,SSE3,DTES64,MWAIT,DS-CPL,EST,TM2,SSSE3,CX16,xTPR,PDCM,LAHF,PERF
real mem  = 526839808 (502MB)
avail mem = 510959616 (487MB)
mainbus0 at root
bios0 at mainbus0: AT/286+ BIOS, date 11/24/08, BIOS32 rev. 0 @ 0xfa080, SMBIOS 
rev. 2.4 @ 0xf0000 (34 entries)
bios0: vendor Phoenix Technologies, LTD version "MS7336 1.14" date 11/24/2008
bios0: Hewlett-Packard HP Compaq dx2300 Microtower
acpi0 at bios0: rev 0
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SLIC HPET MCFG APIC SSDT SSDT
acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: apic clock running at 199MHz
cpu at mainbus0: not configured
ioapic0 at mainbus0: apid 4 pa 0xfec00000, version 20, 24 pins
ioapic0: misconfigured as apic 0, remapped to apid 4
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (PEX0)
acpiprt2 at acpi0: bus -1 (PEX1)
acpiprt3 at acpi0: bus -1 (PEX2)
acpiprt4 at acpi0: bus -1 (PEX3)
acpiprt5 at acpi0: bus -1 (PEX4)
acpiprt6 at acpi0: bus -1 (PEX5)
acpiprt7 at acpi0: bus 2 (HUB0)
bios0: ROM list: 0xc0000/0xb000! 0xcc000/0x1800
pci0 at mainbus0 bus 0: configuration mode 1 (bios)
pchb0 at pci0 dev 0 function 0 "Intel 82946GZ Host" rev 0x02
ppb0 at pci0 dev 1 function 0 "Intel 82946GZ PCIE" rev 0x02: apic 4 int 16
pci1 at ppb0 bus 1
vga1 at pci0 dev 2 function 0 "Intel 82946GZ Video" rev 0x02
wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
"Intel 82801GB HD Audio" rev 0x01 at pci0 dev 27 function 0 not configured
uhci0 at pci0 dev 29 function 0 "Intel 82801GB USB" rev 0x01: apic 4 int 23
uhci1 at pci0 dev 29 function 1 "Intel 82801GB USB" rev 0x01: apic 4 int 19
uhci2 at pci0 dev 29 function 2 "Intel 82801GB USB" rev 0x01: apic 4 int 18
uhci3 at pci0 dev 29 function 3 "Intel 82801GB USB" rev 0x01: apic 4 int 16
ehci0 at pci0 dev 29 function 7 "Intel 82801GB USB" rev 0x01: apic 4 int 23
usb0 at ehci0: USB revision 2.0
uhub0 at usb0 "Intel EHCI root hub" rev 2.00/1.00 addr 1
ppb1 at pci0 dev 30 function 0 "Intel 82801BA Hub-to-PCI" rev 0xe1
pci2 at ppb1 bus 2
fxp0 at pci2 dev 8 function 0 "Intel 82801GB LAN" rev 0x01, i82562: apic 4 int 
20, address 00:19:db:xx:xx:xx
inphy0 at fxp0 phy 1: i82562ET 10/100 PHY, rev. 0
pcib0 at pci0 dev 31 function 0 "Intel 82801GB LPC" rev 0x01
pciide0 at pci0 dev 31 function 2 "Intel 82801GB SATA" rev 0x01: DMA, channel 0 
configured to native-PCI, channel 1 configured to native-PCI
pciide0: using apic 4 int 19 for native-PCI interrupt
wd0 at pciide0 channel 0 drive 0: <ST3250318AS>
wd0: 16-sector PIO, LBA48, 238475MB, 488397168 sectors
wd0(pciide0:0:0): using PIO mode 4, Ultra-DMA mode 6
atapiscsi0 at pciide0 channel 1 drive 0
scsibus0 at atapiscsi0: 2 targets
cd0 at scsibus0 targ 0 lun 0: <HL-DT-ST, DVD+-RW GSA-H31L, W618> ATAPI 5/cdrom 
removable
cd0(pciide0:1:0): using PIO mode 4, Ultra-DMA mode 5
"Intel 82801GB SMBus" rev 0x01 at pci0 dev 31 function 3 not configured
usb1 at uhci0: USB revision 1.0
uhub1 at usb1 "Intel UHCI root hub" rev 1.00/1.00 addr 1
usb2 at uhci1: USB revision 1.0
uhub2 at usb2 "Intel UHCI root hub" rev 1.00/1.00 addr 1
usb3 at uhci2: USB revision 1.0
uhub3 at usb3 "Intel UHCI root hub" rev 1.00/1.00 addr 1
usb4 at uhci3: USB revision 1.0
uhub4 at usb4 "Intel UHCI root hub" rev 1.00/1.00 addr 1
isa0 at pcib0
isadma0 at isa0
com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
com0: console
com1 at isa0 port 0x2f8/8 irq 3: ns16550a, 16 byte fifo
pckbc0 at isa0 port 0x60/5
pckbd0 at pckbc0 (kbd slot)
pckbc0: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard, using wsdisplay0
npx0 at isa0 port 0xf0/16: reported by CPUID; using exception 16
umass0 at uhub0 port 2 configuration 1 interface 0 "Generic USB2.0-CRW" rev 
2.00/11.22 addr 2
umass0: using SCSI over Bulk-Only
scsibus1 at umass0: 2 targets, initiator 0
sd0 at scsibus1 targ 1 lun 0: <Generic-, Compact Flash, 1.00> SCSI0 0/direct 
removable
sd1 at scsibus1 targ 1 lun 1: <Generic-, SM/xD-Picture, 1.00> SCSI0 0/direct 
removable
sd2 at scsibus1 targ 1 lun 2: <Generic-, SD/MMC, 1.00> SCSI0 0/direct removable
sd3 at scsibus1 targ 1 lun 3: <Generic-, MS/MS-Pro, 1.00> SCSI0 0/direct 
removable
umass1 at uhub0 port 5 configuration 1 interface 0 "HGST Touro Desk 3.0" rev 
2.10/0.00 addr 3
umass1: using SCSI over Bulk-Only
scsibus2 at umass1: 2 targets, initiator 0
sd4 at scsibus2 targ 1 lun 0: <HGST, , 0000> SCSI4 0/direct fixed 
serial.xxxxxxxxxxxxxxxxxxxx
sd4: 3815446MB, 4096 bytes/sector, 976754431 sectors
softraid0 at root
scsibus3 at softraid0: 256 targets
root on rd0a swap on rd0b dump on rd0b
erase ^?, werase ^W, kill ^U, intr ^C, status ^T

Welcome to the OpenBSD/i386 5.4 installation program.
(I)nstall, (U)pgrade or (S)hell? s
# cd /dev
# . ./MAKEDEV sd4
# cd /
# dd if=/dev/zero bs=1m count=1k of=/dev/rsd4c
    1024+0 records in
1024+0 records out
1073741824 bytes transferred in 40.960 secs (26213930 bytes/sec)
# fdisk -e sd4
Enter 'help' for information
fdisk: 1> e 0
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
0: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused Partition id ('0' to disable) [0 - FF]: [0] (? for help) 07 Do you wish to edit in CHS mode? [n] Partition offset: [0] 63
Partition size: [0] 30m
fdisk:*1> e 3
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
3: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused Partition id ('0' to disable) [0 - FF]: [0] (? for help) a6 Do you wish to edit in CHS mode? [n] Partition offset: [0] 8000
Partition size: [0] 100m
fdisk:*1> flag 3
Partition 3 marked active.
fdisk:*1> update
Machine code updated.
fdisk:*1> w
Writing MBR at offset 0.
fdisk: 1> q
# disklabel -c sd4
# /dev/rsd4c:
type: SCSI
disk: SCSI disk
label: HGST duid: 0000000000000000
flags:
bytes/sector: 4096
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 60800
total sectors: 976754431
boundstart: 8000
boundend: 33600
drivedata: 0

16 partitions:
#                size           offset  fstype [fsize bsize  cpg]
  c:        976754431                0  unused
i: 7680 63 NTFS # disklabel -E sd4
Label editor (enter '?' for help at any prompt)
a
partition: [a] offset: [8000] size: [25600] FS type: [4.2BSD]
p
OpenBSD area: 8000-33600; size: 25600; free: 0
#                size           offset  fstype [fsize bsize  cpg]
  a:            25600             8000  4.2BSD   4096 32768    1
  c:        976754431                0  unused
i: 7680 63 NTFS
w
q
No label changes.
# newfs /dev/rsd4a
/dev/rsd4a: 100.0MB in 204800 sectors of 4096 bytes
4 cylinder groups of 25.00MB, 800 blocks, 1792 inodes each
super-block backups (for fsck -b #) at:
 64, 51264, 102464, 153664,
# reboot
syncing disks... done
rebooting...


# dd if=/dev/rsd4c bs=4k |hexdump -C |more
00000000  ea 05 00 c0 07 8c c8 8e  d0 bc fc ff 8e d8 b8 a0  |................|
00000010  07 8e c0 31 f6 31 ff b9  00 02 fc f3 a4 ea 22 00  |...1.1........".|
00000020  a0 07 1e 07 0e 1f b4 02  cd 16 a8 03 74 0a b0 07  |............t...|
00000030  e8 cb 00 80 0e b4 01 01  f6 c2 80 75 08 be 36 01  |...........u..6.|
00000040  e8 af 00 b2 80 be be 01  b9 04 00 8a 04 3c 80 74  |.............<.t|
00000050  0f 83 c6 10 e2 f5 be 6a  01 e8 96 00 fb f4 eb fc  |.......j........|
00000060  88 d0 24 0f 04 30 a2 27  01 b0 34 28 c8 a2 34 01  |..$..0.'..4(..4.|
00000070  56 be 1a 01 f6 06 b4 01  01 75 01 46 e8 73 00 5e  |V........u.F.s.^|
00000080  26 c7 06 fe 01 00 00 f6  06 b4 01 01 75 31 88 14  |&...........u1..|
00000090  bb aa 55 b4 41 cd 13 8a  14 72 24 81 fb 55 aa 75  |..U.A....r$..U.u|
000000a0  1e f6 c1 01 74 19 b0 2e  e8 53 00 66 8b 4c 08 66  |....t....S.f.L.f|
000000b0  89 0e 12 01 56 b4 42 be  0a 01 cd 13 5e 73 19 b0  |....V.B.....^s..|
000000c0  3b e8 3a 00 8a 74 01 8b  4c 02 b8 01 02 31 db cd  |;.:..t..L....1..|
000000d0  13 73 05 be 52 01 eb 81  be 7d 01 e8 14 00 26 81  |.s..R....}....&.|
000000e0  3e fe 01 55 aa 75 05 ea  00 7c 00 00 be 61 01 e9  |>..U.u...|...a..|
000000f0  67 ff 50 fc ac 84 c0 74  0f e8 02 00 eb f6 50 53  |g.P....t......PS|
00000100  b4 0e bb 01 00 cd 10 5b  58 c3 10 00 01 00 00 00  |.......[X.......|
00000110  c0 07 00 00 00 00 00 00  00 00 21 55 73 69 6e 67  |..........!Using|
00000120  20 64 72 69 76 65 20 58  2c 20 70 61 72 74 69 74  | drive X, partit|
00000130  69 6f 6e 20 59 00 4d 42  52 20 6f 6e 20 66 6c 6f  |ion Y.MBR on flo|
00000140  70 70 79 20 6f 72 20 6f  6c 64 20 42 49 4f 53 0d  |ppy or old BIOS.|
00000150  0a 00 0d 0a 52 65 61 64  20 65 72 72 6f 72 0d 0a  |....Read error..|
00000160  00 4e 6f 20 4f 2f 53 0d  0a 00 4e 6f 20 61 63 74  |.No O/S...No act|
00000170  69 76 65 20 70 61 72 74  69 74 69 6f 6e 0d 0a 00  |ive partition...|
00000180  90 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 4f 78  00 00 00 00 00 00 00 01  |......Ox........|
000001c0  01 00 07 7a 39 00 3f 00  00 00 00 1e 00 00 00 00  |...z9.?.........|
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 80 7e  |...............~|
000001f0  3f 00 a6 17 15 02 40 1f  00 00 00 64 00 00 55 aa  |?.....@....d..U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
003e8200  57 45 56 82 04 00 00 00  53 43 53 49 20 64 69 73  |WEV.....SCSI dis|
003e8210  6b 00 00 00 00 00 00 00  48 47 53 54 20 20 20 20  |k.......HGST    |
003e8220  20 00 00 00 00 00 00 00  00 10 00 00 3f 00 00 00  | ...........?...|
003e8230  ff 00 00 00 80 ed 00 00  c1 3e 00 00 ff 16 38 3a  |.........>....8:|
003e8240  8b bf 60 18 54 14 d4 ef  00 00 00 00 00 00 00 00  |..`.T...........|
003e8250  40 1f 00 00 40 83 00 00  00 00 00 00 00 00 00 00  |@...@...........|
003e8260  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
003e8270  00 00 01 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
003e8280  00 00 00 00 57 45 56 82  8a 54 10 00 00 20 00 00  |....WEV..T... ..|
003e8290  00 00 01 00 00 64 00 00  40 1f 00 00 00 00 00 00  |.....d..@.......|
003e82a0  07 1c 01 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
003e82b0  00 00 00 00 ff 16 38 3a  00 00 00 00 00 00 00 00  |......8:........|
003e82c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
003e8310  00 00 00 00 00 1e 00 00  3f 00 00 00 00 00 00 00  |........?.......|
003e8320  14 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
003e8330  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
01f42000  00 00 00 00 00 00 00 00  08 00 00 00 10 00 00 00  |................|
01f42010  18 00 00 00 50 00 00 00  00 00 00 00 ff ff ff ff  |....P...........|
01f42020  7e 22 ec 51 00 64 00 00  d7 62 00 00 04 00 00 00  |~".Q.d...b......|
01f42030  00 80 00 00 00 10 00 00  08 00 00 00 05 00 00 00  |................|
01f42040  00 00 00 00 3c 00 00 00  00 80 ff ff 00 f0 ff ff  |....<...........|
01f42050  0f 00 00 00 0c 00 00 00  01 00 00 00 00 20 00 00  |............. ..|
01f42060  03 00 00 00 03 00 00 00  00 10 00 00 00 00 00 00  |................|
01f42070  00 00 00 00 00 20 00 00  00 01 00 00 08 00 00 00  |..... ..........|
01f42080  00 00 00 00 00 c8 00 00  01 00 00 00 00 00 00 00  |................|
01f42090  7e 22 ec 51 b8 b2 11 49  50 00 00 00 00 10 00 00  |~".Q...IP.......|
01f420a0  00 10 00 00 00 00 00 00  00 c8 00 00 00 c8 00 00  |................|
01f420b0  04 00 00 00 01 00 00 00  00 07 00 00 00 19 00 00  |................|
01f420c0  01 00 00 00 59 0c 00 00  fd 1b 00 00 0e 00 00 00  |....Y...........|
01f420d0  00 01 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
01f420e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
01f423e0  00 00 00 00 00 00 00 00  00 20 00 00 00 00 00 00  |......... ......|
01f423f0  01 00 00 00 00 00 00 00  59 0c 00 00 00 00 00 00  |........Y.......|
01f42400  fd 1b 00 00 00 00 00 00  0e 00 00 00 00 00 00 00  |................|
01f42410  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
01f42430  7e 22 ec 51 00 00 00 00  00 64 00 00 00 00 00 00  |~".Q.....d......|
01f42440  d7 62 00 00 00 00 00 00  50 00 00 00 00 00 00 00  |.b......P.......|
01f42450  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
[...]


Regards,
David

Reply via email to