Debugging/Single Stepping GCC (GNU C Compiler) with Eclipse

Debugging/Single Stepping GCC (GNU C Compiler) with Eclipse

I am doing the below steps in a Lubuntu running on VirtualBox. I usually do messy things on a virtual machine as it does not disturb my actual OS.

The GCC source code can be downloaded from the official page : http://ftpmirror.gnu.org/gcc/gcc-5.3.0/gcc-5.3.0.tar.bz2

Change directory to where the sources were downloaded. Extract the sources by running the following command in the terminal:

tar jxf gcc-5.3.0.tar.bz2

Install the prerequisites that are required for the gcc build.

cd gcc-5.3.0
./contrib/download_prerequisites

Some other prerequisites might be required to be installed.

sudo apt-get install build-essential gawk m4 gcc-multilib

Create an “objdir” outside the extracted GCC sources and change directory to it.

cd ..
mkdir objdir
cd objdir

Run the following commands to build the GCC (prefix is set so that it does not affect the already installed gcc version) :

$PWD/../gcc-5.3.0/configure --prefix=$HOME/gcc-5.3.0 --enable-languages=c --disable-multilib
make STAGE1_CXXFLAGS="-g -O0" all-stage1
sudo make install

If required install Eclipse with CDT with the following command:

sudo apt-get install eclipse eclipse-cdt eclipse-jdt

Create a new Eclipse project with “Makefile project with existing code”.

MakeFileWithExistingCode

Import the sources :

import

Open the “Debug” perspective:

Perspective

Create a “hello.c” file in your home folder which has to be compiled by the GCC which we have built.
/* Hello World program */
#include <stdio.h>
main()
{
printf(“Hello World”);
}

Create a .gdbinit file in the home folder with the following contents:

set follow-fork-mode child

Create the debug configuration as follows.

DebugConfig_1DebugConfig_2

Select the options related to “Non-Stop mode”, Force thread list..” and “Automatically debug forked…”DebugConfig_3

Begin the debug session by clicking on the bug symbol at the top. The execution stops at the main function of the gcc driver.

debug_1

Put a breakpoint in the actual c compiler which the gcc driver calls. The file is at gcc-5.3.0/gcc/main.c.

debug_2

Run the code further and it will hit the breakpoint that was set in the c compiler.  Here you are debugging/single stepping the gnu c compiler.

Learning to drive in India

Learning to drive in India :

I was already 30 years young by the time I decided to learn driving.  This is quite late as the driving license in India can be obtained at 18. But during my college days I could not afford to join driving classes and I am not the kind of person who would ask around so that someone would lend their vehicle to me to learn driving.  So this is how I went about learning to drive.

Step 1 : 

First step is to buy a second hand car. I bought a second hand Tata nano. This was for several reasons.

TataNano

  1. I did not want to spend a lot on a car on which I would be learning to drive. Learning to drive can punish a car, especially the clutch and the engine.
  2. It is a small car so it would be easy to judge distances.
  3. It is a very basic car which has no power steering,  no ABS, and a small engine. Hence if you can drive this you can drive almost any other thing.
  4. It has very good mileage hence I can drive a lot for practice without making a hole in my pocket.
  5. It would be my second car of the house in the future when I buy a bigger car. I am wary of motor bikes.

Don’t postpone this step to a later date its always better to have your own car if you want to learn driving quickly. Get someone who knows about cars to help you out with this step.

Step 2:

Enroll into a driving school. Choose a driving school that is professional and teaches you dedicatedly for minimum 20 hours. I stress dedicatedly because some driving schools combine multiple pupils during on-road driving classes. You along with the instructor should be the only people in the driving school car. Learn in a car with lesser power like Maruti Alto or 800. Cars with powerful engines do not need to have good clutch/accelerator coordination. Learning the clutch/accelerator coordination early is always good. The driving school should arrange for you learners driving license (LL) and the coveted driving license.

Ask them to specifically teach you bumper to bumper traffic driving and uphill driving. These are very important skills.

Step 3 :

