Saturday, October 12, 2013

Linux Dual Booting Adventures: Part 3 - Installing Linux (Tutorial for HP Envy 17-jXXX)

In this post, I'm going to try to document the process I used for installing Linux Mint 15 (Cinnamon) on my HP Envy 17-j007tx alongside the preinstalled Windows 8. Hopefully this will be useful to someone out there, just like the post that I based much of this process on helped me (cheers to Larry Mulcahy!)

I'll start with a condensed version of the process I employed. Along the way, various missteps taken will be noted/numbered, and discussed at the end.

Ok, let's get started!


Machine Setup
I'll assume that by now you've played around with Windows 8 for a little while, and have at least ended up activating it when the machine started up for the first time.

Before starting the dual boot install process, you'll need to do the following things:
1) BIOS Configuration
2) HP Recovery Media Creation
3) Check the exact specs of all hardware on machine (and the driver versions used)
4) Windows Preparation - Files backup, Fast Boot disable, and Disk Defragment

BIOS Configuration
  1. Shut down the computer
  2. Press the power button
  3. Before the light on the power button comes up, start mashing the F10 or Esc keys madly until the BIOS comes up. If you see the HP logo, you've failed, and will need to try again, more aggressively...
  4. The system uses an "Insyde BIOS". You want to navigate to the third tab - System Configuration, where most of the relevant settings are located. The bar at the bottom provides the relevant keys that you should use to do this.
  5. Set "Action Keys" to "<Disabled>". This is used to make it so that the F-keys work normally, so that pressing F5 within many applications works as the refresh hotkey instead of the "toggle keyboard backlight".
  6. Set "Secure Boot" to "<Disabled>". This is important, otherwise your computer will complain, and will probably make an awful noise.
  7. Leave "Legacy Mode" on "<Disabled>". DO NOT TOUCH IT. (Note: It will give you a big ugly warning about the consequences if you do accidentally modify it, and for this to work, you definitely don't want to modify it)
  8. Go to "Boot Options"
  9. Adjust the "Boot Order" list so that the list looks something like - the important point is that drives with bootable media are checked before the HD gets read:
    1. "CD/DVD Drive"
    2. "USB/Flash Drive"
    3. "Internal Disk" ...
  10. Set "Boot Timeout" (or whatever it is) from "0 sec" to "5 sec" (or perhaps it was 10)
  11. Exit the BIOS, and confirm that you want to save your changes.
  12. The machine should now restart, and boot back into Windows. (NOTE: the HP logo will now take 5-10 seconds to show up; during that time, you are now free to press F10 or other boot-keys such as F9 - used later - at a more leisurely pace)

HP Recovery Media Creation
Creating the HP Recovery Media (i.e. basically, a set of discs which can be used to restore the machine to factory-new condition) is quite a straightforward process. Simply click on the HP icon on the taskbar, go to "HP Recovery Manager" (first icon), confirm the UAC prompt, and click on"Create Recovery Media" (1st item, 3rd column). Then, follow the instructions on screen.

However, before you go ahead and start burning, there are a few caveats to be aware of:
1) You can only (officially) burn one set of the disks, though that doesn't stop you from using disk copying software on those disks later I guess ;)
2) Number of discs required: 6 x DVD-R's  or 3 x Double Layer DVD's, for a total of 24-25 GB
3) The disc burning process is SLOW. On my machine, it took over 2 hours, or roughly 20 minutes per disc (there are 3 stages for each disc)

However, burning off a set of these discs is definitely something you'll want to do, as it gives you a bit of a safety cushion if you end up bricking the machine by overwriting some or other bootloader and corrupting some other partitions when repartitioning... Just sayin'...


System Specs
The three things you probably need to be most concerned about are:
1) wireless adapter/drivers,
2) integrated and/or dedicated graphics cards,
3) touchpad.

In my case, I had the following items (your mileage may vary, since there are 2 options for each of the graphics cards, and up to 5 for the wifi as per the HP Maintenance Manual):
1) Ralink RT 3290 (802.11 bgn)
2) Intel HD Graphics 4600 (default for monitor) + NVidia GeForce 740M
3) Synaptics Clickpad (no separate/physical buttons for left/right mouse buts)






You'll also want to know the screen resolution just in case (i.e. 1600x900 at 60Hz - alternative frequency of 40Hz also possible).

Finally, to prevent any nasty surprises, you'll want to check on how many partitions the machine currently has (Win-X (Windows Quick Admin Menu) -> Disk Management):

