That will get you where you want to go. You can omit the merging of feature2 -> feature and merge feature2 directly into master, if you want a slightly simpler set of commands.
git rebase feature feature2 # Ensure that all feature changes are
# included in feature2
git rebase master feature2 # Create a linear history
git checkout master
git merge feature2 # Merge feature2, which contains feature,
# into master