Archive for the 'Tech' Category

Note: I've reorganized this site to use tags; the category archive remains to support old links. Only posts prior to April, 2006 are categorized. Tag Archive »

HOWTO Recover Files from a Non-Bootable Windows PC using Ubuntu Live

Update: fixed typos in steps 3 & 8.

My preaching the joys of Mac to all my coworkers has claimed another victim; John, who I share my office with, purchase a shiny new 20″ iMac G5 two days ago. John asked me for a way to get some files off his old Windows PC without booting Windows, because his Windows install is very flaky, and doesn’t like to boot anymore. I developed the following procedure using a Ubuntu Live CD.

This wasn’t as easy as I’d expected. Ubuntu Live is great, but it’s not designed for system recovery. I had 2 yr old copy of Knoppix in the office, but I couldn’t get everything working, so I tried a brand new Ubuntu Live CD. With a little work I got things going.

The Premise: Boot a Windows PC using a Ubuntu Live CD. Mount the Windows drive and share it using Windows File Sharing (aka Samba). I chose to share with Samba because just about everything can be a client. Windows, Mac OS X, and most Unixen/Linuxen can retrieve files from Samba shares.

The Requirements: Ubuntu Live CD, network connection between the unbootable machine and the machine that will recover the files, and a live internet connection (proxied is ok). The internet connection is required because the Live CD is missing a key piece of software, which we can get with a net connection. Other LiveCDs may not have this restriction (a recent Knoppix, perhaps, but that’s another HOWTO). Note that if your recovery system is a Mac, you don’t even need a router/switch to connect the machines… the Mac’s ethernet port is auto-sensing, and will reverse directions if connected to a PC’s ethernet card with a standard RJ-45 cable. Sweet.

The Steps:

  1. Boot from a Ubuntu Live CD. This method was tested with Ubuntu 5.10 “Breezy Badger”. It should work with Ubuntu 5.4, “Hoary Hedgehog” as well, although I have not (yet) tested this.

  2. Open a Terminal window. From the menus at the top of the screen, choose Applications | Accessories | Terminal.

    Terminal Window Screenshot

  3. Now we need to create a mount point for the Windows drive. We’ll use the traditional location of /mnt.

    cd /mnt
    sudo mkdir windrive
    
  4. Run the Ubuntu Disks Manager. From the system menu bar, choose System | Administration | Disks. In the Disks Manager, find the Hard Disk icon that represents your Windows drive. It is usually /dev/hda. You may see other Hard Disks that you don’t recognize, these are virtual devices created by the LiveCD.

    Disks Manager Disk List Screenshot

  5. On the partitions tab, locate your Windows partition. For many systems, there will be only one partition to choose. The Partition Type should be (something like) NTFS, FAT, or FAT32. In the Access Path text box, enter /mnt/windrive. Make a note of the “Device” value. In the example below (and on many machines), its /dev/hda1. Click Enable.

    Disks Manager Partition List Screenshot

  6. Return to the terminal window. Type mount and press enter. In the output generated, look for the device name from the last step, and note the value after the word “type”. Pay special attention to spelling, case, etc. In the example below, our device /dev/hda1 has a type of ntfs.

    Checking Partition Type Screenshot

  7. Although the windows drive is now mounted, we can’t use it yet to share, because it’s only accessible to the root user, due to the default mount behavior for Windows drives. We need to remount the drive ourselves and override this. First, return to the Disks Manager, and Click Disable. Close Disks Manager.

  8. In the terminal window again, mount the drive manually. Be sure to substitute your device name if it’s not /dev/hda1, and to substitue your filesystem type, if it’s not ntfs. The ls command should show you the contents of your Windows drive.

    sudo mount -t ntfs /dev/hda1 /mnt/windrive -o "umask=022"
    ls windrive
    
  9. So far, so good- we can read the contents of the Windows drive as the default user (named, oddly enough, ubuntu). Now we have to enable Windows File Sharing, aka Samba. The bad news is, the LiveCD doesn’t include the smbd, the Samba Daemon. The good news is, you can install it automatically, and in memory (since we’re running from CD). If you access the web via a proxy server, step 10 is for you. If not, skip ahead to step 11.

  10. (Proxy users only) We need to tell Ubuntu’s package system how to use your proxy to access the Internets. From the system menu bar, choose System | Administration | Synaptic Package Manager. From Synaptic’s menu bar, choose Settings | Preferences. On the Network tab, enter your proxy settings. Click OK, and quit Synaptic.

    Synaptic Network Preferences Screenshot

  11. From the system menu bar, choose System | Administration | Shared Folders. The Shared Folders app will start, and warn you that no sharing services are installed. Check the box for Samba, and click Apply. An installation progress dialog will appear; when the installation is complete, you will see the message “Changes Applied”. Close the dialog.

    Sharing Services Dialog Screenshot

    Installation Dialog - Changes Applied Screenshot

  12. In the Sharing window, choose Add. In the Share Folder dialog that appears, change the path to /mnt/windrive. Set the name to Windrive, and check the “Allow browsing folder” box. Click ok.

    Share Folder Dialog Screenshot

  13. We’ve told the system to share the Windows drive via Windows File Sharing, but Samba will prompt for a user name and password that don’t exist. Let’s fix that. Return to the terminal window, and run a couple of commands. After the first command, you’ll be asked for a new SMB password. This is the password you’ll use from another computer to access the share. Use something you’ll remember, this is just a temporary hack. I used ‘test’.

    sudo smbpasswd -a ubuntu
    sudo sh -c "echo 'ubuntu=\"ubuntu\"' > /etc/samba/smbusers"
    

    Samba credentials commands Screenshot

  14. We’re ready to test. The easiest way to connect to your machine is using the IP address. You can check your IP with the ifconfig command. Look for a line that begins “inet addr”.

    ifconfig Screenshot

  15. Test it! From Windows, you can use Start | Run… and enter “\172.17.25.46\windrive” (change the IP, of course). When prompted for credentials, user name is “ubuntu”, password is “test” (or whatever you used in step 13).

    Windows Run Dialog Screenshot

    Success

You can now access the files on the Windows drive of the PC running Ubunutu Live. I’ll try to get a Mac OS X screen shot up later.