Sunday, May 12, 2013

Installing Ubuntu alongside Windows

For those Windows users who have discovered what Linux has to offer, but for one reason or another are not ready to completely abandon Windows, dual-booting between the two operating systems is one method of keeping a foot in both worlds. And to help those users, this article presents a step-by-step guide on how to configure dual-booting between Windows 7 and Ubuntu 11.04 on a computer with one hard drive. The same steps may be used to dual-boot both between both systems on a computer with two hard drives.
In attempting to dual-boot between Windows 7 and Ubuntu 11.04, you will either install Windows anew, then install Ubuntu 11.04 alongside it, or install Ubuntu 11.04 alongside an existing installation of Windows. This tutorial uses as example, a case of installing Ubuntu 11.04 on an existing installation of Windows 7.
As shown in the image below, the existing installation of Windows 7 used for this tutorial has three primary partitions. And because of the limitations of the MBR partitioning scheme, only one primary partition is available for installing Ubuntu 11.04. By using an extended partition, we can configure as many partitions as we need for Ubuntu.
dualBoot3
To begin, boot the computer using a Ubuntu 11.04 CD or DVD. At the disk partitioning step, the installer will present several options. Because the installer will not automatically partition and configure the free space, using the installer’s advanced partitioning tool is the only method of creating the necessary partitions. To launch the advanced tool, select the “Something else” option, the click Forward.
dualBoot4
This is Ubuntu’s advanced partitioning tool and the detected partitions. The first three partitions are obviously the ntfs partitions that we saw in the first image. Because there are three existing primary partition, the last partition will have to be an extended partition, under which logical partitions for installation of Ubuntu will be configured.
By default, Ubuntu’s installer configures two partitions – the first for /, the root directory, and the second for Swap. When creating partitions for installing any desktop Linux distribution, my recommendation is to create the following four partitions:

  • /boot, the boot partition. This is where programs critical for booting the system will reside.
  • /, the root directory. The bulk of the programs used for running the system will be installed here.
  • Swap, unformatted disk space for use as virtual memory.
  • /home, the partition where your home directory will be located. In the course of using the system, files and folders you create will reside in various folders here.
So, to start setting up these partitions, select the free space and click on Add. Note that this step will have to be repeated for all the partitions.
dualBoot5
 
The first partition will be for /boot. When setting up an LVM-based system using an Alternate Installer ISO image, the default disk space allocated to /boot is 258 MB. However, only about 22 MB of that is used, so anything thing between that size range will do. For this tutorial, the default will be used. The mount point will, of course, be /boot. The default file system is ext2. OK.
dualBoot6
The second partition will be for Swap. It is possible to install Ubuntu without Swap. However, if you attempt to do that, the installer will try to discourage you with the following warning:
swapwarn
For the record, I have been able to install Ubuntu 11.04 successfully without Swap. The sky has not fallen yet, but I have not tried to put the system in Suspend or Hibernate mode. In any case, save yourself a load of trouble and configure Swap. The suggested size for Swap is 2000 MB. Select “swap area” from the “Use as” dropdown menu. OK.
dualBoot7
The third partition will be for /, the root directory. The default journaling file system on Ubuntu 11.04 is ext4. You may stick with it or choose another journaling file system available. Btrfs is supported, but this partitioning scheme is not for btrfs. If you are interested, how to install Ubuntu 11.04 on a btrfs file system is a good place to start.
The installer recommends a minimum of 4.4 GB for Ubuntu 11.04, but on a new installation, less than 3 GB of disk space allocated to / is used. Note that as you install additional applications after installation, disk space used will grow, so be generous here. I think 10 GB should be more than enough. OK.
dualBoot8
The last partition will be for /home. The file system is ext4, and you may allocate all available disk space to it. OK.
dualBoot9
All the partitions have been configured. You may continue with the rest of the installation. But before you do, decide where you want to install GRUB, the boot loader. You may install it in the Master Boot Record (MBR), the default, or in the boot partition (/dev/sda5 in this example). A good case can be made for either choice.
If you install GRUB in the MBR, it will overwrite Windows’ boot programs. This is the most common and requires no other configuration on your part. However, upgrading or reinstalling Windows, or even installing a Service Pack can overwrite certain aspects of GRUB. Restoring GRUB is not a very difficult task, but you can save yourself the trouble by installing GRUB in the boot partition of Ubuntu. This is the recommended method because it completely separate the two operating systems, even as they co-exist on the same disk. It does requires additional configuration on your part. That, however, is nothing compared to the potential headache of the other option.
For this tutorial, I will follow my recommendation and install GRUB in /dev/sda5, the boot partition. Note that the version of GRUB used by Ubuntu 11.04 is GRUB 2.
dualBoot10
After installation and reboot, the computer will reboot into Windows. The final task then is to add an entry for Ubuntu in the boot menu of Windows 7. For that, the easiest program to use is EasyBCD, a free program by NeoSmart Technologies. Download and install it like you would any Windows 7 application. Start it and click on the Add New Entry tab, then on the Linux/BSD tab. From the “Type” dropdown menu, select “GRUB 2,” the version of GRUB used by Ubuntu 11.04. Click on the “Add Entry” button. Click on Edit Boot Menu tab to view the new configuration.
dualBoot12
 
