Getting a  sometimes on boot
Sounds to me like you have corruption on the drive and/or the directory information. Boot up in Recovery Mode and use Disk Utility to repair the boot disk. I strongly advise you to make a complete backup before proceeding.


Restart your Mac whilst holding Command (⌘)-R to boot into Recovery Mode
Select Disk Utility from the options presented
Select your internal system disk from the list in the left panel
Choose the Repair option (or First Aid button, depending on your version)


If all goes well, any problems encountered will be fixed. If Disk Utility is unable to fix the issues you will either need to Erase the disk and reinstall the version of OS X/macOS and then use your backup to restore your applications and personal files/settings, or you could try a third-party disk/system utility. My personal favourites are DiskWarrior by Alsoft (https://www.alsoft.com) and TechTool Pro by Micromat (https://www.micromat.com).