Archive for the 'Linux' Category

Repair Windows MBR with Ubuntu LiveCD

If something happens to your Windows Master Boot Record (MBR), here is a very quick and easy way to restore it with nothing but an Ubuntu LiveCD

WARNING: You are working with your disks in a very direct manner throughout this process. As always, having thorough and recent backups is essential.

  1. Boot into your Ubuntu LiveCD on the offending machine.
  2. Once Ubuntu has started up, go to System > Administration > Software Sources and enable the Universal Repository.
  3. Open a terminal session (Applications > Accessories > Terminal) and type sudo apt-get install ms-sys
  4. Now you need to figure out which partition is the one hosting your Windows operating system. Start by typing sudo fdisk -l in to Terminal window.
  5. From the resultant list of available partitions, you are looking for a partition that says something like:

    /dev/sda1 1 8619 94723115 81 NTFS

    The two important bits are the /dev/sda1 which is the partition label and the NTFS which tells us it is a Windows formatted partition. So, in this example, your Windows partition exists on the drive sda and it is at partition 1.

  6. We nned to fix the MBR on /dev/sda so type sudo ms-sys -m /dev/sda. You will need to change the sda text if your results from step 4 are different.
  7. Remove the LiveCD from the CD drive and reboot the machine. Windows should come back to you.

Of course, you could do this by inserting the correct Windows CD and booting into repair mode but the Ubuntu way doesn’t care about versions and is actually a bit faster.

Run Linux from a USB flash drive

Linux is a relatively lightweight operating system and can be run quite effectively from a USB flash drive. This can be very useful when trying to retrieve files from a PC with a corrupt OS or boot sector. Most PCs manufactured in the last couple of years will allow you to boot from a USB device but you may have to enter the computer’s BIOS to enable this functionality. This tutorial enables you to install, boot and run Ubuntu Linux 7.10 Gutsy Gibbon from a USB flash drive. In addition to installing Ubuntu to the USB device and then booting from it, this also enables you to automatically save your changes and settings back to the flash drive and restore them on each boot using a second persistent partition.

You will need:

  1. Ubuntu 7.10 ISO image
  2. DVD Burner
  3. Blank writeable DVD
  4. 2GB USB flash drive
  5. The computer on which you are working must have internet access

Throughout the following instructions, replace X with your drive letter:

  1. Grab the Ubuntu 7.10 ISO image and burn it to a DVD
  2. Insert the CD and your USB flash drive
  3. Reboot your computer into Ubuntu from the CD
  4. Open a terminal window and type sudo su
  5. Type fdisk -l to list available partitions. Note which device is your flash drive (example: /dev/sda). Throughout these instructions, replace x with your flash drive letter. For example, if your flash drive is sdb, replace x with b.
  6. Type umount /dev/sdx1
  7. Type fdisk /dev/sdx
  8. Type p to show the existing partition and d to delete it
  9. Type p again to show any remaining partitions (if partitions exist, repeat the previous step)
  10. Type n to make a new partition
  11. type p for primary partition
  12. type 1 to make this the first partition
  13. Hit enter to use the default 1st cylinder
  14. Type +750M to set the partition size
  15. Type a to make this partition active
  16. Type 1 to select partition 1
  17. Type t to change the partition filesystem
  18. Type 6 to select the fat16 file
  19. Type n to make another new partition
  20. Type p for primary partition
  21. Type 2 to make this the second partition
  22. Hit enter to use the default cylinder
  23. Hit enter again to use the default last cylinder
  24. Type w to write the new partition table
  25. Type umount /dev/sdx1 to ensure the 1st partition is unmounted
  26. Type mkfs.vfat -F 16 -n ubuntu710 /dev/sdx1 to format the first partition
  27. Type umount /dev/sdx2 just to ensure the 2nd partition is unmounted
  28. Type mkfs.ext2 -b 4096 -L casper-rw /dev/sdx2 to format the second partition
  29. Remove and re-insert your USB flash drive
  30. Type apt-get update
  31. Type apt-get install syslinux mtools
  32. Type syslinux -sf /dev/sdx1
  33. Type cd /cdrom
  34. Type cp -rf casper disctree dists install pics pool preseed .disk isolinux/* md5sum.txt README.diskdefines ubuntu.ico casper/vmlinuz casper/initrd.gz /media/ubuntu710/ (ignore any cannot create symbolic link errors)
  35. Type cd /home/ubuntu
  36. Type wget pendrivelinux.com/downloads/U710fix.zip
  37. Type unzip -o -d /media/ubuntu710/ U710fix.zip
  38. Restart your computer, set your BIOS or Boot Menu to boot from the USB device and reboot again.

You will now have a USB flash drive running Ubuntu 7.10 Gutsy Gibbon that will automatically save your changes, restoring them on boot. If you have trouble getting Ubuntu to boot, your memory stick may have a corrupted Master Boot Record (MBR). To repair the MBR of your USB device, at the terminal type sudo apt-get install lilo followed by lilo -M /dev/sdx (again replacing x with the letter of your flash device).