Wednesday, August 27, 2008

Vista: Partitioning and Formatting a New Disk

I just got a new Terabyte hard drive, and I popped it into my Vista Media Center machine (Elrond). When I booted up, it said it recognized the new hardware, and it installed the disk. However, no drive showed up in the Computer folder, so I poked around in the Device Manager. The drive was indeed there, installed and working. I tried rebooting. No effect. Finally, I remembered that last time I had to manually format the drive (I guess the drives don't come pre-formatted to NTFS like they used to), and so (after refreshing my memory with Google) I Opened up Computer Management, went to Storage -> Disk Management, and there was my drive, sitting there labelled "Unallocated". Excellent: all I have to do now is format it, and I'll be on my way. So, I right-clicked on the drive, selected format, and went through the wizard. Then I got this message:
"The operation cannot be completed because the disk is not initialized."
What? Isn't that what I'm trying to do here? Do I have to pull out my Knoppix or GPartEd LiveCD just to get a drive formatted to NTFS for Vista? This is not looking good. Windows Help was worthless when I searched for 'initialize disk'. Back to Google, where I typed in 'vista' plus the error message in quotes, and got a page with a grand total of three (hopefully now with this post it will be four) pages. The first was no help: the guy formatted the drive in XP. The second and third results both contained the solution to the problem. Apparently, we're supposed to all recognize that space to the left of the disk space illustration as right-clickable. Yep, to get a disk initialized, you need to right-click that space and select "Initialize disk" (which writes the partition table, by the way):
After that, it was a simple matter of re-running the format wizard on the drive. Why wasn't there a wizard that said, "You just installed an un-initialized, un-partitioned, un-formatted hard drive, what do you want to do next?" Even a button on the notification that my new hard drive was installed to further configure it would do. There could be appropriate warnings for such possibilities as other operating systems being installed on that disk, or unrecognized filesystems, or other installations.

Monday, August 25, 2008

Shell access to Vista from Linux

Yep, you read that right, I'm going to ssh into a Windows command prompt from Linux box. The first question to answer is, "why on earth would anyone want to do that?" to which my reply is that I wanted to be able to be able to remotely access Elrond, my media box, since it's an always-on machine. I might want to download something directly from it, check what files are there, move them around, etc. My initial thought was to do all of this from Linux, and then just use the default shares (e.g., \\elrond\c$, etc.) to move files, but I ran into trouble accessing default shares from Linux, and it's much more powerful to have command-line access, especially since I've been learning some VBScript lately. Not content with (and not too familiar with) using only the native Windows Shell command-line utilities, I of course installed Cygwin first, and added "c:\cygwin\bin;" to the Path environment variable (put it right after "%systemroot%\system32;"--not before!). Presto! Instant access to all of the Linux utilities and programs that I'm used to. See? This is much better than just Samba/CIFS mounts. The next task was to get an SSH server. My requirements were:
  1. Free
  2. Runs on Vista as a daemon (I don't have to be logged in).
  3. Easy to configure
(Open source would be nice, but it's not a must on Windows.) This article was helpful in rounding up the canidates. My choice was freeSSHd. I tested the server by logging in from my laptop using PuTTY. It worked great, but when I tried to ssh from a Linux box, I got:
$ ssh elrond ssh: elrond: Name or service not known
Oh, yeah, that's right. I use DHCP for my windows boxes, so they're not in the hosts file, and DNS doesn't resolve Windows names not in a domain. Sure, it works if I use the IP address, but using that over time would work havoc on my known_hosts file, and given the nature of DHCP, it's bound to bite me in the butt sooner or later. But Samba can find them, so there must be a way. It took me about a minute (and some bash-completion) to remember the proper command:
$ nmblookup elrond querying elrond on 192.168.5.255 192.168.5.143 elrond<00>
I thought about setting up a script that would parse out the IP address with egrep and then pass it along to the ssh command, but I like a nice clean known_hosts file. There had to be a way to log on to the host by name, so I turned to the Internet. It turns out that the solution is called WINS. Using it requires that "wins" be in the hosts line of nsswitch.conf, like this:
hosts: files dns wins
It also (at least on Gentoo) requires that Samba be compiled with WINBIND support (which is not WINS). This was a rather non-intuitive step, and I have my ignorance to thank for trying WINBIND support in the first place. Okay, at this point I have it all up-and-running!
tim@athena ~ $ ssh elrond tim@elrond's password: Permission denied, please try again. tim@elrond's password: Permission denied, please try again. tim@elrond's password: Received disconnect from 192.168.5.143: 2: Too many attempts.
Wait, what? This worked before! "ssh Tim@elrond" didn't work, and neither did "ssh 192.168.5.142". The server is up and responding. I was using the right password, but something else was wrong. After a little bit of poking around on freeSSHd's website (the forums are, thankfully, rather sparse) I was able to find this, which it turns out is also linked directly from their homepage. Apparently it's a common problem. When running freeSSHd as a service, you have to configure it in "elevated mode"--even if your account is an administrator, that is, you have to explicitly launch the configuration program with elevated privileges, or else you won't be altering the settings for the system, just for the logged-on user. That's why it worked when I had tested it before (my first clue should have been that when I launched the configuration program, I had to stop the service to keep it from saying it was already running. Another problem I ran into was this:
$ ssh elrond Tim@elrond's password: No console window found! Unable to emulate VT100 terminal. Unable to execute command or shell on remote system: Failed to Execute process. Connection to elrond closed.
Basically, I can log in, but it won't give me a terminal. It fails, and kicks me out. The solution was on the forums:
Problem already reported. Disable "use new console engine" until we find a solution.
So I did that, and now it finally works. Update: see comment(s).