By default, your machine should look something like this:
sda1 = Partition 1 (400MB) = Windows Recovery Partition
sda2 = Partition 2 (260MB) = EFI System Partition (i.e. the system's bootloader lives here)
sda3 = Partition 3 (~100MB - Not shown) = Either Windows Bootloader, Windows Swap, or "Windows Reserved" (for the core of the OS itself).
sda4 = Partition 4 (> 900GB) = Windows (C:\ drive) - This is where Windows and all your files live
sda5 = Partition 5 (24.6 GB) = HP Recovery Partition (D:\ drive) - This is the on-disk copy of your recovery DVD's that you burnt. AFAIK, it's not strictly necessary to ensure that this remains on your HD for the recovery media to work, but if you don't desperately need the space it's perfectly fine to leave it alone (that's what I did)

In the procedure below, we're only going to split up sda4 into several smaller partitions that we're going to install Linux in. Also note that the disk here uses GPT (Guid Partitioning Table) instead of the old MBR (Master Boot Record - from MSDOS days).


Windows Preparation
Finally, you'll probably want to back up anything you might have installed/downloaded on the machine before continuing.

Now, some of the threads I've read have recommended doing a full-disk backup (i.e. low-level byte-for-byte copy) that you can just write directly back onto the disk later if it all turns to custard. Certainly, if you've got relatively more stuff on the machine than I had (only about 70GB including vendor-installed cruft, but most of that stuff could either be reinstalled, redownloaded from a cloud/central remote server, or could be zipped up and dumped on a flash-drive to be dumped back on disk post-restore), you may want to go for this option. Or, if you really desperately don't won't to lose Windows 8. In my case, I wanted to keep it around "just in case" (since I knew there were some hardware support issues) but also since there are some things I occasionally need to use which are windows only (besides, the Win8 license was included as part of the price of the machine, so I might as well keep a working/licensed copy in case I need to use it for battle-honing some research prototypes in future). Anyways, I ended up just making a copy of all the installers I downloaded, along with any config files I created, and a copies of a few projects I was working on (even though these were already backed up via Git).


Fast Boot
Apparently, Windows 8 achieves faster startup/shutdown speeds by actually going into Hibernation when we chose to power off. Now, ordinarily this would be fine, but since we are trying to get as much space as possible for the dual-boot, we want to eliminate any other sources of large unmovable files in the Windows partition (lest they be referred to by some absolute addresses, thus rendering the machine unbootable later).

To disable Fast Boot:
1) Win-X -> Power Options
2) Select "Choose what the Power Button does" in the LHS pane (2nd item)
3) Click "Change settings that are currently unavailable" (beside the shield, right under the description text at the top), and confirm the UAC request
4) Disable the "Turn on fast startup (recommended)" option
5) Click "Save Changes" (and confirm if necessary)

Defragment and Disk Integrity Check
1) Win-X -> Disk Management
2) Right click on the Windows Partition -> Properties
3) Go to the Tools Tab
4) Click "Optimise"
5) Click "Defragment" - This could take 10-30 minutes, and has 7-8 stages...



Bootable Linux ISO Preparation
Instructions:
1) Go to the appropriate distro's site
2) Select the appropriate ISO for your machine - 32 bit for 32 bit machines, 64 bit for 64 bit machines, and select one with the desktop environment you want.
3) Download from the nearest mirror. It should be a 900mb or so download.
4) Verify the integrity of the disk by computing an MD5 hash against the one on the website  (see Python script below for one way to do it; other ways include downloading various executables from various websites...)
5) Burn the ISO using appropriate software - The Cyberlink Media Suite that HP bundles does the trick. Just use it to open/mount the disk image to read it (strangely, that will cause it to poll the DVD drive once), and it should open. Then, from there poke around for a button to burn the image to a blank DVD-R.

My Setup:
- Linux Mint 64-bit, Cinnamon Edition

Python Script for Checking MD5 Hashes

import hashlib

def md5_for_file(path, block_size=256*128, hr=False):
    '''
    Block size directly depends on the block size of your filesystem
    to avoid performances issues
    Here I have blocks of 4096 octets (Default NTFS)
    '''
    md5 = hashlib.md5()
    with open(path,'rb') as f:
        for chunk in iter(lambda: f.read(block_size), b''):
             md5.update(chunk)
    if hr:
        return md5.hexdigest()
    return md5.digest()
   

official_md5 = "2396a39e802a0463bf1727acd72d0700"

fpath = "C:\\Users\\Joshua\\Downloads\\linuxmint-15-cinnamon-dvd-64bit.iso"
fhash = md5_for_file(fpath, hr=True)

print "Hashes equal = %s" % (official_md5 == fhash)
print "fhash = %s" % (fhash)



Starting the Live Disc
By this point, you should now have a bootable Live CD/DVD with Linux Mint (or your preferred distro on it), and a machine that will be able to boot this disc (and have Linux installed on it later).

1) Restart the Machine with the Disc Loaded
Since it isn't really possible to open the disc drive tray when the machine is powered off, you'll need to be in Windows when you open the tray and put the disc in.

Restart the machine yourself, or follow the prompts that you get from the Mint helper that runs when you autorun the disc on Windows. (Beware though, that mint4win is apparently dangerous in combination with Win8 and/or UEFI systems, and should be avoided. AFAIK, it may/may not be based on wubi, which is definitely known to be problematic).

2) Booting into Linux from GRUB(2)
If you've done everything right, when you reboot, you should be presented with a black screen, with white/gray lettering on it, and a list of items drawn inside a simple box. The top of the screen should say something to the effect of "GRUB 2.xxx-ubuntu" or similar.

Unless you have a radically different setup (mainly, no NVidia card, or perhaps an ATI instead), your mileage may vary a bit here, and you may be able to boot into Linux with either one of the first two entries. But, chances are, neither is going to work - i.e. you'll be left staring at a black screen, with an unresponsive machine that you'll have to hard reset (i.e. hold down the power button until you hear a "blip" sound, and then power it back up again).

To get Linux booting from here:
2.1) With either "Start Linux Mint" or "Start Linux Mint (Compatability Mode)" selected (both of these work if you apply the tweaks below, but if the first gives you trouble, stick with the second for now), press 'e' on your keyboard
2.2) You're now presented with a screen that contains 2-3 long command lines. These are essentially the commands that GRUB will execute in order to boot up Linux. Of particular interest is the second line - the one that starts with "linux" and ends with "--" (and is followed by a line with "initram.d" or something similar)
2.3) Navigate the cursor to just before the "--". Do this by pressing the down-arrow 2-3 times, Home/End, and left-arrow a few times.
2.4) Append the following text before the "--", leaving a space before what you type and after what you type:
acpi_backlight=vendor  nouveau.modeset=1

The first bit of this tells the Linux kernel about your screen's backlight (so that it gets initialised on startup, and you aren't left with a dim login screen or similar at any point in time), while the second part tells Linux Mint NOT to use the default open-source drivers for NVidia graphics cards (which ends up fighting with the Intel integrated card for control of the monitor; remember that the Intel is the only one which really has "write access" to it - at least from what I gather about the problems here). With these two tweaks, everything should work, though when you boot into Linux, your NVidia graphics card won't be usable yet - getting that working is something to worry about AFTER you've managed to get the dual boot setup working!

2.5) Press F10 to boot Linux using your modified boot instructions. I know what the info text at the bottom of the screen says about Ctrl-X, but from experience, that does not work at all. Only F10 (boot using modified config) and Esc (go back to GRUB menu) work.

2.6) All going well, you'll either get a Mint logo in the middle of your screen which gets brighter (Standard option) or pages of terminal text blasting past (Compatability Mode), followed by a screen where a cursor appears on a black screen, followed by the Mint desktop appearing before your eyes.

Testing The Live Disc
Congratulations! You've finally landed in Linux land.

Have a good poke around to see if everything seems to work fairly well with your hardware, and/or whether the operating system feels like something you'd want to spend time working with. (If not, then simply find a way to shut down the machine, eject the disc, destroy said disc - or give it to the neighbours - and get another distro to try again).

Some things I'd recommend trying:
1) From the tray bar, find the "connection" icon, and try to connect to your Wifi network. In fact, check whether it even shows any Wifi networks in range! If your Wifi access point is visible, try connecting to it. Once you've found that this has succeeded, click the connection icon again, go to "Network Settings", and click on the arrow on the far right of the name beside your Wifi access point, and check on the connection speed for your network to ensure that it doesn't look too hideous.

If at any stage something went wrong here, make a note to do some reading up about the relevant issues here to make a judgement whether the issues are surmountable given current packages. More likely than not (and in the general spirit of this tutorial), things should work perfectly fine (at least at first).

