XDSFyP
Posts: 7
Joined: Mon Aug 27, 2018 1:06 am

Store a config file in /boot ?

Sun Oct 21, 2018 11:07 pm

Hi,

I am having an intermittent issue where I have my Qt program stored in /home/pi/QtProgram and a small (~20KB) settings file stored in /boot/qtProgramSettings.dat

I am using Raspian Lite without the desktop, and I have setup the Pi to boot straight into my Qt program in /etc/rc.local .

On some occasions when booting, the Qt program does not load the settings file /boot/qtProgramSettings.dat . I'm not sure why it does not load the settings file but to me looks like the /boot partition is not mounted at the time when rc.local starts the Qt program. I have not been able to confirm the /boot partition is mounted when the issue occurs as I don't have access to the Pi over the network. When the Pi is turned on again, the Qt program generally loads the settings file.

I think I will change the location of the settings file to /qtProgramSettings.dat since the Qt program always boots up but is there a reason why putting the settings file in /boot is a bad idea? A possible cause could be that the Pi is not properly shut down using the sudo halt command, but instead pulling the Micro USB cable. I am using the official RPI power supply. Is starting the program in rc.local a bad idea?

The reason why I am using the /boot location to store the settings file is easy copying of settings from the SD card to a Windows PC.

n67
Posts: 839
Joined: Mon Oct 30, 2017 4:55 pm

Re: Store a config file in /boot ?

Mon Oct 22, 2018 12:05 am

I think that /etc/rc.local gets run very early in the process (in the world of systemd). So, it is reasonable to assume that at least some of the time, /boot will not have been mounted by the time rc.local gets run. So, I think your analysis is probably correct.

As you say, the easiest fix would be to move the settings file to somewhere on the ext4 partition, but I get your reason for not wanting to change this.

A couple of possible (though admittedly kludgey) solutions come to mind:

1) Is it possible to detect that the settings file didn't get loaded - such that your app could loop until it becomes available? I'm guessing that the loading of the settings file is somehow hard-coded into QT and you can't directly do what is being suggested here. But you could write a shell script that goes something like:

Code: Select all

#!/bin/bash
until [ -f /boot/myfile.txt ]; do sleep 2;done
exec myQTProgram
2) Or you could just put some kind of delay into the QT program - people often suggest putting "sleep 60" somewhere in the process - before running the QT program. Obviously, this is not as desirable as the loop suggested above, but many people don't like the complexity of the loop; they prefer a more brute-force approach.
"L'enfer, c'est les autres"

If a post offends you, just put that poster on your foes list, and be done with it (and with them).

To do otherwise, risks being banned.

XDSFyP
Posts: 7
Joined: Mon Aug 27, 2018 1:06 am

Re: Store a config file in /boot ?

Wed Oct 24, 2018 12:37 am

Thanks for your reply n67.
I think that /etc/rc.local gets run very early in the process (in the world of systemd). So, it is reasonable to assume that at least some of the time, /boot will not have been mounted by the time rc.local gets run. So, I think your analysis is probably correct.
That does seem to be what is happening. My understanding or operating systems isn't that deep, but wouldn't /boot need to mounted quite early because the RPi needs the booting files (start.hex etc) and loads settings from the "/boot/config.txt" file a long time before "/etc/rc.local" and therefore my Qt program is run?

For example, I have an official RPi touchscreen where in "/boot/config.txt" I have rotated the touchscreen 270 degrees. When it boots, all the bootup statuses and information is displayed rotated 270 degrees from the very start, so the "/boot" folder should be mounted long before my Qt program loads its settings from "/boot/qtProgramSettings.dat"
As you say, the easiest fix would be to move the settings file to somewhere on the ext4 partition, but I get your reason for not wanting to change this.
The Qt program is something I have written (I should have explained this in my first post), so my (inelegant) current solution was to store 2 settings files, one in the "/qtProgramSettings.dat" directory, and another in "/boot/qtProgramSettings.dat". When I save the settings I save both, but I only load settings from the "/qtProgramSettings.dat".

n67
Posts: 839
Joined: Mon Oct 30, 2017 4:55 pm

Re: Store a config file in /boot ?

Wed Oct 24, 2018 12:53 am

No. See, here is the thing.

When the RPI boots, the boot ROM (not a term that is normally used, but that is what it is) in the RPi mounts (in a manner of speaking) the boot partition on the SD card and reads the files there. But this is long before any OS (i.e., Linux/Raspbian) is actually running. So, this mounting (the mounting done by the on-board firmware on the Rpi) has nothing to do with whether or not /boot is mounted once you are up and running in Raspbian.

