Divide both sides by x

\(y'+ \frac{2}{x}y= -x^2+1\)

This is first order linear differential equation of form

\(p(x)= \frac{2}{x}, \ q(x)= -x^2+1\)

Integrating factor is

\(=e^{\int p(x)dx}\)

\(=e^{\int \frac{2}{x}dx}\)

\(=e^{2 logx}\)

\(=e^{log x^2}\)

\(=x^2\)

equation is

\(y \cdot (I.F.)= \int (I.F.) q(x)dx+c\)

\(yx^2= \int x^2(-x+1)dx+c\)

\(yx^2=\int-x^4+x^2dx+c\)

\(x^2y= -\frac{x^5}{5}+\frac{x^3}{3}+c\)

\(y= -\frac{x^3}{5}+\frac{x}{3}+cx^{-2}\)

Given initial condition

\(y(1)=2\)

\(2= -\frac{1}{5}+\frac{1}{3}+\frac{c}{1}\)

\(2= \frac{-3+5}{15}+c\)

\(2= \frac{2}{15}+c\)

\(2- \frac{2}{15}=c\)

\(\frac{30-2}{15}=c\)

\(\frac{28}{15}=c\)

\(y= -\frac{x^3}{5}+\frac{x}{3}+\frac{28}{15x^2}\)