April 10, 2011
After a number of years, it has finally become time for me to buy a new computer. I wanted a laptop for business reasons, and I also wanted to use Ubuntu Linux as my primary operating system. Although a Mac has an unquantifiable “cool” factor and is the system of choice for many Ruby on Rails and other developers, I ruled it out as too pricey for my budget. Besides, I have become accustomed to Ubuntu’s clean functionality.
I decided not to buy a laptop preloaded with Linux because that would have seriously limited my choices, and also because I might need to have access to a Windows 7 OS in some situations. After some searching, I settled on a Lenovo Ideapad Y560p because it incorporates a fast four core Intel i7 processor and was priced attractively.
I didn’t want to destroy the hidden Windows 7 restore partition and the existing bootloader partition, so that if desired, I could restore the computer to its original configuration at some later time. This coupled with the fact the factory-installed configuration uses all four primary partitions, made installing dual-boot capability more complex than it otherwise might have been.
While this article applies specifically to the Lenovo Y560p, most computers come with a hidden system restore partition and likely a boot partition these days. With suitable modification, these instructions should be applicable to many recent computers. The key is to not touch the bootloader or recovery partitions, nor to change the order or the type of the partitions. Merely shrink one or more of them to make space for the new Linux partitions, which can be created inside the extended partition.
Comments are welcome. Please email me at firstname.lastname@example.org
Following is an overview of the steps I took to accomplish this:
Converting the Lenovo Ideapad Y560p to a dual boot system is complicated by the fact that as factory-configured, the hard drive uses up the entire partition space. A PC’s hard drive can be divided into a maximum of four main partitions, and the Y560p already uses all of them for:
The first partition is the Windows 7 bootloader. It normally boots the Windows 7 OS in the second partition. It also is capable of booting the recovery program in the hidden recovery partition (/dev/sda4) if the recovery button is pressed.
Maintaining the original geometry will maximize the likelihood that Windows 7 and the recovery features will still work after Ubuntu installation. To that end, the following partition changes will be made to provide space for Ubuntu:
1) Substantially compact the Windows 7 OS partition from 420 GB to 40 GB, making 380 GB free space available.
2) Move down the bottom of the extended partition to the new end of Drive C:
3) Ensure that the 20 GB Drive D: data partition remains abutting one end of the extended partition. Move it if necessary.
This provides 380GB free space in the extended partition, into which Ubuntu can be installed.
See Disk Partition Layout — Before and After for more details.
To load Ubuntu, the Windows bootloader will still initially gain control, but it will be given an added option to invoke Ubuntu’s entirely separate GRUB 2 bootloader. This schema where two separate bootloaders are invoked in sequence is known as “chainloading”.
As factory-configured, the Windows bootloader, which resides in the 200 Mb active partition at the beginning of the hard drive, directly boots the Windows 7 OS that resides in the second partition. When Ubuntu is installed, its GRUB 2 bootloader will be installed into the Ubuntu /boot partition, so as to not overwrite the Windows bootloader.
When the GRUB 2 bootloader gains control, it will load Ubuntu. The Windows bootloader will still get control upon power on or a restart, but its “Boot Configuration Data” (BCD) will be modified to give it the option pass control onto the GRUB 2 bootloader. While Windows 7 provides a command line utility to modify the BCD, a free program called EasyBCD will used to perform this.
As is the custom today, Lenovo saves perhaps 50 cents of per unit production costs by not providing separate OS recovery media. Instead the Lenovo One Key Rescue System accessible by pressing the recovery_button can be used to create backup OS restore media. With these disks, the hard drive can be restored to its factory-loaded state regardless of any errors in performing the following steps. Omit this essential step at your own peril!
The program states that either 17 blank CDs or 3 blank DVDs are required. Use DVDs to minimize the possibility of error or losing a disk. The Lenovo DVD drive is said to write either DVD-R or DVD+R media. (I used the DVD+R type.) The completion legend states that the DVDs were written from a “15GB hidden partition”.
If you are paranoid (like I am), you might want to perform a trial boot from the first recovery disk. Just cancel before the first disk is to be restored.
The limited functionality of Windows 7 partition management will be used to perform this step. (While the partition changes could be performed entirely from an Ubuntu “Live CD” session, it’s always best to use an OS’s own utility to manipulate its partition if possible.)
I often keep a USB memory stick plugged into one of the USB ports, but this can be problematic with the Lenovo Y560p, because the default BIOS boot order gives a USB drive higher priority than either the hard drive or DVD drive. In fact, I lost a fair amount of time trying to understand why the Lenovo would repeatedly start but not complete the boot sequence. It turns out that it was trying to boot a non-existent OS from a plugged-in USB memory stick, failing, then trying again. I changed the boot order in the BIOS, and the problem disappeared. I recommend that you do that too.
Another feature (aka “gotcha”) that I encountered was that the Lenovo wouldn’t boot from the DVD drive when I placed the Ubuntu install CD in the drive. (The hard drive has a higher priority than the DVD drive in the BIOS boot menu.) After discovering that pressing the F12 key upon startup displays a BIOS boot menu, where the boot device can be specified, I decided to not touch the DVD drive boot priority.
See Booting Gotchas for more information.
Now that Windows Drive C: has been shrunk ( /dev/sda2 in Linux parlance), there is now about 400 GB free to be used by Ubuntu. But Ubuntu has to be placed in the extended partition (/dev/sda3), which is completely occupied by Windows Drive D: (/dev/sda5). The solution is to move down the extended partition to abut the new end of Drive C: and acquire the free space. Drive D: will remain at the top of the extended partition, abutting the lower end of the hidden recovery partition.
The Gnu GParted Partition Editor will be run within an Ubuntu Live CD session to move the partition.
In order to install Ubuntu, you need either an install CD or DVD. You can download a CD image from ubuntu.com and burn the CD using a CD/DVD drive with write capability. Installing from a CD requires that your computer have (very preferably broadband) Internet access in order to download components from the Ubuntu software repositories. Alternatively, a free DVD which presumably has all required components can ordered from ubuntu.com, but it will take a few weeks to arrive.
The following instructions are for an install CD, but installing from a DVD should be almost identical.
To install Ubuntu you can either continue with the Live CD session or you can reboot the CD. In either case:
Next the partitions which Ubuntu will use must be specified. Because of the special partitioning requirements, it is best to specify this manually rather than let the installer create them automatically. I chose to create only boot, root, and swap partitions. One can get more creative and create separate partitions for some of the directories under the root, but I don’t recommend this, at least not initially. I also chose to allocate only 200 GB to the root directory, leaving about 200 GB free for later expansion.
The boot partition contains the GRUB 2 boot loader, boot configuration files, and the Ubuntu OS images. Supposedly only 100 MB is needed, but the partition is made larger because it will be hard to expand later.
The swap partition supposedly should be 1-1/2 times the size of the main memory (which for my Y560p is 4 GB) Note: You might not be able to hibernate the computer if the swap space is smaller than the main memory.
Everything else goes into the root partition. This puts /home and other hierarchies that could usefully be separated together, but I left over 200 GB free space on my hard drive, allowing me to change this later.
Upon completion, the installer offers the option to either restart or return to “live” session.
Ubuntu has been installed, and it will load if the GRUB 2 bootloader located in the Ubuntu boot partition (/dev/sda6) can get control. But until the Windows bootloader is given an Ubuntu boot option, and it will continue to load only Windows 7. Now we need to modify the Windows “Boot Configuration Data” (BCD) to be able to do exactly that. Windows 7 provides a command line utility to modify the BCD, but using a free program called EasyBCD is more fool-proof.
After getting the Windows 7 bootloader to load the Ubuntu GRUB 2 bootloader, the next step is to make the chained bootloading process (almost) seamless to the user, by presenting the user with only one of the two boot menus. Because GRUB 2 has multiple Linux kernel boot options that may be useful, the Windows 7 boot options will be added to the Ubuntu GRUB 2 menu, and the Windows menu will be set to load the default GRUB 2 bootloader (almost) instantaneously. (Note: This feature is TO BE ADDED.)
EasyBCD is a free program written by Mahmoud Al-Qudsi. It can be downloaded from the NeoSmart Technologies web site.
From within Windows 7:
From within Windows 7:
At this point, we now have a completely functional if somewhat awkward two-stage procedure for booting Windows or Linux. Windows can be booted from the first (Windows) menu. To boot Ubuntu, select Ubuntu, which loads the second (Ubuntu) menu. Select the first (Ubuntu) menu item.
Note: The defaults are set up to boot Ubuntu after a sixteen second delay if no action is taken.
Upon computer power up or restart, the Windows bootloader gains control. A two item menu is presented:
As configured, the Ubuntu GRUB 2 loader runs after six seconds delay. Press an arrow or other key to prevent this.
The Ubuntu selection of the Windows 7 bootloader chainloads Ubuntu’s GRUB 2 bootloader and presents its own menu with the following selections:
The “Windows Vista (loader)” selection actually boots the recovery program. The “Windows 7 (loader)” selection does not boot Windows 7, but merely cycles back to present the Windows boot menu again.
Note: The “recover” button still works to boot the “Lenovo One Key Rescue System 7.0” recovery program when the power is off. (Though you wouldn’t normally use it, because restoring a partition will totally wipe out the Ubuntu OS that we labored so mightily to install.) However, we have met the goal of installing Ubuntu without disabling any of the factory-installed Windows functionality.
Note: Instructions for performing the following are not yet available.
In order to make the bootloading procedure appear seamless, we need to change both the Windows and Ubuntu boot configurations.
GRUB 2 configuration changes:
From Windows, rerun EasyBCD to set the timeout to zero. Now the Windows menu will be invisible (or immediately fly by), and all boot selections are available in the GRUB 2 menu.
While the required changes to the GRUB 2 menu are seemingly simple, figuring out the idiosyncratic procedure for creating menu components which are then compiled into a single GRUB 2 configuration file is now more complex. These instructions will be added later. However I didn’t want to wait to post this article.
This completes the installation of Ubuntu onto the Lenovo Y560p laptop computer, while maintaining Windows 7 dual boot capability. Hopefully this will help to get started with Ubuntu Linux without needing to abandon a Windows 7 safety net.
The Gnu Linux GParted graphical partition editor was used to obtain the following partition info.
Partition File System Label Size Used Flags /dev/sda1 ntfs 200.00 MiB 66.92 MiB boot -- The bootloader partition /dev/sda2 ntfs 420.33 GiB 19.77 GiB -- Windows 7 Drive C: - contains the OS & applications /dev/sda3 extended 30.48 GiB -- lba /dev/sda5 ntfs LENOVO 30.48 GiB 3.01 GiB -- Windows 7 Drive D: - contains only device drivers /dev/sda4 ntfs LENOVO_PART 14.75 GiB 9.18 GiB diag -- The hidden recovery partition
Note: GParted reports the size of the entire drive (/dev/sda/) as 465.76 GiB. The “Disk Utility” application claims “500 GiB == 500,107,862,106 bytes”.
Partition File Sys Mount Pt/Label Size Used Flags /dev/sda1 ntfs 200.00 MiB 66.92 MiB boot /dev/sda2 ntfs 39.06 GiB 21.06 GiB /dev/sda3 extended 411.75 GiB -- lba /dev/sda6 ext2 /boot 285.00 MiB 41.61 MiB /dev/sda8 ext4 / 186.26 GiB 5.59 GiB unallocated 189.13 GiB /dev/sda7 linux-swap 5.59 GiB unallocated 5.00 MiB /dev/sda5 ntfs LENOVO 30.48 GiB 3.00 GiB /dev/sda4 ntfs LENOVO_PART 14.75 GiB 9.18 GiB diag ("Disk Utility" describes as "Compaq diagnostics" 0x12)
There are two “features” of the default Lenovo BIOS boot order that may seem like “gotchas” to the unwary:
1. The DVD drive has a lower priority than the IDE hard drive, meaning that even with a CD in the drive, the computer will boot from the hard disk. This is OK — if you want to boot from the DVD drive, repeatedly press F12 during startup, and the BIOS will present a boot device menu. Here you can select the DVD drive.
2. With the default BIOS settings, a USB device has a higher priority than the IDE hard drive, meaning that the computer will attempt to boot from a USB memory stick if one is inserted. This is NOT OK for me, since I often leave a one inserted into a USB port. (I was baffled why the computer would repeatedly go through the boot cycle until I realized it was attempting to boot a non-existent OS from the USB memory stick. The solution is to press F2 repeatedly upon startup to go into the BIOS and move the IDE drive up to the very first device in boot order. (Select the Boot tab and follow instructions.)
The Lenovo Y560p has a small “recovery” button located immediately above the power button on the left side. If this button is pressed when the power is off, the bootloader loads the “Lenovo One Key Rescue System 7.0” recovery program (actually a special version of Windows Vista) stored in the hidden partition. The recovery program provides three options:
Pressing the recovery button while Windows 7 is running also starts the recovery program. Pressing it while Ubuntu is running has no effect.
The GParted graphical partition editor can be run from the Ubuntu Live CD Session to obtain partition information prior to installing Ubuntu. However, GParted is not one of the default applications in the installed Ubuntu OS and needs to be specifically installed.
(Not necessary when running an Ubuntu Live CD session)
Note: The first user to be set up becomes the administrator by default
The partition data for the hard disk(s) as presented above is displayed.
The recovery system claims that it verifies each recovery disk just after writing it. Still, if you’re like me, you might want to perform a trial boot to heighten your confidence that the recovery disks will work if you need them.
The Ubuntu OS is capable of putting the Lenovo Y560p into hibernation mode (aka “put to sleep”), depending upon how it is configured in the System | Power Management dialog. (The default is after 30 min. inactivity for on battery power only.) To restore the OS, press the power button to turn on the computer. Upon startup, the computer executes the normal boot sequence with both boot manager menus, but when Ubuntu loads, the previous session is restored
I selected the “encrypt home directory option”, and upon the first login, a dialog box is presented offering to disclose a strong passphrase that can be used to recover the data manually in special cases. (Normally logging in with the user password is sufficient.) This information can also be recovered by running ‘ecryptfs-unwrap-passphrase’ from a command line.
I found the following web resources helpful in preparing this article: