Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, 23 August 2011

VirtualBox - virtually complete: part 1

My new Linux machine is almost complete now. It has been running for a couple of months. Since I lost my laptop along with the company I worked for, and haven't seen a reason to buy another one yet, the Linux machine has become my main computing platform for just about everything.

However there are some things which can only be done on Windows. One is iTunes - I only use it as a backup for my iPhone, but for that it is indispensable. Another is the package that updates the navigation data for the plane. Then there is expensive software I bought for Windows and don't plan to buy again - Mathematica, CorelDraw and so on. Not to mention my HP printer/scanner which has no Linux driver. So I've had two machines sitting next to each other, with a  KVM switch to go back and forth when needed.

Of course the solution to this is obvious - virtual machines. I've been idly looking at VirtualBox, one of the open-source VM solutions, for a while. It took something odd to make me dig a bit deeper - the discovery that our electricity supplier (PG&E) has a web page where you can see your hourly consumption. It's fascinating to study, and one thing it showed is that my two desktop computers were accounting for about 60% of the house's background electricity usage. So, turn one of them off, instant 30% energy saving. (If only I could do something equally miraculous for the pool, which accounts for over half of our electricity).

I started by creating a second Linux system. That seemed less scary, though as it turned out it was harder than Windows. It's simple enough - tell VBox to create a virtual machine, then boot it with a Ubuntu CD in the drive and it pretty much goes all by itself. My plan for this VM was to use it as a web server for stuff I want to host at home, rather than through my web provider. It all went well, until I tried to set up a "shared folder".

In its pure form, the VM concept means that the VM runs in complete isolation in a bubble inside the real operating system. This is fine until you do actually want to share stuff. You can do it over the net, using FTP or whatever, but even that isn't "out of the box". By default, Vbox creates VMs using internal NAT addresses, so there is no way to access the VM from anywhere else, including the host. That can be fixed with a couple of clicks, selecting "Bridged Adapter" in the "Attachedto" drop-down, instead of "NAT". But still, it's a clunky way to do things.

So you can also create a "shared folder". This is just a regular directory on the host system, but it looks like a remote filesystem to the guest. It's easy enough to set up, but I just could not get it to work. I successfully mounted it just once. After that, attempts to mount it always failed with "no such device" (or some such). Even deleting it and creating a new one didn't work.

Finally I discovered that, because I'd ticked the "auto-mount" box, it was being automatically mounted in /media. Well, duh, I suppose.

With that done, my Linux VM was usable. Fortunately, because it turns out in my main (host) system, Firefox had autoupdated itself to V6 - and the Flash player doesn't work an more. No more stock charts from Google, no more news video clips from the BBC. This seems to be a problem that a handful of people have run into, with no solution. So for now, I just use an older version of Firefox running inside the Linux VM whenever I need Flash.

The next step was to install a Windows VM. But this is already too long, so that will be for another time


Friday, 22 July 2011

Moving my Linux system to an SSD

Phew, done it! I decided to put a solid-state disk (SSD) on my new Linux system, to get some experience of using them. I expected to run into a few obstacles, but as usual with Linux I also expected to figure them out with a judiciously worded Google query. (Open-source would not work without Google).

It wasn't that easy. My goal was to move my existing system. A re-install from scratch would have been easier but then I'd have to try and remember all the hundred or so packages I've installed since, remember how I configured things like Apache and MySQL...

With Windows of course this is impossible. Thanks to that brilliant invention (not), the registry, you have to reinstall from scratch every time, then spend hours locating the CDs and babysitting the installation process. Been there, done that, and it's one of the main things I dislike about Windows.

I googled around and found a few descriptions of what to do, and indeed it seemed easy. So I physically installed my brand new 64GB SSD, which worked fine, and copied everything on my 1TB hard drive (not that much) to it. The of course I just needed to make it into a bootable system... and that is where the fuin started.

Ubuntu uses a boot system called Grub. I'd found clear instructions how to run that. Unfortunately for me, I just upgraded to Ubuntu 11.04 ("NattyNarwhal"), which uses Grub2, not Grub. And of course, they are completely incompatible - they don't seem to have a single command in common. (This seems to be a fairly widespread disease in the open-source world, deciding to reinvent some well-known piece of the system and make it gratuitously different. The most egregious example is Python 3, though bjam, the build system for Boost, runs a close second).

And I just could not find how to make Grub2 make changes to anything other than the currently running system. I could install it on the SSD, but trying to boot from it was a failure. Ubuntu finds file systems by their unique ID (UUID), and the SSD system was looking for the old hard drive's UUID. If both drives were plugged in, the SSD would boot Grub which then cheerfully booted from the hard drive. But if not... not so good.

I tried creating a "Super Grub 2" boot CD, hoping I could use this to make the changes. This however deserves some kind of award for unhelpful software. There is no "help" command and as far as I can tell no documentation either. So that was out.

By now I'd spent (wasted) two whole evenings on this project. Only my intense natural reluctance to give up on things kept me going, since I didn't actually need this to work. Then I tried a slightly reworded Google query and found this article. If you're an experienced Linux sysadmin you're probably thinking, "What an idiot, everybody knows that's how you do it". But I didn't know...

