# FreeBSD 8.1 on Compact Flash (CF Card)



## jailed (Jan 10, 2011)

Hello,

I'm trying to setup a FreeBSD system on a CF card.

FreeBSD setup has detect the card, I installed BSD traditionally without problem.

Then rebooted the system after installation. But system didn't boot.

Computer can't find any operating system.

Is there any tip for installing FreeBSD onto CF cards? While formatting etc?

Thank you.


----------



## Beastie (Jan 10, 2011)

jailed said:
			
		

> Then rebooted the system after installation. But system didn't boot.
> 
> Computer can't find any operating system.


How are you booting it? Directly or as a USB device through a USB adapter?
Does your BIOS support booting these?
Have you double-checked the BIOS options for booting? There might be more than one option you need to set/change for this to work properly.


----------



## jailed (Jan 10, 2011)

Hello, thanks for reply.

I plugged the card via a CF to IDE card. Bios see the card as a harddisk without a problem. FreeBSD too see the card as a hard drive. I installed FreeBSD from CD with standard installation without any problem.

But system doesn't boot.

Bios says


```
Reboot and Select proper Boot device
or Insert Boot Media in Selected Boot device and press a key
```


----------



## wblock@ (Jan 10, 2011)

Are you sure the boot block was written?

Some of the CF-to-IDE adapters and cards didn't support DMA, and that has to be disabled in FreeBSD.  This used to work, don't know about now.
/boot/loader.conf:

```
hw.ata.ata_dma="0"
hw.ata.wc="0"
```


----------



## jailed (Jan 10, 2011)

wblock said:
			
		

> Are you sure the boot block was written?
> 
> Some of the CF-to-IDE adapters and cards didn't support DMA, and that has to be disabled in FreeBSD.  This used to work, don't know about now.
> /boot/loader.conf:
> ...



Thank you, adding the lines to loader.conf absolutely worked 

Does disabling DMA mode affect to performance? Is there any important disadvantages?


----------



## jailed (Jan 10, 2011)

*Update*

The problem is hardware or BIOS related. Because I had moved the card to another server to mount it and add the lines to /boot/loader.conf

It worked and I thought that it's related with this change. I moved card back to the installation server and it didn't worked.

The working machine is an old P3. The installation is made on a newer P4 motherboard.

The good this is, I will use it on this P3 server. I try to install it on a P4 to make the compile process faster. So I'm happy.

I don't know why it didn't work on the other machine. It's still a problem but I don't matter.

Thanks again for your replies and sharing your valuable time for me..


----------



## wblock@ (Jan 11, 2011)

jailed said:
			
		

> Thank you, adding the lines to loader.conf absolutely worked
> 
> Does disabling DMA mode affect to performance? Is there any important disadvantages?



PIO is slower than DMA.  OTOH, slower but working is still infinitely faster than not working.


----------



## easymac (Jan 11, 2011)

Not sure exactly what your setup is, so this may not be relevant, but I do this plenty on single-board computers, for use with routing/firewalling/etc...  CF cards are really slow, so disabling DMA isn't a big deal.  More importantly, CF cards die rather quickly, when you're writing data to them for no reason, so you want to reduce the amounts of writes however you can.

One good way is to make use of varmfs and tmpmfs (*grep mfs /etc/defaults/rc.conf*) and mount the remaining partitions read-only.  This way you can even yank the power plug and not worry about fsck!  You'll lose your anything created after boot in /var and /tmp, but on a router, that's pretty much logs.  When I need to make configuration changes I just *mount -o rw /* and make the change, then *mount -o ro /* before logging out.

If you want to install packages, you should reboot with varmfs disabled, so the package database is maintained.


----------



## jailed (Jan 12, 2011)

@easymac

Hello,

First of all DMA is not disabled now. Setup is working with DMA.

I'm using this CF card on a web server that contains Apache, PHP and MySQL.

To minimize writes, I don't use logging (and I don't need logs for this system).

The SQL database's size is under 5 MB. Daily writes (INSERT & UPDATE) to SQL database is no more than just 1 MB. Does writing 1 MB daily cause my card die?

CF card is 4 GB in size. RAM is 1 GB. Most of the SQL reads are done from RAM.

There is no usage on /tmp and /var (expect MySQL database /var/db/mysql) The server's RAM is so enough to run my software, so there's no SWAP usage too.

Do you still suggest me to use tmpfs and varfs in this cases?

Writing 1 MB (at most) per day to the card affect it to die or crash?

Thank you all.


----------



## wblock@ (Jan 12, 2011)

The last time I saw specs on that, a CF card was supposed to be good for about two years as a replacement for the disk in a FreeBSD system with no adjustments (logging enabled).  Those were estimates, not actual tests.  CF cards are cheap, so one approach is just to try it.  AFAIK, the card should handle errors on bad flash locations like a hard disk, swapping them with spares, and then either running out of spares or using unused blocks as spares.  Don't know how to check spare usage on a CF card, either, as SMART is probably not available.


----------



## danbi (Jan 13, 2011)

You may need to disable disk DMA in your BIOS as well. I have had cases when computer would not boot off CF card when DMA is enabled in BIOS. Try disabling other disk options in BIOS until you get it to work. Some CF controllers are pretty dump.

There will be no performance penalty. PIO is faster than most CF cards. If your card supports DMA (few do), you will know, because it will be expensive. Disabling DMA in the OS helps sometimes, because some CF controllers lie they support DMA, while they don't.

I have had CFs fail due to writes (not because of huge writes, just some.. unlucky writes) many years ago. My most recent CF failures have always been read-only and they failed because data has obviously faded. Rewriting the CFs made them good again, for a while.. It is of course possible to wear the CF by writing so many times over it, but the OS doesn't do that, even if log files are involved. In the 4.x era, there was problem with /dev being updated sometimes too frequently..

Having said this, I now happen to have few servers running off flash (USB and CF), that run for well over two years without any measures to reduce writes.. At least the daily jobs and log files (+rotation) surely write lots of megabytes per day.


----------