2) Fire up Firefox, and start trying to access various common sites you frequently access. Start conservatively with only a single tab access at a time, then move up to doing several in parallel (as you'd usually do things).

Also, try connecting to IRC to check whether your connection is stable enough to sustain it.

3) Make sure you visit a page where there are a number of photos you've taken and know the "real/intended" colours of (the more photos there on that page, and of different colours, the better). Use this to evaluate how accurate the colour calibration seems to be. It's all fixable later, but it helps to have a gauge on how much work you're going to have in front of you.

4) Visit Youtube and play a few clips. In particular, check how well sound works (chances are, it may sound a bit hollow), and how well the system in general copes. Check volume and backlight controls.

5) Fire up LibreOffice Writer, and start typing some text. Note how well (or badly the trackpad performs during serious typing - i.e. does palm contact cause any major issues). Also, check that both mouse buttons on the clickpad work. Try scrolling and/or zooming for good measure. And perhaps fire up the mouse/trackpad config settings (Mint Menu -> System Settings -> (System Settings) -> Mouse and Trackpad), and see the effects that these have on the usability.

6) Fire up GIMP, and plug in a tablet (if you have one). Check that this works (it probably will).

7) Close the lid of the laptop, check that it goes into standby (after 5-10 seconds), wait another few minutes, then open up the lid again and check that it resumes correctly. Repeat again with leaving it for 1-2 hours. Ensure that all devices (including Wifi connection) still work after resuming from standby. If not, you'll once again have some more things to check on later.

8) Put the machine into standby from the gui - Menu -> Power -> Standby.  Check the various ways you can bring it back from standby and that everything works fine that way.

9) Plug in a USB stick, and check that you can access your files on it, save stuff on there, unplug the device safely, then plug it back in again after a few minutes (and have everything work perfectly) once again.

10) Fire up the console, and type glxgears . Ensure that something shows up, and check on the frame rate (it should be 60fps, since you're running on the Intel only). Double check this by checking on the "System Information" tool.

11) Fire up System Monitor and check how many CPU's and amount of RAM it's detected. If you've fired up Task Manager in Windows, also note the difference in "idle" RAM usage ;)

12) Try restarting and shutting down the machine as well. Check that it doesn't throw a hissy fit (it won't) on exit - more likely than not, it will tell you to remove the Live Disc before pressing ENTER though.

13) In the terminal, run "sudo gparted". Check on what partitions Linux sees on your disk, comparing that to what you saw in Windows. Chances are, things may look even more hideous than before!


That above was my testing regime for the Linux Mint Live Disc. In fact, I went through this multiple times - on my first 2 attempts, the Wifi was really flaky, and ended up getting slower and slower (or simply refusing to communicate with the rest of the internet). Yet, today, it has been relatively well behaved (when doing a pre-install test, but also now that I've got it booted on my machine). (Cue conspiracy theories about the spooks getting suspicious about a new and unidentified/uncleared "Loonix" box trying access the internet from this account)

Depending on what other issues you run into, you may need to spend some time reading through whether all of those issues seem surmountable and/or whether you think you're willing to wade through all of those fixes. Weighing things up at this point is perhaps what'll take the most time...


Installing Linux Dual Boot
Ok, so if you're still reading, you've probably decided to take the plunge. We'll start by booting into the Live CD as before (and checking that everything works, for a last-check before installing).

Starting the Install Process
To start installing Linux Mint, simply click on the "Install Linux Mint" icon on the desktop, and follow the instructions for the first few screens. They should be pretty self explanatory. For further details about this, the instructions on the Linux Mint pages spell this all out pretty clearly.

Partitioning - Choosing the Installation Scheme
The last two steps of the install process (before it goes away and starts modifying your disk, downloading stuff, and generally "installing Linux"), are dedicated to partitioning - or the figuring out how Linux will be stored on your computer. This is the part where we really get down to business.

On the first page, it will ask you how you would like to install Linux:
1) Perform an "automatic" install alongside Windows 8
2) Completely blast away Windows 8
3) "Something Else" - AKA I want to manually decide how big my partitions are, and which partitions the installer can safely manipulate.

For this tutorial, we're going to go with 3, since I wanted to keep my Linux system files and my personal files separate. The advantage of this approach is that if at a future stage I look into upgrading the distro to another one (very unlikely, since, prior to this change, I've generally only upgraded operating systems when forced to by a change of machine so far) my files should be relatively safe from having to be copied back in full as a result of the partition they were on getting fully wiped and reinstalled.

AFAIK, the "automatic" install will create two partitions: a "boot" partition and a "linux" partition (containing the entire Linux system). In retrospect, there's probably not much wrong that can happen from doing that which wouldn't require the sorts of intervention we're having to do now anyways (after all, it *is* provided as the default), except that it doesn't quite provide as nice a base system as we'd like. While many other tutorials don't explain why they tell people not to use this, I will here: while it is a good basic setup, it doesn't let me create the setup I want. Hence, in this tutorial, we won't be using this. (Caution: If you do proceed to go with this option instead, you're on your own a bit if/when some other problems crop up)

Partitioning - Setting up the Partitions Manually
Now, when we advance to the next screen, we are presented with the "Advanced Partitioning Tool", which is basically the same as GParted in many ways (it probably shares the same code!).

The first thing to do is to take stock of what partitions we have before us. To make things easier to understand, I'll repeat these again from the earlier list:
sda1 = Partition 1 (400MB) = Windows Recovery Partition
sda2 = Partition 2 (260MB) = EFI System Partition (i.e. the system's bootloader lives here)
sda3 = Partition 3 (~100MB) = Some unknown windows partition
sda4 = Partition 4 (> 900GB) = Windows (C:\ drive) - This is where windows currently lives. <--- X
sda5 = Partition 5 (24.6 GB) = HP Recovery Partition (D:\ drive)

Of all these partitions, the most important one from our perspective is sda4 (aka "Windows C:\"). This is the largest one (over 900 GB), since this is the partition assigned for Windows and all your files when working in Windows. To get Linux on this hard drive, we're going to need to shrink down this Windows partition only to free up some space, which we will then proceed to use to create the new partitions that Linux will live in.

Every other partition on the disk will be left alone!

----

So, before we start resizing and playing with partitions, let's stop and think a bit about how much space we want to have.

Since I'm planning to eventually move to Linux nearly full-time, and I will end up having a substantial photo collection within that (after struggling for weeks to reign in the colour management under Windows, I've just about given up), while still needing to retain enough space on Windows so that it won't get itself into grief, I figured that it would be a 200 GB : 700 GB split (Win : Linux).

Of that 700 for Linux, you need at least 20 GB for the core Linux system (10GB absolute minimum, 10GB extra for some slack/growth of extra applications and packages you'll inevitably need to install), and some swap space (with 12GB RAM, standard recommendation seems to be 0.5 x Total RAM, and 1.5 x Total RAM for hibernation; not creating swap space will result in the installer throwing warnings at you, but the same can't be said of boot partitions).

In the end, I ended up settling on 50GB for Linux core, ~12 GB for swap (compromise between having full requirement for hibernation and hardly any to save disk space - while I don't currently use hibernation, I can't say I won't use it in the future), and the rest for Home/Files (700 - 50 -12 = 682).

Once we know the amount of space required, it's important to note that the installer only lets you set values in terms of MB. So, you'll need to multiply those sizes by 1024. (Despite doing this though, in practice, you'll see that Windows and Linux report these sizes differently, often by a noticable margin of several GB).

----

Now that we know how much space we need, it's time to setup the required partitions. At the end of this process, we want to end up with something like:
sda1 = Partition 1 (400MB) = Windows Recovery Partition [ntfs?]
sda2 = Partition 2 (260MB) = EFI System Partition (i.e. the system's bootloader lives here) [fat32]
sda3 = Partition 3 (~100MB) = Some unknown windows partition [fat32]
sda4 = Partition 4 (200GB)   = Windows (C:\ drive) [ntfs] <--- NOW SMALLER
sda6 = Partition 6 (50GB)     = Linux Root [ext4]              <--- NEW PARTITION FOR LINUX
sda7 = Partition 7 (~690GB) = Linux Home [ext4]             <-- NEW PARTITION FOR LINUX
sda8 = Partition 8 (12GB)     = Linux Swap [swap]             <-- NEW PARTITION FOR LINUX
sda5 = Partition 5 (24.6 GB) = HP Recovery Partition (D:\ drive) [ntfs]

This can be accomplished by performing the following steps:
1) Select sda4
2) Click "Change" and adjust the value in the "Amount to Reduce By" box until the value in the last box (showing the new value) approaches 204800 (200 * 1024). Click Confirm to instantly resize the partition (*1).
3) sda4 should now be followed by a large block of "Free Space"
4) Select the "free space" and press "+" to add a new partition using this space
5) Set the size of this partition to 51200 (50 * 1024), leave the format type as "ext4" (Linux default), and set the "Mount Point" to "/" (i.e. Linux Root). Confirm (and this partition is added as sda6)
6) Select the "free space" following sda6, and press "+" to add a new partition in this space
7) Set the size of this second partition to 698597, leave format type as "ext4", and set the "Mount Point" to "/home". Confirm (and this partition is added as sda7).
8) Select the "free space" following sda7, and press "+" to add a new partition in this space
9) Leave the partition size alone (so that it will take all available space left), and change the format type to "Swap". Mount Point disappears at this point. Confirm (and this partition is added as sda8).