The key to success, once the files have been copied and /etc/fstab edited, is the following:

sudo -s
for f in sys dev proc ; do mount --bind /$f /ssd/$f ; done
chroot /ssd
grub-install /dev/sda
update-grub


The magic here lies in the chroot command, which is what gets Grub to work on a different drive from the current one. Now I know about it, I'm sure I'll find all sorts of other places to use it.

That done, the SSD booted perfectly by itself, and with a bit of juggling of SATA connections, I got it to boot with the hard drive as well. Problem solved.

By the time I finished this, I was ready for a glass of wine and dinner. So I can't yet say whether the SSD has indeed given me the expected boost in system performance. But at least I've got it working.

Friday, 20 May 2011

My Very First Linux System

Ubuntu rocks. For more, read on...

About a year ago, I converted my home desktop machine from Windows XP to Windows 7, hoping to improve its dire performance problems. That was not a success. Not only was the Windows 7 performance if anything worse than XP, but a number of other things stopped working as well. Based on my experience I cannot imagine why anyone would ever choose to run W7 instead of XP. W7 is full of poorly conceived "security" misfeatures, making it painful to use and even harder to manage. For example, it's impossible to save an image from a webpage to local storage. And I never did get the Cisco VPN to work.

I've been thinking for a while that it would be a good idea to have a Linux server at home. I've switched just about all my non-embedded stuff at work from Windows and Visual Studio to run on Linux systems. VS is actually quite decent but things need to end up on Linux anyway and keeping them dual-platform is too much trouble.

When I first used Unix, Linux hadn't even been thought of. I equipped my network architecture team at DEC with workstations in about 1988. Of course at DEC we didn't have the System Whose Name Must Remain Unspoken, we had Ultrix - which was just BSD Unix. And Linux is both our development and our production environment at work. Running Linux as a user is no issue, but I was worried about the sys admin aspect of the thing. My perception of Linux was of constantly having to build things from source, of irrenconcilable version conflicts and unfindable drivers and bits of operating system. So I kept putting it off.

Then a friend told me about a system they had just bought. Six-core 3.2 GHz AMD CPU, 8 GBytes of memory... all for under $500. That sounded too good to be true, but I went to the Tiger Direct web site and there it was. The temptation was too strong. It's difficult to buy a PC-type system without getting - and paying for - Windows, whether you want it or not. NewEgg for example won't sell you a barebones system like this.

A few days later it all showed up in several large packages. I've always bought assembled systems before, but this one came as a collection of parts - case, power supply, motherboard, CPU, disk, memory, and a few other bits and pieces. I was apprehensive about putting it all together but in fact it was easy. The only trickly part was getting the cheap-and-nasty metal plate around all the motherboard conneectors to fit propely. Functionally speaking, this isn't strictly necessary, but it would look funny without it.

Actually the system came without memory, because it was backordered, and also I'd ordered the wrong part for the CD/DVD drive as well. So it took a couple of trips to Fry's to get everything required. I'd also bought an Ubuntu book which conveniently had a CD in the back, avoiding the problem of downloading the distro and burning a CD - for which I'm not sure I have the software.

And then came the miraculous part. I put the CD in the drive and booted the machine. Ubuntu came up, and with a couple of clicks started to install itself. Nothing could ever have been easier! Once my new system was running, there were numerous things I wanted to install. For every single one of them, a single command and a short wait downloaded it, installed it and got it running. No scratching round trying to find ancient CDs, no complicated licence agreements, no complex configuration screens. And better yet, no Windows registry! Everything just installed and run.

I'd never used Gnome or any other Linux GUI before. Up to now, all my Linux usage has been from the command line - which I rather like, actually. I had low expectations of Gnome but I couldn't have been more wrong. It does everything Windows does, and without all the irritating bogus security misfeatures. I was especially pleasantly surprised by OpenOffice, which can read and edit all my Word, Excel and Powerpoint files. And it's free.

There was only one thing that gave me problems. No surprise, it was the interconnection with my Windows system which, for now anyway, I have kept in place. There is a piece of software, Samba, that allows a Linux system to provide a Windows file server. Unfortunately it has to accomodate all of the superfluous complexity and options of Windows, so configuring it is a nightmare and I just couldn't get it to work. Finally a friend pointed me to SWAT which straightened it all out for me. A key item is that the accounts and passwords for Samba have absolutely nothing to do with any other accounts and passwords on the system. Connection in the other direction, accessing Windows files from my Linux system, is still distinctly shaky. It kind of works, sometimes, but keeps running into all those security misfeatures that made me dislike W7 so much in the first place. I have yet to get it so the Linux machine can write files on Windows, even using the adminsitrator account.

One thing I wanted to do was open up the machine for very limited outside access, so I can retrieve my files from it. This was amazingly easy - install Apache and it just works. Then a little configuration on my Linksys router, five minutes to create an account with dyndns.org, and now I can (with a password of course) access my files from anywhere.

I love my new Linux machine. Next step: move Windows to be a VM under Linux. More on that later...