Fix filesystem on unformatted drive /dev/sg2

I have a hard drive that I’m pretty sure still works, but it doesn’t show up in partition managers or file managers. As far as I can tell, a device (/dev/sg2) shows up when it’s plugged in, and that’s it. For a few moments after unplugging it, another device (/dev/sdb) shows in the list, but goes away really quickly. What steps should I take to see if it’s still useable and to make it show up?

The short explanation from the long one - udev. Udev detects devices in arbitrary order depending on presence e.g. plugged after boot or plugged when booting.

You cannot format a device while mounting - so the best you can do is to launch your system’s GUI partition manager, locate the device and format the partition to the desired filesystem.

If the device is USB stick you can use this script

If it is internal disk or USB removable disk with several partitions you can use your preferred partition manager. Then create mount units for it.