  We extend stochastic thermodynamics by relaxing the two assumptions that the
Markovian dynamics must be linear and that the equilibrium distribution must be
a Boltzmann distribution. We show that if we require the second law to hold
when those assumptions are relaxed, then it cannot be formulated in terms of
Shannon entropy. However, thermodynamic consistency is salvaged if we
reformulate the second law in terms of generalized entropy; our first result is
an equation relating the precise form of the non-linear master equation to the
precise associated generalized entropy which results in thermodynamic
consistency. We then build on this result to extend the usual trajectory-level
definitions of thermodynamic quantities that are appropriate even when the two
assumptions are relaxed. We end by using these trajectory-level definitions to
derive extended versions of the Crooks fluctuation theorem and Jarzynski
equality which apply when the two assumptions are relaxed.
