Both the classical time-ordering and the Magnus expansion are well-known in the context of linear initial value problems. Motivated by the noncommutativity between time-ordering and time derivation, and related problems raised recently in statistical physics, we introduce a generalization of the Magnus expansion. Whereas the classical expansion computes the logarithm of the evolution operator of a linear differential equation, our generalization addresses the same problem, including however directly a non-trivial initial condition. As a by-product we recover a variant of the time ordering operation, known as T*-ordering. Eventually, placing our results in the general context of Rota-Baxter algebras permits us to present them in a more natural algebraic setting. It encompasses, for example, the case where one considers linear difference equations instead of linear differential equations.