Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am writing an update utility for an embedded Linux device for which I am responsible.

I'm creating a basic side-by-side setup, where updates are applied to a staging partition and then the bootloader is switched to the staging partition, changing the primary partition into the new staging one.

However, the embedded device uses a CF card, which are known for sometimes writing data out of order, etc. For this reason, if I mount a file system as read/write, there's a chance of corruption. Therefore, I cannot mount my bootloader partition RW in order to point to the new partition.

Is there a location on disk to which I can safely write a single byte, where the byte represents a 0 for the first partition or a 1 for the second? Even a CF card can't screw up a single byte write, which should happen atomically.

I'm using a plain-old DOS MBR format disk.

share|improve this question
    
Can a CF card write a single byte? I thought it worked by rather bigger sectors, big enough to rewrite a PC partition table. –  Gilles Apr 26 '12 at 0:46
    
@Gilles Typically it does but it isn't a guarantee. –  David Pfeffer Apr 26 '12 at 2:35
add comment

1 Answer

up vote 2 down vote accepted

Create a third, tiny, partition to hold your data. Any other location on your disk will sooner or later bring trouble if indeed you cannot rely on the filesytems.

Sometimes the last few clusters of a disk cannot be addressed in the FAT entry, that may be an option but it heavily depends on exact size of the device.

Does the embedded CPU / device have EEPROM? That would be an ideal place for a single byte.

share|improve this answer
    
Unfortunately no EEPROM. –  David Pfeffer Apr 25 '12 at 17:14
    
I also happen to be out of primary partitions; the bootloader, two roots, and the writable data partition that gets wiped if it gets corrupt. –  David Pfeffer Apr 25 '12 at 17:21
    
Is an extended partition no option? –  jippie Apr 25 '12 at 17:23
    
I'll have an issue when I image larger CF cards -- extended partitions aren't easily resized. –  David Pfeffer Apr 25 '12 at 17:32
    
@DavidPfeffer, how so? I've never had trouble resizing them with (g)parted. –  psusi Apr 26 '12 at 3:07
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.