That really depends. Usually it’s done by the OS installer. My Humax 5300 cable-TV recorder it did it automatically when I connected the disk. And if you have to do it yourself, the “how” in Windows and Linux are different.
By the way, you don’t format a disk. You format a partition.