These are two entries you will see every time you boot the computer. The default is Window 7, but you can change it to Ubuntu 11.04 if you like. Exit EasyBCD and reboot.
dualBoot13
This is the boot menu you will see.
dualBoot14
And this, when you attempt to boot into Ubuntu. Note: If at any time you decide to have GRUB be responsible for dual-booting, you can do so easily. Just log into Ubuntu and write GRUB to the Master Boot Record, or MBR. And if you want to switch back to Windows’ boot manager, log into Windows 7, start EasyBCD and use it to overwrite GRUB.
dualBoot15

Restore GRUB2 after installing Windows

How I Restored GRUB2 after a Windows 7 Install. GRUB2 (Grand Unified Bootloader)  is a universal bootloader used by Ubuntu and other Linux Distributions. If you have a Linux Distribution installed on a partition, and attempt to  install Windows alongside it, your GRUB bootloader will be overwritten by the Windows bootloader, and your computer will only boot into Windows.

Recovering the GRUB2 Bootloader after a Windows Install  is simple. When finished, your Bootloader should detect all installed Operating Systems and automatically add a bootable menu item for each of them.
Note: This GRUB2 Installation process assumes that a Linux Partition still exists. If you overwrote Linux with Windows, this tutorial will not work for you, as there is no Linux system to recover boot.
How to Restore GRUB2 after installing Windows:

  1. Boot from an Ubuntu Live CD or Live USB
  2. Once up and running, Open a Terminal Open a Terminal
  3. Type sudo su (press enter after typing each command)
  4. Type fdisk -l Type sudo su and then fdisk -l
  5. Note which device contains your Linux partition (IE: /dev/sda1) Locate your Linux Device
  6. Type mount /dev/sdx# /mnt (replacing x# with your actual device and partition number)
  7. Type mount --bind /dev /mnt/dev
  8. Type mount --bind /proc /mnt/proc
  9. Type cp /etc/resolv.conf /mnt/etc/resolv.conf
  10. Type chroot /mnt mount and chroot
  11. Type grub-install --recheck /dev/sdx (replacing x with your actual device)
  12. Type reboot (to reboot your PC) Install grub 2 and reboot
Make sure to remove your Live USB or CD. Upon reboot you should be presented with a GRUB2 menu. However, Windows is missing. Now, I show you how to fix that.
Making GRUB 2 detect Windows Installs:
  1. Proceed to boot into your Linux environment.
  2. Open a terminal and type sudo update-grub (enter your root password when prompted) sudo update-grub
If all went well, grub should have updated it’s menu entries to reflect what it detected. Including existing Windows partitions.

Cool Linux Tips And Tricks

It’s Sunday and that means we’re all ready for the weekend. But that also means we’re ready for some fun. Because of that I thought it would be fitting to do an article on some of the cooler Linux tips and tricks that I have come across over the years. This article will be a bit of mish-mash of topics…but well worth the read. So, without further adieu, let’s cry havoc and let loose the dogs of war!



Collaborate with the screen command
Let’s say you and your co-worker are both working on debugging an application and your partner has run into a snag. Instead of having to march back and forth between offices, or leaving the comfort of your own chair (you lazy thing), you can log onto your co-workers machine and collaborate! Here’s how it works. Both machines will be Linux machines and both will have ssh accessibility. If you need to help your co-worker out follow these steps:

  1. Secure shell into your friends machine…the only catch is, you have to log on with his username/password.
  2. Issue the command screen -s NAME Where NAME is any name you want.
Now your co-worker has to open up a terminal window and issue the command screen -x NAME Where NAME is the same name you used in your command. Now whenever either of you type in your screen both of you will see what is going on at the same time.
To detach yourself from this session you have to hit <Ctrl>a and then d. That means hold down <Ctrl>, hit a, and then hit d. You will be released from the session.


Execute files as programs in GNOME

Say you have that killer bash script you use for something tucked away in your home directory. You can run that script by open up a terminal window and issuing the command to run the script, OR…you can set up Nautilus so that files can be run with a simple double click. Now, use caution with this, because it can open up security issues. But if you know you are safe (are you ever really safe?) you can set this feature.
To set this up open up Nautilus to the directory that will house the script and then right-click the script and select Properties. In this new window click on the Permission tab and then check the box for Execute. Close the Properties window and then, back in Nautilus, double click that script and see what happens…it should execute.


Double your copy/paste pleasure
You have have heard me mention before how Linux has a cool way to copy paste. You simply highlight what you want to copy with the left mouse button (click and drag to select) and then click the middle mouse button to paste. But did you know that form of copy/paste does not effect the traditional <Ctrl>c/<Ctrl>v? That’s right. So effectively you have a primary and secondary buffer for copy/paste. You can highlight section A with the left mouse button drag/highlight method and then copy section B with the standard <Ctrl>c method. Now you two different pieces of text to paste – one with the middle mouse button and the other with <Ctrl>v! Sweet.


Final thoughts
There’s your fun friday Linux tricks. Now, go out and enjoy the weekend! Or just sit at home and continue to rock away on your Linux box.