How can I loosen a hard-to-reach square nut whose holder is broken?
Sounds like a nice project for a couple hours that grows into a multi-weekend odyssey! 

OPTION 1  I'd wedge a couple of thin paint scrapers under the exposed bolt head outside the shell of the unit, and take the bolt's head off with an angle grinder and a thin cut-off wheel

BUT CONSIDER spark danger - given this is a generator there was probably petrol or diesel in the area.  You'll want to vent it absolutely to remove all trace of gas fumes.  And do this outside, with an extinguisher and sand handy.

Once the bolt head is off, the bolt should drop into the housing and you can fish it out when the covers are removed.

Assembly, well that's not the reverse.  You'll want to find some way to bolt it together without risking the same again.  A dirty hack is to put a new longer bolt in from the inside-to-outside.  The nut will be on the outside and a bit of thread should be exposed.  You can file two spanner-flats into the thread before or after assembly.  Or you could hacksaw a flat slot across the end for a screwdriver.

Also consider what other bolts on the unit might do the same in the future, and either reinforce their mounts with epoxy or fibreglass, or preemptively do a similar bolt hack.



Option 2  - Cut the casing around the bolt head, and deal with it once the cover is off.   You'll probably want to do a patch job on the case after-ward to control fumes etc.



Option 3 - Make a tool to suit.  This is probably the most laborious solution, but you know exactly where the nut is and how long your tool would have to be.  

 From http://www.performanceforums.com/forums/showthread.php?67243773-dodgy-homemade-distributor-spanner

Given how cheap tools are these days, there's no shame in sacrificing a cheap combo ring/open spanner to get the angle or reach you require.  Or sometimes bike chain can be used to grab something you can't otherwise get to.  Example:

 From https://www.youtube.com/watch?v=E8qN9oK8Hzc