Need help with fdisk for tinybsd

WeaponX

Member


Messages: 22

Hi, I have a 256MB compact flash drive. diskinfo -v shows the following:

Code:
/dev/ada1
        512             # sectorsize
        257949696       # mediasize in bytes (246M)
        503808          # mediasize in sectors
        0               # stripesize
        0               # stripeoffset
        984             # Cylinders according to firmware.
        16              # Heads according to firmware.
        32              # Sectors according to firmware.
When I run the tinybsd install script, it asks me the following questions and I have entered the following:

Code:
512 byte sectors per unit? [503808]
Tracks per cylinder? [16]
Sectors per track? [32]
Tinybsd compiles successfully but at the end I notice the following error
Code:
fdisk: invalid fdisk partition table found
Code:
/dev/md4
        512             # sectorsize
        257949696       # mediasize in bytes (246M)
        503808          # mediasize in sectors
        0               # stripesize
        0               # stripeoffset
        984             # Cylinders according to firmware.
        16              # Heads according to firmware.
        32              # Sectors according to firmware.

fdisk: invalid fdisk partition table found
******* Working on device /dev/md4 *******
******* Working on device /dev/md4 *******
parameters extracted from in-core disklabel are:
cylinders=984 heads=16 sectors/track=32 (512 blks/cyl)

parameters to be used for BIOS calculations are:
cylinders=984 heads=16 sectors/track=32 (512 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 32, size 503776 (245 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 983/ head 15/ sector 32
The data for partition 2 is:
<UNUSED>
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
<UNUSED>
When I commit the tinybsd.bin using the command: dd if=tinybsd.bin of=/dev/ada1s1a and reboot selecting compact flash a primary boot device, the bootloader doesn't even load the kernel and constantly reboots.

Can anyone explain if I have the right sector values while building tinybsd or is it a problem with how I'm preparing the compact flash? I used the following steps to prepare the compact flash:

Code:
 fdisk -BI ada1
 bsdlabel -w -B ada1s1
 bsdlabel -e ada1s1 (added 4.2BSD to a partition with the editor)
 newfs /dev/ada1s1a
Any help is much appreciated!
 
OP
OP
W

WeaponX

Member


Messages: 22

I'm guessing I'm not creating the boot loader part correctly :( here's what I'm getting:

Code:
Not ufs
Not ufs
Not ufs
No /boot/loader

FreeBSD/x86 boot
Default: 0:ad(0,a)/boot/kernel/kernel
boot:
Not ufs
No /boot/kernel/kernel

FreeBSD/x86 boot
Default: 0:ad(0,a)/boot/kernel/kernel
boot:
 
OP
OP
W

WeaponX

Member


Messages: 22

Code:
=>      34  62533229  ada0  GPT  (29G)
        34       128     1  freebsd-boot  (64k)
       162  20971392     2  freebsd-ufs  (10G)
  20971554  39845888     3  freebsd-ufs  (19G)
  60817442   1715821        - free -  (837M)

=>    34  503741  ada1  GPT  (246M)
      34     128     1  freebsd-boot  (64k)
     162  503613     2  freebsd-ufs  (245M)

=>     0  503613  ada1p2  BSD  (245M)
       0      16          - free -  (8.0k)
      16  503597       1  !0  (245M)

=>     0  503613  gptid/490b4b6a-5bd7-11e1-82d2-885588558855  BSD  (245M)
       0      16                                              - free -  (8.0k)
      16  503597                                           1  !0  (245M)
Code:
crw-r-----  1 root  operator    0,  97 Feb 20 12:31 /dev/ada1
crw-r-----  1 root  operator    0, 104 Feb 20 12:31 /dev/ada1p1
crw-r-----  1 root  operator    0, 106 Feb 20 12:31 /dev/ada1p2
crw-r-----  1 root  operator    0, 109 Feb 20 12:31 /dev/ada1p2a
please note ada0 is my SSD and ada1 is compact flash which it keeps telling not ufs each time I try and boot....
 

Beeblebrox

Aspiring Daemon

Reaction score: 147
Messages: 985

You ran the dd command for an mbr partitioned disk and it messed up your gpt partition table (ada1p2a??). Empty the disk and destroy the partition table:
# gpart delete -i 2 ada1
Do that for all slices and then
# gpart destroy ada1
# gpart create -s gpt ada1
Then re-create your slices. When you re-run the install script correct for the fact that you have a gpt layout and NOT an mbr layout:
# dd if=tinybsd.bin of=/dev/ada1p2
and NOT ada1s1a (mbr type notation)

Also please read the comment on the bottom of your last post!
 
OP
OP
W

WeaponX

Member


Messages: 22

Hi again,

Here's what I did:

Code:
dd if=/dev/zero of=/dev/ada1
gpart delete -i 2 ada1
gpart delete -i 1 ada1
gpart destroy ada1

gpart create -s gpt /dev/ada1
gpart add -b 34 -s 128 -t freebsd-boot /dev/ada1
gpart add -b 162 -s 503613 -t freebsd-ufs /dev/ada1
gpart set -a bootme -i 2 /dev/ada1
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 2 /dev/ada1
Result:

Code:
=>    34  503741  ada1  GPT  (246M)
      34     128     1  freebsd-boot  (64k)
     162  503613     2  freebsd-ufs  [bootme]  (245M)
Now when I do: dd if=tinybsd.bin of=/dev/ada1p2, I get:
Code:
=>    34  503741  ada1  GPT  (246M)
      34     128     1  freebsd-boot  (64k)
     162  503613     2  freebsd-ufs  [bootme]  (245M)

=>     0  503613  ada1p2  BSD  (245M)
       0      16          - free -  (8.0k)
      16  503597       1  !0  (245M)

=>     0  503613  gpt/boot0  BSD  (245M)
       0      16             - free -  (8.0k)
      16  503597          1  !0  (245M)

=>     0  503613  gptid/3b7920f8-5c89-11e1-8c66-885588558855  BSD  (245M)
       0      16                                              - free -  (8.0k)
      16  503597                                           1  !0  (245M)
and when I boot, I get the following:
Code:
Not ufs
Not ufs
Not ufs

gptboot: No /boot/loader on 0:ad(0p2)
gptboot: No /boot/kernel/kernel on 0:ad(0p2)


FreeBSD/x86 boot
Default: 0:ad(0p2)/boot/kernel/kernel
boot:


FreeBSD/x86 boot
boot: 0:ad(0p1)/boot/kernel/kernel

gptboot: specified partition is not UFS
gptboot: no UFS partition was found
Why do I keep getting /dev/ada1p2a automatically created when I write using DD?
 

wblock@

Administrator
Staff member
Administrator
Moderator
Developer

Reaction score: 3,644
Messages: 13,850

WeaponX said:
Hi again,

Here's what I did:

Code:
dd if=/dev/zero of=/dev/ada1
gpart delete -i 2 ada1
gpart delete -i 1 ada1
gpart destroy ada1
Replace all that with
Code:
# gpart destroy -F ada1
Code:
gpart create -s gpt /dev/ada1
gpart add -b 34 -s 128 -t freebsd-boot /dev/ada1
That is more work than necessary, and has some problems.
Code:
# gpart create -s gpt ada1
# gpart add -s 128k -t freebsd-boot ada1
For an embedded device, 128k (k, not bytes) may be wasteful. GPT might not be the right choice for something small. gpart(8) can create MBR layouts also.

Code:
gpart add -b 162 -s 503613 -t freebsd-ufs /dev/ada1
Again, working too hard. Let gpart do the work:
Code:
# gpart add -t freebsd-ufs ada1
Code:
gpart set -a bootme -i 2 /dev/ada1
Unnecessary.

Code:
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 2 /dev/ada1
Write the bootcode to the boot partition, not the filesystem partition.
Code:
# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada1
Why do I keep getting /dev/ada1p2a automatically created when I write using DD?
Because the thing that is generating a partition binary is putting a bsdlabel(8) at the beginning of it.
 
OP
OP
W

WeaponX

Member


Messages: 22

wblock,

Thanks for the detailed explanation! I finally tinybsd working :)

I ended up copying files manually using the copy command: cp -iprv /mnt /cf

dd was messing things up all along.. I will try and figure out the dump command to see if it can read in raw and dump to /dev/ada1p2

One last question:

Does shrinking Freebsd to 28MB have any performance implications? Tinybsd seems to have removed alot of libraries and I'm wondering if mulithreading will suffer? I have kept SMP kernel/multi-threading feature option during kernel build. What are your thoughts?

Thanks again!
 

wblock@

Administrator
Staff member
Administrator
Moderator
Developer

Reaction score: 3,644
Messages: 13,850

dump(8)/recover(8) work well to copy UFS filesystems; see Backup Options For FreeBSD for examples. There's also net/rsync, which may work as well for special uses like this, just be sure to use -H.

As far as a trimmed-down kernel being slower, well, maybe. If memory structures are limited, that could have a noticeable impact. But kernel stuff is usually not where the majority of time is spent anyway. Applications might run as well as possible on the limited hardware.
 
OP
OP
W

WeaponX

Member


Messages: 22

Just out of curiosity.. what would be the suggested boot code for an embedded system only running Freebsd FreeBSD?

The man page lists several choices but it looks like GPT is the most widely compatible code?

Code:
options GEOM_PART_APM
options GEOM_PART_BSD
options GEOM_PART_GPT
options GEOM_PART_MBR
options GEOM_PART_EBR
options GEOM_PART_EBR_COMPAT
options GEOM_PART_PC98
options GEOM_PART_VTOC8
 

wblock@

Administrator
Staff member
Administrator
Moderator
Developer

Reaction score: 3,644
Messages: 13,850

Those are not the bootcode, but partition schemes. MBR is the old standard, the four partition per disk MSDOS style. That would be the choice for maximum compatibility. GPT is the second, a much more flexible partition system. The pmbr is backwards-compatible with MBR, but some computers have trouble with it. BSD is the old bsdlabel(8) layout, which most computers will boot but is rare and best avoided. APM is for Macs, PC98 is an MBR variant for the old PC98 standard, and VTOC8 is for SPARC computers.

For bootcode, use /boot/mbr for a normal MBR boot, and /boot/gptboot when using GPT partitions.
 

kpa

Beastie's Twin

Reaction score: 1,807
Messages: 6,318

Note that the /boot/mbr is used in different way compared to /boot/gptboot, the first one is written to the first sector of a disk (don't try to dd(1) it directly to the disk, you'll destroy the slice table!!!, use gpart(8)) and the second one is written to a GPT partition of type freebsd-boot.

/boot/mbr installation when ada0 has MBR partitioning:

# gpart bootcode -b /boot/mbr ada0

/boot/gptboot installation when using GPT partitioning (assuming the first GPT partition on ada0 is of type freebsd-boot)

# gpart bootcode -p /boot/gptboot -i 1 ada0

Installing the "protective mbr" /boot/pmbr when using GPT, this is needed to make a bootable GPT partitioned disk unless the BIOS has direct support for booting from a GPT partitioned disk:

# gpart bootcode -b /boot/pbmr ada0
 
OP
OP
W

WeaponX

Member


Messages: 22

I really appreciate the detailed explanation once again! Makes much more sense after reading it twice :)

The reason why I'm digging further on gpart is because I keep getting an error message during kernel boot:

Code:
gpart: Unknown command: show.
usage: gpart help
       gpart list [-a] [name ...]
       gpart status [-ags] [name ...]
       gpart load [-v]
       gpart unload [-v]
I've copied gpart and its relevant libraries to my tinybsd compact flash (/dev/ada1p2), the same gpart executable has more options on my primary drive which I can't figure out how to fix this.

I do have open geom-GPT support compiled in tinybsd kernel and my main build kernel so this is really weird. Any thoughts?

Once again, I really appreciate your help!
 

wblock@

Administrator
Staff member
Administrator
Moderator
Developer

Reaction score: 3,644
Messages: 13,850

WeaponX said:
I really appreciate the detailed explanation once again! makes much more after reading it twice :)

The reason why I'm digging further on gpart is because I keep getting an error message during kernel boot:

Code:
gpart: Unknown command: show.
usage: gpart help
       gpart list [-a] [name ...]
       gpart status [-ags] [name ...]
       gpart load [-v]
       gpart unload [-v]
gpart(8) is a partitioning tool. It should not be run at startup. Find and remove whatever is trying to run it, possibly /etc/rc.local. The error is probably because you have an older version, but it doesn't matter, it shouldn't be running at all.
 
Top