In fact, there is no real need for /boot to be mounted at all, once you are up and running. The system would work fine without it being mounted. The only reason why the convention is to mount it is so that the update/upgrade process will work - i.e., so that when you upgrade your system, if there is a new version of the kernel (or other stuff that lives in /boot, such as the overlays), it can get put in the right place.
"L'enfer, c'est les autres"

If a post offends you, just put that poster on your foes list, and be done with it (and with them).

To do otherwise, risks being banned.

XDSFyP
Posts: 7
Joined: Mon Aug 27, 2018 1:06 am

Re: Store a config file in /boot ?

Wed Oct 24, 2018 3:54 am

Ahh I understand now. Thank you again for your extended response n67!

User avatar
HawaiianPi
Posts: 2870
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Store a config file in /boot ?

Wed Oct 24, 2018 7:41 am

Are you actually putting the settings file in /boot on the ext4 partition? If so, then that's your problem.

The small FAT32 partition gets mounted to /boot when the OS loads, and that will replace anything you have there. If you want something in /boot, you put it on the fist partition of the card (the small FAT32 partition that's labelled "boot"), not in the /boot folder on the 2nd partition.

Unless you are putting the file there from a running Raspbian OS, in which case /boot should already be mounted.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

procount
Posts: 1289
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Store a config file in /boot ?

Wed Oct 24, 2018 7:58 am

@XDSFyP - Because your qt program runs quite early it should first check that the first fat partition is actually mounted on /boot before checking for your settings file. If it is not, then just wait until it is.

You can find examples of this in the noobs or pinn source code on github, which also use qt.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

jahboater
Posts: 3027
Joined: Wed Feb 04, 2015 6:38 pm

Re: Store a config file in /boot ?

Wed Oct 24, 2018 8:44 am

Perhaps you can modify the rc.local systemd service to depend on /boot being mounted?

Aydan
Posts: 588
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: Store a config file in /boot ?

Wed Oct 24, 2018 8:53 am

I would suggest to create a service file in /etc/systemd/system for your program and make it depend on local-fs.target
Whis will make sure that is is only started after all filesystems defined in /etc/fstab (except the noauto ones) are mounted.

Regards
Aydan

XDSFyP
Posts: 7
Joined: Mon Aug 27, 2018 1:06 am

Re: Store a config file in /boot ?

Sat Oct 27, 2018 4:11 am

HawaiianPi wrote:
Wed Oct 24, 2018 7:41 am
Are you actually putting the settings file in /boot on the ext4 partition? If so, then that's your problem.

The small FAT32 partition gets mounted to /boot when the OS loads, and that will replace anything you have there. If you want something in /boot, you put it on the fist partition of the card (the small FAT32 partition that's labelled "boot"), not in the /boot folder on the 2nd partition.

Unless you are putting the file there from a running Raspbian OS, in which case /boot should already be mounted.
I'm using Raspbian Lite, and once booted for a long time, I view the contents of "/boot" I get all the RPi files and my " /boot/qtProgramSettings.dat" file.

Although I believe sometimes when my Qt program loads "/boot" isn't mounted yet and doesn't load my "/boot/qtProgramSettings.dat" file.

XDSFyP
Posts: 7
Joined: Mon Aug 27, 2018 1:06 am

Re: Store a config file in /boot ?

Sat Oct 27, 2018 4:23 am

procount wrote:
Wed Oct 24, 2018 7:58 am
@XDSFyP - Because your qt program runs quite early it should first check that the first fat partition is actually mounted on /boot before checking for your settings file. If it is not, then just wait until it is.

You can find examples of this in the noobs or pinn source code on github, which also use qt.
From very briefly looking at the pinn sorce code, looks like it measures the size of the contents of "/boot" before doing an action which I could do something similar before loading my settings file.

https://github.com/procount/pinn/blob/c ... ad.cpp#L51

XDSFyP
Posts: 7
Joined: Mon Aug 27, 2018 1:06 am

Re: Store a config file in /boot ?

Sat Oct 27, 2018 4:27 am

jahboater wrote:
Wed Oct 24, 2018 8:44 am
Perhaps you can modify the rc.local systemd service to depend on /boot being mounted?
Aydan wrote:
Wed Oct 24, 2018 8:53 am
I would suggest to create a service file in /etc/systemd/system for your program and make it depend on local-fs.target
Whis will make sure that is is only started after all filesystems defined in /etc/fstab (except the noauto ones) are mounted.

Regards
Aydan
Thanks for the suggestions, I need to learn more about systemd and this would be a good project to get started.

Return to “Troubleshooting”