Monday, January 20, 2014

A Clean Install of a Windows 7 & Ubuntu Dual-Boot System

While writing my last post which was about hibernation, I noticed that Ubuntu cannot mount the Windows partition (or rather, can only mount it as read-only) if Windows was hibernated. This lead me to consider creating a partitioning scheme where Windows is separated from the rest of the files on my hard drive. Rather than playing with the partitions of the hard drive, I decided to do a clean install. While at it, I also purchased an optical drive bay caddy and a 64 gb solid state drive to contain the operating systems. Here's a step-by-step list of what I have done:

  • Step 1: Order the optical drive bay caddy and the solid state drive.

    The optical bays in laptops are usually either 12.7mm or 9.5mm high and contain either a SATA or PATA interface. Upon determining that my laptop has a 9.5mm high optical drive bay with the SATA interface, I ordered one from newmodeus, along with the rubber enclosure and a SATA-to-USB cable so that I can keep using my optical drive as an external drive.

    For the solid state drive, I decided to go with a 64 gb Sandisk Ultra Plus, which is barely enough to contain both Windows 7 and Ubuntu 13.10 after all the updates and such. I would probably buy a 128 gb SSD if I were buying it now.

  • Step 2: Decide how to partition the two hard drives.

    The scheme I wanted consisted of the following:

    1. The Solid State Drive (64 gb):
      1. A small Windows boot partition (NTFS)
      2. The main Windows partition (NTFS)
      3. Ubuntu Partition (Ext4)
      4. Linux swap partition
    2. Secondary Hard Disk (500 gb):
      1. The Windows recovery partition (NTFS)
      2. Ubuntu Live CD partition (Ext4)
      3. A large storage partition for documents (NTFS)
      4. Free space for testing other operating systems and/or Linux distributions

    There will probably be a strong opposition to partitioning this way since the swap partition is located on the SSD, but I want to be able to hibernate and I want the hibernation to be as fast as possible; that is why I am placing the swap partition on the SSD. If I did not care about hibernating, I would probably move the swap partition to the spindle drive and reduce its size considerably.

  • Step 3: Install Windows 7 from the recovery partition.

    After installing the caddy and the disks to the computer and verifying that everything is working, I moved on to install Windows on the solid state drive. Windows 7, along with the drivers and lots of bloatware, is kept on a hidden partition in my hard disk drive (which just became my secondary); so I had to either use recovery DVD's or find some other way.

    No matter which boot order I choose from the BIOS, the computer boots from the secondary hard drive (i.e. the optical drive bay) only if there is nothing installed in the main hard drive slot. Moreover, there is no option in the recovery software to use some other drive as the C drive; so, at the cost of some extra writes (which are not good for SSDs), I decided to copy the recovery partition (around 9 gb) to the end of the SSD (so that I can remove it easily after I am done) using GParted. After marking the partition as bootable, I was able to boot into the recovery partition and install Windows 7 on the drive; however, after Windows was installed, the recovery software could not locate the drivers for the computer (along with the bloatware), because the recovery partition was expected to be in the beginning of the disk, rather than the end. After I moved the recovery partition to the beginning and reboot, I was able to restore the C drive to the original factory condition. The problem now was that I did not want to sacrifice 9 gigabytes of valuable solid state disk space to store the recovery partition (which I maybe use once in a whole year). After erasing the recovery partition and moving the other partitions to the beginning of the disk using GParted, Windows refused to boot (which was predicted by GParted while moving those partitions). (UPDATE: Simply booting the computer with a Windows 7 installation DVD or a rescue CD and choosing the "startup repair" option fixes this error.)

    I decided at this point to boot into the old hard drive and create recovery disks. Before doing this, just out of curiosity, I copied the recovery partition from the secondary hard drive back to the beginning of the SSD and moved all other partitions accordingly to see if Windows would boot again. To my surprise, it did; but I still went ahead and created the recovery disks. After using the recovery software to restore the computer to the factory settings for the third time, I was finally satisfied with the system. I kept the recovery partition without the drivers and bloatware, which reduces the size of it to around 1.5 gb. Now, on the solid state disk, I have a Windows recovery partition, Windows boot partition (system reserved), the main Windows partition (which is 40 gb, the minimum allowed by the recovery software) and around 20 gb of unallocated space to use for Ubuntu.

  • Step 4: Solid State Disk optimization for Windows 7.

    After successfully booting into Windows, I removed the bloatware and followed most of the advice offered in "Sean's Windows 7 Install & Optimization Guide for SSDs & HDDs". Namely, I did the following:

    • Disable System Protection (no restore points)
    • Turn off drive indexing
    • Shrink the page file to 1024 mb (because I got low memory alerts when the page file was 512 mb)
    • Run the update software that comes with the computer (to update drivers for motherboard and SATA controllers, etc.)
    • Run the Windows Update
    • Disable scheduled defragmentation for the SSD
    • Enable write back caching and turnoff windows write-caching buffer flushing for the SSD
    • Disable prefetch and superfetch

  • Step 5: Install Ubuntu 13.10.

    At this point, I decided to install Ubuntu on the SSD. I removed the secondary hard disk and installed the optical drive back because I could not manage to boot the computer from the external optical drive. I also removed the SSD and installed my old hard drive back, because I had the CD image for Ubuntu 13.10 Desktop Edition on that drive. After burning the image to a disk, I went ahead and installed Ubuntu 13.10. After some research, I found out that the partitioning that I described in this post is a little outdated, since it uses the old "ram x2" swap partition size advice and a separate boot partition. Instead, I used the "ram + 1 mb" swap size (because I want to be able to hibernate) and I did not create any separate partition mounted at /boot. The installation went pretty smooth and I had a working dual boot system in no time.

  • Step 6: Solid State Disk optimization for Ubuntu 13.10.

    After logging into Ubuntu and going through with the usual first-boot routines (like removing amazon.com shopping suggestions, enabling the hibernation etc.), I applied this guide for optimization of the SSD under Ubuntu. Here's what I did:

    • Make sure that SATA mode is set to AHCI by running the command "dmesg | grep -i ahci"
    • Do the firmware upgrades for the SSD (I actually need to boot into Windows for this step since the update software is only offered for Windows)
    • Edit fstap to add the "noatime" parameter for mounting the root partition
    • Edit /etc/rc.local to add a trim command which executes on boot
    • Limit swap wear and tame the inode cache (as adviced in the guide)
    • Move the folders for temporary files and system logs to a ramdrive
  • Step 7: Create a partition for the Ubuntu 13.10 Live CD and add a menu entry to GRUB.

    Since I no longer will have an optical drive in my laptop, I decided to have a partition which contains the latest Ubuntu Live CD iso image that I can boot into so that I won't have to re-install the optical driver if I need to boot from the Live CD. It may also prove useful if I need to do a clean install of Ubuntu; several times in the past I messed up the system to the point that a clean install was the only way to recover it. The cd image for the latest version is around 900 megabytes, but I decided to make this partition large enough to contain a DVD (which is 4.7 gigabytes) so that I don't have to resize it in the future.

    To have an option to boot into the Live CD in GRUB, first create an ext4 partition and copy the iso file of the Live CD that you want to boot into to this partition. You shouldn't extract the files from the iso, it will be easier to replace it with other images in the future. Next, edit the file /etc/grub.d/40_custom as a super user (for instance, you can enter gksu gedit /etc/grub.d/40_custom) and add the following to the end after making the appropriate changes:

    menuentry "Saucy Salamander Live CD" {
     set isofile="[Path to the iso file]"
     loopback loop (hdX,Y)$isofile
     linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile noprompt noeject
    initrd (loop)/casper/initrd.lz
     }

    You should enter the full path and the name of the file after the isofile= entry. Also, where it reads (hdX,Y); you should replace X with the drive number and Y with the partition number. Remember that the first hard drive is hd0, not hd1. For example, my iso file is named "ubuntu-13.10-desktop-amd64.iso" and it is located in the root folder of the second partition of the second hard drive; so I enter the following:

    menuentry "Saucy Salamander Live CD" {
     set isofile="/ubuntu-13.10-desktop-amd64.iso"
     loopback loop (hd1,2)$isofile
     linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile noprompt noeject
    initrd (loop)/casper/initrd.lz
     }
  • Final Step: Install the programs and enjoy!.

No comments :

Post a Comment