Mental illness, gun violence and school shootings are different issues and despite the fact that there are connections between them, each of them requires their own solutions.
Mental illness is something that seems to not be yet treated in a sufficiently effective way all around the world. It's complex subject and there are still aspects that are not well understood. But to me it seems clear that mental health requires more attention on the whole.
It's essential to point out (like you did in your post) that most people suffering from mental illness are non-violent. Vilifying them is a huge problem even if guns are not involved as it discourages people from seeking help when they need it out of fear that they are going to be looked down on and/or lose some rights or freedom.
I do think gun violence is a problem worth addressing and possible prevention is worth investigating and school shootings are something that should not be happening on regular basis. If it is, there is clearly a huge problem.
I live in a country where owning a gun requires a permit and I see nothing wrong with such policy. Guns are a dangerous thing and should not be in the hands of people not capable of handling them properly and since they present a public danger, regulation is a prudent thing to do. Are guns safer and more vital than cars that it would be reasonable for them to be easier to get? If you are going to be driving, you need a driver's license to show that you are capable of performing the task and your car needs to be registered and have a license plate so it is identifiable. I see no good reason for guns to be treated differently especially keeping in mind that cars have more everyday utility than guns.
Where I live, to get both a driver's license and a firearm license, you need to pass a mental health test with a professional psychologist. I have passed both and it's not a high bar to clear but it does serve a purpose. I personally know a mentally unstable person who applied for a gun license and was denies because of this issue and I am glad he did as he has no business having a gun and would have been a huge danger to everybody around him.
RE: Is Mental Illness Really Fueling Mass Shootings?