Driving you own car independently. This is much more challenging than it seems. In a driving school the instructor has controls and can brake/clutch the car in case of emergencies. There are no such arrangements when you drive your own car. Hence get to an empty flat ground along with someone who knows driving and practice the following.

  1. Getting off from a stationary position. This requires some practice in small power engine cars. A good Clutch/Accelerator coordination is requires. The normal technique is give press the accelerator gently until you hear the engine rev and then release the clutch very very slowly. The very very slow part is very very important. This makes the car move smoothly without any jerks. Remember try this on a flat surface and not on an incline.
  2. Learn to brake gently. Feel the amount of pressure required to get the vehicle to slow down and stop. This is very important. Practice this a lot. At slow speeds (First Gear) the clutch should be pressed completely while braking. Not doing this will stall the car. At high speeds first brake until the car slows down and then press the clutch completely just before the car stops. Also remember that there are different kinds of brake technologies and hence braking require slight adjustments when driving different cars. Hence always feel the brakes every time you drive a different car.  The clutch connect the engine to the wheels. Pressing the clutch disconnects the engine from the vehicle. Hence while braking and shifting the clutch has to be pressed.
  3. Shifting gears upwards :Read the vehicle manual and find out the correct speed for each gear. Always start on the first gear no matter how powerful the engine is.  Accelerate the vehicle to the optimum speed for the gear before and then shift the gear with the clutch pressed. Release the clutch gently.
  4. Shifting gears downwards: Slow down the car by gently applying the brake. Now shift the gear downward while completely pressing the clutch. Once the gear is shifted release the clutch slowly. Lower the gear slower should be the clutch release. If the car jerks then the clutch release is not slow enough.
  5. Steering control : Make markings on the ground and learn to steer the vehicle between these markings. Understand that the steering response is different at different speeds.
  6. Parking : Make markings similar to a car park and learn to park the vehicle correctly between the markings. Learn forward and reverse parking. Also learn parallel parking.

Practise the above steps until you feel comfortable while doing it.

The above steps should make you feel comfortable while driving on a flat road. One of the challenging aspects of driving is driving uphill (climbing). Find a place that has a incline and enough space before and after the incline for safety. Try to drive the car uphill on first gear and stop by pressing the brake  when the car is on the incline. Do not let go the brake, doing so will make the car roll back. Now with the brake pressed slowly release the clutch partially until you hear the engine rev and the car vibrate slightly. This is called the clutch bite point. Now release the brake with the clutch still at the bite point and press the accelerator gently and release the clutch. The car should move forward. This step requires a lot of practice. The goal is to see that the car does not roll back.  Once you have mastered this step you are good to drive on road.

Some safety tips:

  1. Keep adequate distance between vehicles on the road. This gives reaction time to avert accidents. The distance should be larger when it’s raining and during the night.
  2. Have patience. Be nice to two wheelers, pedestrians and other vehicles. By hurrying you only save a few minutes to destination. So do not risk yours and others lives for these few minutes.
  3. There is nothing called as a perfect driver. A person who claims this is a fool. Every situation on the road is different. Hence please do not assume that once you have mastered the mechanics of a car you can do anything on the road.
  4. The car is a big wild killing machine. Hence do not be complacent when driving one.
  5. If you like racing find a racing track. Do not do it on the roads.
  6. Do not jump traffic signals. This is very dangerous and cause most of the accidents.
  7. Do not honk unless it is absolutely necessary as in case of taking a turn and warning other drivers of impending dangers.
  8. Learn how to operate the wipers and the different lights.
  9. Signal well in advance before changing lanes and taking turns.
  10. Do not stop suddenly even if someone in the car says so.
  11. Do not make sudden and surprising moves.
  12. Always anticipate difference scenarios.
  13. When tired take rest. Do not drive continuously for more than 2 hours.
  14. If sleepy do not drive. All it takes is a fraction of a second.
  15. Do not get frustrated because of other arrogant drivers.
  16. Check the tyres before driving.
  17. Wear seat belts.
  18. Put the L board when learning to drive.

It takes months before you can drive naturally on the roads. Don’t worry if the car stalls. Be calm. There will be a lot of honking from behind but ignore them. The more you drive the more comfortable the driving will be. There is no substitute for practise.

Raspberry Pi Private Cloud (NAS), Time Machine OSX (Yosemite)

Raspberry Pi Private Cloud (NAS), Time Machine OSX (Yosemite)

The intention is to create a private cloud at home (Within the range of your router). The cloud hosts the TIme Machine and generic storage area for photos and documents. The generic storage should be read/write compatible to Linux and OSX.

The following are required:

Raspberry Pi (Model B) ( Running Raspbian Wheezy, connected to the network, with keyboard and monitor). The procedure to get your PI running is available here.

  1. External hard disk with power supply. (I have : Verbatim 1 TB)IMG_2617

I have two laptops one is a MacBook Pro ( running OSX Yosemite ) and the other is a Toshiba (running Fedora 20).

Procedure on the Mac : Connect the external hard disk to the MacBook Pro. I have made two partitions of size 333 GB (partition name : timemachine )and 666 GB (partition name : cloud) on my external Hard Drive. The partitioning is done using the “Disk Utility” application (OSX). The file system type chosen is “Mac OS extended (journaled)” (HFS+) for both the partitions.

Run the below command on the terminal to make the OSX recognize non AFP volumes.

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Procedure on the Pi :
Now connect the External Hard Drive to the Pi.
Install the hfs+ driver.

sudo apt-get install hfsprogs

Create two directories and mount the drives. In my case sda1 was created for Time Machine and sda2 for the generic storage. To find out device names of the external hard drive run the command “lsblk”.

sudo mkdir /home/timemachine
sudo chmod 777 /home/timemachine
sudo mkdir /home/cloud
sudo chomd 777 /home/cloud
sudo mount -t hfsplus -o remount,force,rw /dev/sda1 /home/timemachine
sudo mount -t hfsplus -o remount,force,rw /dev/sda2 /home/cloud

Update the fstab so that the mount happens automatically during boot.

sudo echo "/dev/sda1       /home/timemachine hfsplus  force,rw  0  0" >> /etc/fstab
sudo echo "/dev/sda2       /home/cloud   hfsplus    force,rw 0  0" >> /etc/fstab

Create a user (For egs: cloud), a group (For egs : mycloud) and choose a password (and remember them!!!).

sudo useradd cloud
sudo groupadd mycloud
sudo useradd -gmycloud cloud
sudo passwd cloud
sudo chown cloud /home/timemachine
sudo chown cloud /home/mycloud

Install samba and netalink:

sudo apt-get install samba samba-common-bin
sudo apt-get install netatalk

Configure samba client:

sudo nano /etc/samba/smb.conf

Add the below text at the end of the file. “valid users” should have the name of the group you created:

[cloud]
  comment = Cloud
  path = /home/cloud
  valid users = @mycloud
  read only = no

Configure the netatalk.

sudo nano /etc/afp.conf

Add the below text to afp.conf:

[Global]
 mimic model = TimeCapsule6,106
 log level = default:warn
 log file = /var/log/afpd.log

[TimeMachine]
 path = /home/timemachine/
 valid users = cloud
 time machine = yes
sudo echo "/home/timemachine \"Time Machine\" options:tm" >> /etc/netatalk/AppleVolumes.default

restart samba and netatalk and make it start at boot.

sudo service netatalk restart
sudo /etc/init.d/samba restart
sudo update-rc.d netatalk defaults

Now our private cloud is ready.

To access the private cloud from MacBook Pro:
To access the “general storage” disk on our private cloud open the Finder and select “connect to server”.
Screen Shot 2014-11-05 at 21.20.10
Next type in the IP address of the Raspberry Pi (The ifconfig command on the Pi should display the IP address). Do not forget the prefix “smb://” before the IP address. Type in the user name and the password that was created previously.

Screen Shot 2014-11-05 at 21.21.21

For time machine :
To access the “Time Machine” disk on our private cloud open the Finder and select “connect to server”.
Screen Shot 2014-11-05 at 21.20.10
Next type in the IP address of the Raspberry Pi (The ifconfig command on the Pi should display the IP address). Do not forget the prefix “afp://” before the IP address. Type in the user name and the password that was created previously.

Screen Shot 2014-11-06 at 21.35.22
Open Time Machine and press “select disk”. The Time Machine created on our private cloud should be visible. Now you can backup your Mac to this Time Machine Disk on the cloud. It should start creating a sparse bundle. The first backup takes a long time (more than a day) but the next ones will be faster.

Access the private cloud from Fedora :

Open  “Files” window and click on “connect to server”.

Screenshot from 2014-11-07 08:47:44

Put in the Raspberry Pi IP address followed by “smb://”. Type in the user name and the password that was created previously.

GRUB2 : MBR (Master Boot Record)

GRUB2 : Classic Generic MBR (Master Boot Record):

In a Personal Computer (PC) the microprocessor (such as intel x86) execute the instructions collectively called software programs. Software programs can be the operating system or application software.  The Software programs are stored in the non-volatile memories such as Hard Disk. The software programs are loaded (copied) into RAM and the microprocessor fetches instructions from here for execution. Of course the microprocessor can also execute software programs stored in CD-ROM, Flash Drives etc. But here we will consider the case of hard disk. The microprocessor needs a defined start point for execution of software. This defined start point is provided by the firmware in a ROM (Read Only Memory) chip on the motherboard.  The firmware executes after a power on begining at a particular fixed (hardwired) address (“FFFF:0000). The firmware might either be the legacy BIOS or adhering to the newer UEFI specification (In this post I only consider the legacy BIOS MBR). The firmware tests and initializes the hardware components of the PC and finally transfers the execution to the software stored in the hard disk. We are going to see how this transfer of execution from the firmware to this software is facilitated in the legacy BIOS system. In my system I have the CrunchBang 11 “Waldorf” Linux distro using the classical generic MBR.

drawing

The firmware copies the MBR in the first sector of the hard disk to the RAM location starting from 0000:7C00. The microprocessor execution is transferred to this RAM address.  The MBR has a size of 512 bytes.

To see the MBR on your PC run the following linux commands. The first command creates a file mbr.bin with the MBR contents and the second command displays the contents. The dd command can be very dangerous hence run it as exactly mentioned here. In my case the drive name is sda.

dd if=/dev/sda of=mbr.bin bs=512 count=1
hexdump -C mbr.bin

The classic generic MBR has first 446 bytes of Boot Code followed by 64 bytes of partition table and 2 byte signature (0x55AA).
If the output of the hexdump command begins with “eb 63 90” the PC might be having the classic generic MBR with the GRUB2 boot loader.

The 446 byte boot code has the BIOS parameter block and the address of the next stage of the GRUB2 boot loader. The BIOS parameter block begins at an offset of 4 bytes and ends at an offset of 0x5a. The next 2 bytes has the kernel address. This is the RAM address where the next stage of the GRUB2 boot loader is copied from the hard disk for execution, The next 8 bytes have the sector address of the next stage of the GRUB2 boot loader in the hard disk.

The partition table begins at the offset 0x1be. Each partition entry in the partition table is of the size 16 bytes. Hence the classic generic MBR supports only 4 primary partition.

The source code for the GRUB2 can be obtained from here.  The piece of code that goes to the Boot Sector is /Grub/grub-core/boot/i386/pc/boot.S.

This post only discusses the GRUB2 Classic MBR which is common on PCs that run the classic BIOS firmware. Newer PCs might use UEFI compatible firmware, hence the classic MBR is not required.

 

Dual Boot Fedora 20 Kali Linux UEFI

Dual Boot Fedora 20 Kali Linux UEFI

I have already got my Toshiba Ultra Book U840W-x0110 laptop running Fedora 20. This post is about getting the Kali Linux distro to dual boot with Fedora. I have created a Kali Live CD by downloading the ISO image from the official site.

The laptop hard disk size is 500GB. In my installation I had allocated 200GB for the Fedora installation. Hence the remaining approx. 300GB is free for Kali Linux.

The Toshiba Ultra Book U840W-x0110 laptop has UEFI boot enabled by default. The laptop could not directly boot Kali Linux live CD. This is because Kali Linux does not support UEFI boot. Hence to boot Kali Live CD we need to change the UEFI settings of the laptop. We need to make the laptop boot in the legacy BIOS interface (CSM Boot).

  1. Restart the laptop and hold the F12 key. In the Boot Menu navigate using the arrow keys to the <Enter Setup>. Under “Advanced” tab enter “System Configuration”. Here change the “Boot Mode” to “CSM Boot”. Press F10 to save and exit.
  2. Now the Kali Linux Live CD should boot with a loud annoying beep.  Trigger the installation by navigating to the “Install” option.
    IMG_2612
  3. Select the installation language, Location and the Keyboard in the subsequent windows.
  4. For the network interface I connected the internet via the Ethernet cable. Somehow the WiFi didn’t seem to work.
  5. Enter the host name of your choice.
  6. Enter a domain Name.
  7. Provide and verify the root password.
  8. Select the time zone.
  9. Select “Automatic Partition with the remaining free space” for installing Kali Linux in the remaining free space of the hard disk.
  10. Continue with the installation until the below window for GRUB boot loader appears. Do not install the GRUB loader. Press the escape key to do this.IMG_2613
  11. The below window should appear.
    IMG_2614
  12. Select “Continue without boot loader”. The below window should appear. Note down the partition. This is important for GRUB configuration. In my case it is sda4. Finish the installation.
    IMG_2615
  13. Now we need to boot into fedora again. For this we have to enable UEFI again. Follow step 1 but enable UEFI boot this time.
  14. Once in Fedora edit the 40_custom file. Run the below command in the terminal as root.
    gedit /etc/grub.d/40_custom
  15. Add a entry for the recently installed Kali Linux. The 40_custom file should look as below.  In my case I had installed Kali Linux on sda4. Hence the root is also set to (hd0,4).
    #!/bin/sh
    exec tail -n +3 $0
    # This file provides an easy way to add custom menu entries.  Simply type the
    # menu entries you want to add after this comment.  Be careful not to change
    # the 'exec tail' line above.
    menuentry "Kali Linux" {
        set root=(hd0,4)
        linuxefi /boot/vmlinuz-3.14-kali1-amd64 root=/dev/sda4 ro quiet splash
        initrdefi /boot/initrd.img-3.14-kali1-amd64
    }
    
  16. Now run the below command to update the GRUB menu. During the next boot the GRUB menu should show an entry for Kali Linux.
    grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

Indian perspective:Rich Dad Poor Dad:Real Estate

I recently happen to read “Rich Dad Poor Dad”. Although I do not completely accept everything in the book it really got me thinking about personal finance. The book’s main emphasis is on having more assets than liabilities.  Until I read this book I thought I clearly knew what these two words “Assets” and “Liabilities” meant. My understanding was that “Asset” is something that is thought to increase its value in time and liability is the opposite. But the book goes a little further by adding that a good asset should generate income along with increase in value. A real estate property bought for a small amount during an economic slowdown becomes an asset when the economic booms again if it generates income via rent. Similarly an automobile , bought with a big EMI, that is rarely used by the owner becomes a liability.

The crowd mentality among majority of India’s software professionals is that any real estate is an asset. This triggers a mad drive to get hold of a real estate property. Some go beyond their means to buy really expensive real estate of small size. People spend a big part of their income paying EMI’s to the bank. Hoping for the day where the value of their investment grows many fold. Some other buy real estate property at far off places where there is less chances of infrastructure development. There is a huge risk involved in this. One of them would be that the real estate prices in the area would already have saturated during the time of purchase. Also one has to keep in mind if the price (not value) does really go high will somebody buy this small piece of real estate in the future. Remember asset is something that has to start giving you returns in the near or far future. If it fails to do so then you know. Another fact that is emphasised in the book is that self-occupied real estate is not really an asset as it does not generate income.

In order to make profit with real estate one has to come really early to the party and sell the property before it saturates. Otherwise you will be stuck with a liability rather than an asset. A commodity is not necessarily an asset to everyone for some it can be a liability as well. Hence choose your assets carefully. Do thorough home work before choosing to buy any commodity.

If you don’t find a good investment do not rush. Keep the money in the bank. Create a Fixed Deposit (Choose the right bank!!!). Even though it does not give the hope of a big return it is still safe and your money grows gradually. When you find a commodity that assures return for your buck go for it.

Coming back to the book,  “Rich Dad Poor Dad” makes a very good effort in explaining what assets are and how should one choose assets.

Win 8.1 upgrade removes Arch-Linux Grub menu

Win 8.1 upgrade removes Arch-Linux Grub menu

I have a Toshiba Ultra Book U840W-x0110. I have had this laptop dual-boot Windows 8.0 and Arch-Linux. Recently I was offered a free update to Windows 8.1. Since it was free it blocked the logic out of my thought process. I decided to go for this update and after some 2 hours the update to Windows 8.1 was complete. SInce I was working on Windows a restart was always on the cards.  During the restart I observed that there was no grub2 menu. The laptop was directly booting into Windows 8.1.

First I was under the impression that the Windows 8.1 update has overwritten the previous grub2 installation. So I booted up my laptop with the Arch Linux CD. But reinstalling grub2 did not change anything. So it is concluded that the update to Windows 8.1 did not affect grub2. The next step was to check for the boot order in the EFI boot Manager.

The EFI Boot Manager ( efibootmgr ) is a very powerful utility. It can make or break your laptop. There are cases where it has bricked the laptops. Hence exercise extreme caution and care when using these commands. Also my grub2 configuration has the entry to boot Windows 8. Hence for me the priority was to get the Grub2 menu during booting.

Run the below command in the console window:

efibootmgr

The output will have the boot order in the EFI.

BootCurrent: 0004
Timeout: 0 seconds
BootOrder: 0004,0003,2003,2001,2002
Boot0001* EFI Network 0 for IPv6 (08-9E-01-4B-BA-F1) 
Boot0002* EFI Network 0 for IPv4 (08-9E-01-4B-BA-F1) 
Boot0003* arch_grub
Boot0004* Windows Boot Manager
Boot0007* Intel Data_Volume
Boot2001* EFI USB Device
Boot2002* EFI DVD/CDROM
Boot2003* EFI Network

In my case the arch_grub (0003) is after Windows Boot Manager (0004). Hence the Windows Boot Manager boots before without giving a chance for the Grub2 to run. So I changed the boot order so that arch_grub (0003) is before Windows Boot Manager (0004).

The command for my case to change the boot order is :

efibootmgr -o 0003,0004,2003,2001,2002

Now the output for the previous efibootmgr command is :

BootCurrent: 0003
Timeout: 0 seconds
BootOrder: 0003,0004,2003,2001,2002
Boot0001* EFI Network 0 for IPv6 (08-9E-01-4B-BA-F1) 
Boot0002* EFI Network 0 for IPv4 (08-9E-01-4B-BA-F1) 
Boot0003* arch_grub
Boot0004* Windows Boot Manager
Boot0007* Intel Data_Volume
Boot2001* EFI USB Device
Boot2002* EFI DVD/CDROM
Boot2003* EFI Network

Check and recheck the output and restart the laptop, this time the grub2 menu should come up.

Dual Boot Arch Linux and Windows 8

Dual Boot Arch Linux and Windows 8

I have a Toshiba Ultra Book U840W-x0110 that comes with WIndows 8 pre-installed.

Dual booting Linux with Windows has some risk associated. You might end up losing the Windows installation. Hence ensure that you have backed up all the data and have the recovery disk of Windows 8. If you don’t have the recovery disk then create one. (A good guide can be found here).

Prerequisite: A wired internet connection makes the Arch Linux installation easier.

This Ultra book does not have an optical drive. Hence I connected an external optical drive (ASUS DVD writer).

Setup

So here are the steps I followed to have a dual-boot configuration of Windows 8 and Arch Linux.

Steps to create Boot Media for Arch Linux :

    1. Download the Live Media for Arch Linux from here.
    2. Insert a blank DVD into the optical drive.
    3. Right click on the downloaded file and select “Burn to Disk” .
    4. The burn process takes about 5 minutes.
    5. The DVD ejects once the burn process is done.

Create an empty partition on the drive for installing Arch Linux:

    1. Press [Win-Logo]+[R] and type in “diskmgmt.msc” and press [ENTER] to open the Disk-Management in Windows-8.
    2. For my installation  I shrank the C drive to half its size. So that I could install the Arch Linux on a 250 GB (approximate) partition. Select the C drive in the Disk-Management, right-click and select “Shrink volume”.

Steps to change to boot order so that Arch Linux Live Media in the Optical Drive is booted after restart.

  1. Restart the Ultra Book with the shift key pressed. IMG_1664
  2. In the following screen select the troubleshoot option.IMG_1665
  3. In the following screen select the Advanced option.IMG_1666
  4. In the following screen select the UEFI Firmware settings.IMG_1667
  5. Now the BIOS settings are shown.IMG_1668
  6. Move to the security settings and disable the Secure Boot.IMG_1669
  7. Move to the boot settings and change the boot order so that the optical drive is checked first.IMG_1672
  8. Press F10 to “Save and exit”.IMG_1673
  9. Connect to internet via ethernet cable. See that the Arch Linux Live Media DVD is inserted and then restart the Ultra Book.

Booting of the Arch Linux live media and install on hard disk:

  1. After the restart the first screen should have the option “Arch Linux archiso …”. Select it.IMG_2277
  2. Now Arch Linux should boot from the Live Media DVD.IMG_2276

To find out if there is an Internet connection run the command:

 ping -c 3 www.google.com

If you don’t get the below error then you are doing fine else there is something wrong with your internet connection.

ping: unknown host

Toshiba Ultra Book U840W-x0110 has UEFI boot supported. The steps mentioned in this post are for PCs which are booted with UEFI mode. To confirm this run the following command:

mount -t efivarfs efivarfs /sys/firmware/efi/efivars
efivar -l

This will display a list of UEFI variables without errors confirming that we have booted in UEFI mode. Now we can continue with our installation.

Next run the following command to list the block devices (hard disk).

 lsblk

The output should be similar to this :

 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda       8:0    0  229.8G  0 disk 
├─sda1   8:1    0   450M   0 part 
├─sda2   8:2    0   260M   0 part
├─sda3   8:3    0   128M   0 part 
├─sda4   8:4    0 219.3G   0 part 
├─sda5   8:5    0   8.9G   0 part 
sdb      8:16   0  29.8G  0 disk

Create Linux partitions :

 cgdisk /dev/sda

The sda is the name of the block device got by running the lsblk command.

Now you get a table similar to the one below:

                                 cgdisk 0.8.10

                              Disk Drive: /dev/sda
                           Size: 976773168, 465.8 GiB

Part. #     Size        Partition Type            Partition Name
----------------------------------------------------------------
            1007.0 KiB  free space
   1        450.0 MiB   Windows RE                Basic data partition
   2        260.0 MiB   EFI System                Basic data partition
   3        128.0 MiB   Microsoft reserved        Basic data partition
   4        219.3 GiB   Microsoft basic data      Basic data partition
            236.8 GiB   free space
   5        8.9 GiB     Windows RE                Basic data partition
            1.0 MiB     free space
    [ Align  ]  [ Backup ]  [  Help  ]  [  Load  ]  [  New   ]  [  Quit  ]
    [ Verify ]  [ Write  ]

                      Create new partition from free space

Press the down arrow key until you reach the row with a large free space (236.8 GiB in this example).

Press N, followed by Enter (For the line starting with "First Sector ..."), 
Type the size of the sector (230G in my example), 
followed by another Enter (For the line starting with "Hex code ..."), 
followed by another Enter (For the line starting with "Enter new partition name, ....").

This creates a new Linux Filesystem type partition (of size 230G in my example). This will be my root partition.

Next create a Linux Swap partition.

Again press the down (or up) arrow key until you reach the row with the free space(6.8GiB).

Press N, followed by Enter (For the line starting with "First Sector ..."), 
Type the size of the sector (5G in my example), 
followed by 8200 (For the line starting with "Hex code ..."), 
followed by another Enter (For the line starting with "Enter new partition name, ....").

Next create a EFI partition.

Again press the down (or up) arrow key until you reach the row with the free space(1.8GiB).

Press N, followed by Enter (For the line starting with "First Sector ..."), 
Type the size of the sector (512M in my example), 
followed by EF00 (For the line starting with "Hex code ..."), 
followed by another Enter (For the line starting with "Enter new partition name, ....").

Now the partition table will look like:

                                cgdisk 0.8.10

                              Disk Drive: /dev/sda
                           Size: 976773168, 465.8 GiB

Part. #     Size        Partition Type            Partition Name
----------------------------------------------------------------
            1007.0 KiB  free space
   1        450.0 MiB   Windows RE                Basic data partition
   2        260.0 MiB   EFI System                Basic data partition
   3        128.0 MiB   Microsoft reserved        Basic data partition
   4        219.3 GiB   Microsoft basic data      Basic data partition
   6        230.0 GiB   Linux filesystem
   7        5.0 GiB     Linux swap
   8        512.0 MiB   EFI System
            1.3 GiB     free space
   5        8.9 GiB     Windows RE                Basic data partition
            1.0 MiB     free space

Now there are 2 EFI partition. One of them (512M) was created by us. The other from the Windows 8 installation. Note down the partition number of the 260M Windows 8 EFI partition. In this example its 2 (i.e sda2).

Create File Systems:
Next steps are for creating the file systems in the partitions that were created in the previous steps.
To review the partitions we created in the previous steps run the below command:

lsblk

The output should be similar to :

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0   450M  0 part 
├─sda2   8:2    0   260M  0 part
├─sda3   8:3    0   128M  0 part 
├─sda4   8:4    0 219.3G  0 part 
├─sda5   8:5    0   8.9G  0 part 
├─sda6   8:6    0   230G  0 part
├─sda7   8:7    0     5G  0 part
└─sda8   8:8    0   512M  0 part
sdb      8:16   0  29.8G  0 disk

In my example the sda6 of size 230G is the first Linux partition created as a root partition, sda7 of 5G as a swap partition, sda8 of 512M as a EFI partition. Also there is a EFI partition created by the Windows 8 installation. This is a 260MB EFI partition (sda2 in this example). Knowing these partition numbers (sda6,sda7,sda8 and sda2) correctly is very important for the following steps. In your situation these partitions numbers may be different. Hence take caution.

Create the ext4 file system in the root partition:

mkfs.ext4 /dev/sda6

Create the swap file system for the swap partition:

mkswap /dev/sda7
swapon /dev/sda7

Create a EFI system partition:

mkfs.fat -F32 /dev/sda8

Mount the partitions:

Mount the root partition (sda6 in this example):

mount /dev/sda6 /mnt

Mount the EFI partition created by us:

mkdir /mnt/boot
mount /dev/sda8 /mnt/boot

Mount the EFI partition from the Windows 8:

mkdir /mnt/MicrosoftBoot
mount /dev/sda2 /mnt/MicrosoftBoot

Install the base system:

pacstrap -i /mnt base

Generate the File System Table:

genfstab -U -p /mnt >> /mnt/etc/fstab
nano /mnt/etc/fstab

change root :

arch-chroot /mnt /bin/bash

Set Locale :

nano /etc/locale.gen

I will generate the locale for US english with UTF-8 encoding.

Remove the # from the line en_US.UTF-8 UTF-8. Press Control + O to save the file. Control + X to exit the nano editor.

locale-gen

Create the /etc/locale.conf file substituting your chosen locale:

echo LANG=en_US.UTF-8 > /etc/locale.conf

Export substituting your chosen locale:

export LANG=en_US.UTF-8

Set the time Zone. For Berlin,Europe :

ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime

To find out available time zones:

ls /usr/share/zoneinfo/

To find the sub-zones for the zones displayed for the previous command. For Europe:

ls /usr/share/zoneinfo/Europe

Set the hardware clock:

hwclock --systohc --utc

Set the host name. oopra in my case:

echo oopra > /etc/hostname

Set the root password and remember it:

passwd

Install and configure the boot loader:

mount -t efivarfs efivarfs /sys/firmware/efi/efivars
pacman -S grub efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=arch_grub --recheck

Run the below command and note down the output (MicrosoftBoot is the directory where we mounted the Windows 8 EFI partition):

grub-probe --target=fs_uuid /MicrosoftBoot/EFI/Microsoft/Boot/bootmgfw.efi

In the example the output is :

4252-7460

Also run the below command and note down the output:

grub-probe --target=hints_string /MicrosoftBoot/EFI/Microsoft/Boot/bootmgfw.efi

In the example the output is:

--hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2

With the outputs of the above two commands add a custom entry in the grub menu:

nano /etc/grub.d/40_custom

Add the Windows 8 entry. Now the 40_custom file looks like the one below (The outputs of the commands that we noted down are inserted after “–hint-bios=”):

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
        menuentry "Windows 8" {
                insmod part_gpt
                insmod fat
                insmod search_fs_uuid
                insmod chain
                search --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 4252-7460
                chainloader /EFI/Microsoft/Boot/bootmgfw.efi
        }

Now create the grub configuration :

grub-mkconfig -o /boot/grub/grub.cfg

Exit the Chroot, unmount, reboot. Importantly eject the installation CD before the laptop starts up again :

exit
umount -R /mnt
reboot

Now the laptop will boot into the Arch Linux we have installed with the previous steps.

Now we have logged-in as root user. Working as a root user is not recommended for regular use.

So add a new user ( hackoopra in this example):

useradd -m -s /bin/bash hackoopra

Set a password for the new user:

passwd hackoopra

Add sound driver:

pacman -S alsa-utils

unmute ALSA:

amixer sset Master unmute

Install the Graphical User Interface :

pacman -S xorg-server xorg-server-utils xorg-xinit
pacman -S mesa

Install the Intel Video card driver (The Toshiba Ultra Book U840W-x0110 has a Intel Corporation 3rd Gen Core processor Graphics Controller (rev 09)
) :

pacman -S xf86-video-intel

Install input drivers :

pacman -S xf86-input-synaptics

Install the default environment for X :

pacman -S xorg-twm xorg-xclock xterm

Check if X is running :

startx

Now there should be few movable windows. Close them by typing exit in every window.

I prefer the KDE Desktop environment. Hence the below steps are for installing KDE.

Run the below command to install KDE. This takes a while.

pacman -S kde

Install the KDE Display manager (KDM):

pacman -S kdebase-workspace

Configure the KDM:

systemctl enable kdm

Now reboot with the “reboot” command and you should be presented with a login screen. Your minimal Arch Linux is ready.

References :

Arch Linux Wiki

No Hard Drive detected during Linux installation

No Hard Drive detected during Linux installation (Fedora/Ubuntu)

Do the following if the installation is unable to find the Local hard Disk.

  1. This step has some risk associated with it. Hence ensure that you have backed up all the data and have the recovery disk for Windows 8. If you don’t have the recovery disk then do not proceed further. Exit the Linux installation, disconnect the external Optical Drive (To boot into windows 8.1 on the Hard Drive) and create the Recovery Disk (A good guide can be found here).
  2. If you have the recovery disk, quit the installation procedure, but do not exit Fedora.
  3. Open the terminal window (command prompt) and run the command :
    fdisk -l

    Usually the first line begins as :

    Disk /dev/sda
  4. If the disk is shown as /dev/sda in the previous step then run the next command :
    su -c 'gdisk /dev/sda'

    Else replace /dev/sda with whichever disk was shown in the previous step. It will offer to convert the partition table for you. After answering “yes”, type w and press Enter to commit the changes to disk, then type q and press Enter to quit gdisk.

  5. If the previous step was successful then the installation procedure can be restarted from the “Activities”.

Dual Boot Windows 8.1 and Fedora 20

Dual Boot Windows 8.1 and Fedora 20

I have a Toshiba Ultra Book U840W-x0110. It comes with Windows 8 pre-installed. I later got it upgraded to Windows 8.1 for free (It was offered as a software update). The below mentioned steps should work for Windows 8.0 as well.

In this post I will mention certain important steps that are required before dual booting Linux and Windows 8 in general. Once this is done installing Linux distros like Ubuntu or Fedora should be self-explanatory. Although In this post I have explained to steps for Fedora, it will be similar for other Linux distros as well.

Dual booting Linux with Windows has some risk associated. You might end up losing the Windows installation. Hence ensure that you have backed up all the data and have the recovery disk of Windows 8. If you don’t have the recovery disk then create one. (A good guide can be found here).

Prerequisite: This Ultra book does not have an optical drive. Hence I connected an external optical drive (ASUS DVD writer).

Setup

So here are the steps I followed to have a dual-boot configuration of Windows 8.1 and Fedora 20.

Steps to create Boot Media for Fedora 20 :

    1. Download the Live Media for Fedora 20 from here.
    2. Insert a blank DVD into the optical drive.
    3. Right click on the downloaded file and select “Burn to Disk” .
    4. The burn process takes about 5 minutes.
    5. The DVD ejects once the burn process is done.

IMG_1661

Create an empty partition on the drive for installing Fedora:

    1. Press [Win-Logo]+[R] and type in “diskmgmt.msc” and press [ENTER] to open the Disk-Management in Windows-8.
    2. For my installation  I shrank the C drive to half its size. So that I could install the Fedora on a 250 GB (approximate) partition. Select the C drive in the Disk-Management, right-click and select “Shrink volume”.

Steps to change to boot order so that Fedora Live Media in the Optical Drive is booted after restart.

  1. Restart the Ultra Book with the shift key pressed. IMG_1664
  2. In the following screen select the troubleshoot option.IMG_1665
  3. In the following screen select the Advanced option.IMG_1666
  4. In the following screen select the UEFI Firmware settings.IMG_1667
  5. Now the BIOS settings are shown.IMG_1668
  6. Move to the security settings and disable the Secure Boot.IMG_1669
  7. Move to the boot settings and change the boot order so that the optical drive is checked first.IMG_1672
  8. Press F10 to “Save and exit”.IMG_1673
  9. See that the Fedora Live Media DVD is inserted and then restart the Ultra Book.

Booting of the Fedora live media and install on hard disk:

  1. After the restart the first screen should have the option “Start Fedora Live”. Select it.IMG_1674
  2. Now Fedora should boot from the Live Media DVD.
  3. After some considerable time (more than 5 minutes) the following screen will show up.Select “Install to Hard Drive” .IMG_1676
  4. Wait for some time until the language selection menu appears.Press continue.IMG_1678
  5. The next screen gives the installation summary. Select Installation Destination under system. Normally it should show your hard disk under “Local Standard Disk”. If so you’re in luck, you can continue the installation procedure which is very self-explanatory ( Else there is a good guide here (From Step 5). If no Hard Disk is show then the workaround is mentioned in my other post.