If at any point in this process, you discover that you made a mistake (namely, miscalculating the sizes of various partitions - especially of sda7, which you'll discover when trying to add sda8), simply start from the rightmost offending partition and press the "-" to unallocate it. Although the installer appears to immediately apply the changes to the partition table (and especially if it goes about resizing any existing partitions), with new partitions, it seems that it doesn't actually format or "wipe" those for their final usage until you're done with this step in the wizard and press "Install Now".

(*NOTE 1: Pressing "Confirm" in Step 2 will resize the partition on disk at this point, and may take up to a minute or so to fully finish. While some tutorials may say you need to use the Windows tool to do this, and others say to use GParted first, it's perfectly fine to let the installer do this. In fact, the Windows tool will probably fail to go below 400GB, since Windows often stores some large unmovable system files in the middle of the disk - space that it can't exactly recover/move while the operating system is loaded. Using GParted is effectively the same as using the installer to do the job, except that you have to do things in a separate pass.)

Once you've checked that everything looks fine, you can press "Install Now".

Rest of Installation
The rest of the installation process is relatively straightforward and laid back. Fully installing Mint will take between around 30 minutes at this point, but is heavily dependent on having a stable internet connection (since it starts downloading "Language Packs" and a few other support packages). If the installer does get stuck here, you can click the "Skip" button to get it to move on past this roadblock.

While you're waiting, there are a few more customisation steps to perform. Namely, the choice of the all important "Computer Name", "User Name", and "Password" (it includes one of those password strength indicators). It does in fact provide an automatic generic name choice, which somehow manages to magically detect the type of computer (brand + model) and shoves your name/username on to the front of that. In my case, I ended up coming up with a whimsical name (for the first time, having previous rued the fact that when setting up Windows on the same machine, I ended up going for a rather bland name), which was a combination of spur-of-the-moment + an attempt at creating a systematic scheme I can use for all future machines.

Anyways, once the installer done, it will present a message box telling you that it's done, and to restart the computer (removing the live disc) when you're ready. At this point, you should restart the computer as instructed.

Getting Linux to Dual Boot with Windows
First Reboot
Chances are that when it restarts, the system will boot straight in to Windows 8. In fact, for the first time after the partition resize, this is a very good thing, and you'll want to do this a few more times for good measure, so that Windows can get its affairs in order (aka "adjust" to having its turf "lobbed off by a higher power" - nothing that people in Christchurch aren't used to seeing under the government agency in charge of powering the rebuild...)

Getting Back into Linux
To cut the story short, installing and using EasyBCD at this point is useless and may actually contribute to accidental bricking of your machine. That's because, if you're not careful, you will end up accidentally deleting the original entries as well when you attempt to remove your failed attempt to add an entry for Linux. At least with the way we've done things here, it appears that we didn't actually end up installing a valid GRUB2 install (possibly related to not creating a separate boot partition for Linux), hence the EasyBCD Linux fix won't actually be able to find anything to load.

What you want to do instead, is something like this:
1) Using the Boot Menu (F9), use the "Boot From EFI File" option to get into Linux
2) Install "Boot Repair" and Run It
3) Rejoice that you've now got a working Linux/Win8 Dual Boot

Booting from EFI File
On HP laptops, to get back into your installed Linux, follow the following steps:
1) Start computer from scratch
2) Press F9 before the Windows loader come up to get the "Boot Menu"
3) This has 2 options: "Boot From EFI File" and "Continue Normally" (or something along those lines). Select "Boot From EFI File" and press Enter.
4) You should now be greeted by a screen with just a single entry on it: "No Volume Label {... some nasty GUID text ...}" or similar. Press Enter to browse into that.
5) Select the "EFI" folder
6) You should now have a screen with several folders such as "Windows 8", "HP Recovery" (?), etc. and "linuxmint". Select "linuxmint"
7) Select the "efi64" folder
8) Select the "grubx64.efi" file and press Enter

You should now be greeted with a GRUB Menu. This has multiple entries in it, but the ones of interest to you are:
1) Start Linux Mint
2) Start Linux Mint -- Recovery

Either one would probably be fine (though IIRC, I used the first). However, due to our hardware limitations, we MUST remember to edit the GRUB menu in the way described earlier. That is:
1) Press 'e' with the appropriate option selected
2) On the "linux" line, jump to the end of the line (it should say: $vt_handoff), and add our familiar lags to the end of the line. So, the linux line now looks something like:
    linux       ...      acpi_backlight=vendor nouveau.modeset=1 $vt_handoff
3) F10 to boot using the modified commands
4) Mint should now boot from your Hard Drive!

Installing and Running Boot Repair to Fix Your Dual-Boot
1) Bring up Terminal - Wifi settings have been preserved/saved from whatever you were running in the LiveCD
2) sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update
3) sudo apt-get install -y boot-repair && (boot-repair &)
4) You should now get a prompt along the lines of "EFI Detected. Check Options". Dismiss this (and ignore it. I'm guessing that the "options" it refers to are the "Advanced Options" part of the UI. In practice though, all of those looked very scary - some more so than others - but leaving them alone seemed to work perfectly fine)
4) Click "Recommended Repair".
5) The tool will now chug away for a few minutes. Along the way, there will be 2 messages:
     1) "Buggy Kernel"
     2) "Reinstalling GRUB"
6) Done! GRUB should now be set as the default bootloader for the machine. It will provide a link to the log of what it did (here's mine: http://paste.ubuntu.com/6217753/)
7) Restart

GRUB Menu - Post Boot Repair
The GRUB Menu should now come up as soon as you start up. The entries are as follows:
1) Start Linux Mint                               <-- This is the one we still want to use
2) Start Linux Mint -- Recovery
3) Windows 8 UEFI Loader                  <-- This is the original Windows Bootloader (i.e. the one which shows the HP logo)

To get into Linux, we once again have to edit the boot line (but this will be the last time for a while!). Things are slightly different this time in that instead if "$vt_handoff", the end of the linux line is "ro", and there seem to be fewer lines in the boot config altogether (or maybe I've got these the wrong way around). In any case, you'll want to stub in our standard flags before the "ro" for good measure.

Booting Fixes - Permanent Fix
It's not practical to have to keep doing this everytime we launch the machine. The following process solves this problem (and will need to be performed again later, to remove the graphics driver hack in favour of a proper fix, once we install the proper drivers):
1) Using the Package Manager, install "grub-efi-amd64" to get the required config files for grub
2) Using a terminal: gksu gedit /etc/default/grub
3) In GEdit, find the line:
    GRUB_CMDLINE_LINUX=""
4) Change this line to:
     GRUB_CMDLINE_LINUX="acpi_backlight=vendor nouveau.modeset=1"
5) Save the file
6) Now, in the terminal, issue the following command (to rebuild/flush the new GRUB settings):
    sudo grub-mkconfig -o /boot/grub/grub.cfg


Congrats! You should now have a HP Envy 17 that dual boots Windows 8 and Linux Mint 15!

Sure, there are still a lot of things you'll need to tweak to get things totally functional - namely, configuring Beats Audio to use all speakers, installing the proper drivers for the NVidia graphics card, configuring the touchpad to be less sensitive - especially to palm-rest issues, and making sure the Wifi indicator light shows the right color. But, tackling those will have to wait for another post (and when I've actually managed to solve these issues!)


----

