Friday, August 28, 2009

Installing GRUB2

On my last post I described how I hit a problem while trying to rescue files from a bricked Window$ Vista laptop, using my Live HDD (a complete Debian system that I boot from a USB hard disk). My problem: how does one run chkdsk on a corrupted NTFS partition, without a Window$ installation disk?

As I mentioned last time, if you have it installed, you may be able to start the Recovery Console and check the disk. But chances are that either you don't have it installed (Window$ XP) or that it too fails to start.

While searching for a stand alone disk checking utility I recalled that I've once used BartPE to attempt to rescue files from an old desktop PC that I've managed to fry. BartPE was a real wonder at the time: a Window$ Live CD (also known officially as a Windows Preinstallation Environment). You must have a legitimate copy of Windows XP in order to create the Live CD, but other than that it just works. And it includes chkdsk from the original Windows install disk.

(Later on, as I searched some more, I found WinBuilder and LiveXP, which are more versatile and rich in features, but I'll leave that to a future post).

Anyway, I also hit a blog post on how to boot an ISO image via GRUB2. This looked promising: all I had to do was create a Windows PE ISO image, place it on my Live HDD boot partition, and boot into it using GRUB2.

Let me tell you upfront: it doesn't work this way - I misinterpreted that article, and only much later realized that while GRUB2 can loop-mount an ISO image, this doesn't mean that it can boot it. The blog post about why GRUB2 cannot actually boot CDROM images clarifies what can and cannot be done with GRUB2.

So, misguided as I was, I went on to upgrade GRUB on my Live HDD, and replace it with GRUB2. Basically, all that needs to be done is run
aptitude install grub-pc
this will add GRUB2 as the first boot option in the GRUB boot menu ("Chainload into GRUB 2") , but will not replace GRUB on the MBR, so that you may revert to GRUB if you encounter any problem.

Which is pretty considerate.

Once you're happy with it, you should run upgrade-from-grub-legacy in order to finish the transition.

As easy as pie. Really. Unless it bricks your machine. Luckily, it didn't brick mine, which I find somewhat surprising...

I've been hit by some quirks though, most annoying of which is the fact that currently memtest86+ cannot be launched from GRUB2, unless you apply a patch to /etc/grub.d/20_memtest86+ and run update-grub (see Debian bug #540572).

After I verified that GRUB2 worked as advertised, it took a few failed attempts to boot a BartPE ISO image from GRUB2, before I did some more research and realized that I hit a dead end.

What a disappointment.

All in all, I find that there's no real reason to upgrade to GRUB2, unless you really need it. Sure, it's sexier than legacy GRUB (I liked the default Debian graphical background), its configuration is scriptable, it can loop-mount ISO images, it can boot from an Ext4 partition, and much more. But, if your machine works fine with legacy GRUB, I'd suggest you wait for it to be officially obsoleted before upgrading to GRUB 2.

[24 Sep 2009] UPDATE: It didn't take long - the package grub-pc is now the official upgrade path for grub, so I've upgraded to GRUB2 on my laptop too. Works just fine. Just the way I like it.

Sunday, August 23, 2009

Some Things To Try When Windows Fails To Start

We went to visit my wife's aunt. While my wife and her aunt conducted civilized conversation over tea and biscuits, I was cajoled by the aunt's daughter into taking a look at her laptop. "It's broken" I was told, "and surely you can fix it!". Flattery goes a long way with me.

I was handed a brand new Dell laptop, that was literally broken after the teenage daughter dropped it. The plastic cover, close to the bottom right corner of the screen, was cracked. The other problem was that, after turning on the laptop, it remained stuck in the Window$ vista boot screen - the one with a green progress bar going back and forth, indefinitely.

I forcibly shutdown the laptop with the power button and turned it on again, and tried hitting F8 during the boot process, in order to enter safe-mode. I wasn't quick enough so I had to do it again.

Safe mode usually did the trick for me on XP machines, but it didn't help this time.

The boot process hung while loading crcdisk.sys. I now know that this is a pretty common complaint, but it seems to be caused by several unrelated problems. At the time, however, I could only guess that it's a disk access problem of some kind. Not that it helped - the box was bricked.

I wasn't aware of the fact that I could've tried hitting Alt-F10 during the Vista boot process in order to get to a recovery console. That would've at least allowed me to run chkdsk, or something.

I wasn't aware of Startup Repair.

I'm a Vista newbie.

My next step was to boot the laptop using my live HDD which I usually carry with me. It took two attempts to find how to convince the laptop's BIOS to boot from the USB disk, but I finally succeeded. The plan was to access the internal hard disk and either copy important stuff from it to the live HDD, or burn said data to a writable DVD.

The plan was foiled by the fact that I could not mount the NTFS partition - I was notified that I have to run chkdsk first...

At this point I had to admit failure and suggested to my disappointed audience that the laptop be taken to the repair shop.

When we got back home I was restless. I just had to find a way of making that simple plan of mine work in the future. This got me on a roller-coaster ride of activity: I found myself installing GRUB2, setting up a Window$ live CD, slipstreaming an XP install CD and more. I plan to summarize my efforts in some of the upcoming posts.

In the meanwhile you may want to consider installing the Window$ recovery console on an XP box that you care about, by running the following from the Window$ install CD:
d:\i386\winnt32.exe /cmdcons
I did this on my wife's laptop, and it made me feel all warm and fuzzy inside.

Friday, August 7, 2009

Sharing a Directory with a Windows PC

It's rather easy (see, for example, this thread at the Ubuntu forums):
  1. install samba:
    aptitude install samba
  2. open /etc/samba/smb.conf for editing
  3. add a stanza similar to the following:
    comment = Shared Files
    path = /path/to/shared/files
    browseable = yes
    read only = yes
    valid users = user
  4. save the file
  5. run testparm to verify that the new configuration is valid
  6. add the specified user to samba like this (you'll be prompted fro a password):
    smbpasswd -a user
    (note that the default settings require that this user be a valid Linux user on the machine where the samba daemon is running)
  7. restart the server:
    invoke-rc.d samba restart
  8. you should now be able to access this directory from a Window$ machine as \\computer-name-or-ip\files after providing the specified user's user name and samba password

Happy sharing.

[09 Aug 2009] UPDATE: if you're running a firewall (and you probably should) you'll need to configure it to accept incoming/outgoing SMB traffic.

I use shorewall, and I had to add these lines to /etc/shorewall/rules and then restart the firewall:
SMB/ACCEPT  $FW      loc

Note that this rule opens a lot of ports - you should only allow SMB traffic between hosts you fully trust.