Various Notes on Pain/Pressure Points During This Process
As promised, here is the extra commentary on some areas where things are a bit tricky:
1) Should I still go ahead with this? I've got a Windows 8 setup which is fully functional with the hardware I've got. Albeit, it imposes quite a hefty productivity cost on using it, and the flat-design of most parts of the UI are a real eyesore to look at everyday (though installing that Aero Glass plugin with an appropriate custom theme has brought it back up to an acceptable visual standard - at least partially). The setup I'm going to be installing though is only partially functional, with many drivers either debunked or needing some tweaks to be fully functional, while in the long run I'll benefit from having a system that has several important productivity benefits.
2) Install alongside vs Something Else - No-one really explains what the "Install alongside" really does, but all the tutorials out there just jump straight ahead and say to not use it without explaining why, it's really hard for a newbie to tell if it's "safe" to do so or not
3) When to resize the Windows Partition, and How to Do It? This is something that I agonised over, since there's quite a lot of conflicting info out there on this. At the end of the day, in my case it boiled down to Windows failing to do it itself, reading that GParted can apparently safely resize Windows partitions (including defragging them in the process) without hassles - especially many of the "live system" limitations that Windows faces, and ultimately betting on the robustness of the installer ("What the heck... Let's just do it with the installer and we'll see how things go"). Things could have gone very very wrong here very quickly, but they didn't, so things are sweet.
4) Figuring out partition sizes and making mistakes there -  It took a few tries with the partition size assignments to get things right. That's because, the estimates ended up coming out different from what I was predicting using my own calculations. Having created those new partitions, it was initially a bit scary having to then remove them to try again, since the first resize operation had seemed like doing this sort of thing would be quite a big deal.
5) Trying to figure out why on earth the grub booting wasn't working: Was GRUB even installed anywhere? What is the least brittle way of setting these things up, but won't end up costing us a lot in startup speed in the long run? EasyBCD or Boot Repair?  - Other concerns at the time included: "If I do boot repair, it's probably going to end up overwriting the default boot loader with GRUB. What if that munges up and makes the system unbootable?!" -- In the end, things here worked out when it turned out that EasyBCD was useless in the face of the GRUB config problems here, and the nature of the beast forced our hand a bit on this one. Still, it was quite nerve-wracking still.

10 comments:

  1. This is really useful, thanks. I've got about half way through this, but still failing. I'm struggling to get X running - what drivers did you use, did you install any, or did it just work?
    Also getting it locking up in boot unless I use Recovery mode, any ideas?

    ReplyDelete
  2. Scratch that - now working - I think... !

    ReplyDelete
    Replies
    1. Glad to hear that you've got things working :)

      Enjoy!

      Delete
  3. Sincerely grateful for all the research and work you have done to perfect and document the Win8/Linux dual boot for HP's 2013 machines. In a perfect world, HP would encourage and financially support your efforts. On the west coast of Canada, Win7 machines are sold out and Win8 does not interest business or beginners (I'm teaching seniors how to get started with computers). We have no choice but to dual boot with Linux or completely replace Win8.

    Followed your documentation explicitly and had no trouble dual booting an HP Pavilion 17-e053ca. Linux Mint Mate15-64 was the only live trial that would boot up with sound and Wi-Fi on the Ralink RT-3290 wireless, Realtek HD Audio, Intel HD4600 graphics. (Tried Ubuntu 13.10, Kubuntu 13.10 and Zorin7-64, no audio, only Zorin7 had video)

    I used the Windows Disk Management utility to shrink the (large) Windows partition, trying to keep Win8 from going into a snit! Win8 didn't bat an eyelash.
    Only change to the documentation is:
    Installing and Running Boot Repair to Fix Your Dual-Boot
    3) sudo apt-get install -y boot-repair && (boot_repair &)... SHOULD BE (boot-repair &)

    Inserting a link to Boot-Repair (like Larry did) would also be helpful.

    Again, on behalf of the entire Linux community, my sincerest thanks. If HP and the others really want to sell laptops, one could only hope they read your post and act accordingly. In my opinion, Win8 (specifically forcing a tablet O/S on a half billion desktop users) will be MS's biggest failure to date.

    ReplyDelete
    Replies
    1. Thanks for the kind words and spotting the typo!

      Delete
  4. I have recently purchased hp envy 17-j005tx, which came with windows 8 media. Any advice on upgrading to windows 8.1 and then setting up dual boot?

    Prasanth

    ReplyDelete
    Replies
    1. In theory, there shouldn't be any problems upgrading to 8.1 first, and then setting up dual boot.

      However, if you set up the dual boot under Win 8 then let Windows update to 8.1, then you'll find that your dual boot setup gets broken and cannot be easily fixed (you'll end up having to use F9 on boot to be able to select Grub). I don't recommend doing this - especially not on Christmas Eve (or just before any other holiday period)!

      Delete
  5. I haev an HP Envy M6, and had a hard time dual booting with UEFI. I have documented the process here (Linux Mint):
    http://forums.linuxmint.com/viewtopic.php?f=60&t=166161

    I just want the information out there in case someone else tries to do it. It's not easy.

    ReplyDelete
  6. Thank you, can you please provide me details on system issues you foresee while you install a printer, any external software to be downloaded?

    HP envy 5538 install

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete