Tuesday, March 2, 2010

Restoring GRUB2 after installing Windows

This method of installation uses the chroot command to gain access to the broken system's files. Once the chroot command is issued, the LiveCD treats the broken system's / as its own. Commands run in a chroot environment will affect the broken systems filesystems and not those of the LiveCD.

  1. Boot to the LiveCD Desktop (Ubuntu 9.10 or later).
  2. Open a terminal - Applications, Accessories, Terminal.

  3. Determine your normal system partition - (the switch is a lowercase "L")

    sudo fdisk -l

    • If you aren't sure, run

      df -Th. Look for the correct disk size and ext3 or ext4 format.

  4. Mount your normal system partition:
    • Substitute the correct partition: sda1, sdb5, etc.

    sudo mount /dev/sdXX /mnt # Example: sudo mount /dev/sda1 /mnt

  5. Only if you have a separate boot partition:

    • sdYY is the /boot partition designation (examply sdb3)
    • sudo mount /dev/sdYY /mnt/boot

  6. Mount devices:

    sudo mount --bind /dev/ /mnt/dev

  7. To ensure that only the grub utilities from the LiveCD get executed, mount /usr

    sudo mount --bind /usr/ /mnt/usr

  8. mount proc filesystem

    sudo mount --bind /proc/ /mnt/proc

  9. Chroot into your normal system device:

    sudo chroot /mnt

  10. If there is no /boot/grub/grub.cfg or it's not correct, create one using

    update-grub

  11. Reinstall GRUB 2:
    • Substitute the correct device - sda, sdb, etc. Do not specify a partition number.

    grub-install /dev/sdX

  12. Verify the install (use the correct device, for example sda. Do not specify a partition): sudo grub-install --recheck /dev/sdX

  13. Exit chroot: CTRL-D on keyboard

  14. Unmount devices:

    sudo umount /mnt/dev

    • If you mounted a separate /boot partition:

      sudo umount /mnt/boot

  15. Unmount last device:

    sudo umount /mnt

  16. Reboot.

    reboot

Post-Restoration Commands

Once the user can boot to a working system, try to determine why the system failed to boot. The following commands may prove useful in locating and/or fixing the problem.

To refresh the available devices and settings in /boot/grub/grub.cfg

  • sudo update-grub

To look for the bootloader location.
  • grub-probe -t device /boot/grub

To install GRUB 2 to the sdX partition's MBR (sda, sdb, etc.)

  • sudo grub-install /dev/sdX

To recheck the installation. (sda, sdb, etc.) sudo grub-install --recheck /dev/sdX

Please check the following link for further details.

https://help.ubuntu.com/community/Grub2#Reinstalling%20GRUB%202


Sunday, April 13, 2008

compiling the tools for ARM My experience

********************************************************
Building tool chain for ARM using Build root in Linux.
********************************************************

make a directory with ur favourite name some directory.
$mkdir MyFavaouriteDir

copy the build root compressed file buildroot-snapshot.tar.bz2 into the directory created.
$cd MyFavouriteDir

untar the compressed file into the directory
$tar -jxvf buildroot-snapshot.tar.bz2

A directory by name buildroot will be created.Change the directory to buildroot directory.
$cd buildroot
$pwd
MyFavouritedirectory/buildroot/

create a directory by name dl inside the build root directory
$mkdir dl

$ls
dl binaries build_arm Config.in docs Makefile package project
project_build_arm scripts target TODO toolchain toolchain_build_arm

copy the following files into the dl directory

bash-3.2.tar.gz
binutils-2.18.tar.bz2
binutils.tar.bz2
buildroot-snapshot.tar.bz2
busybox-1.9.1.tar.bz2
ccache-2.4.tar.gz
fakeroot_1.9.tar.gz
gcc-4.2.0.tar.bz2
genext2fs-1.4.tar.gz
glibc-2.2.4.tar.gz
gmp-4.2.2.tar.bz2
linux-2.6.23.tar.bz2
mpfr-2.3.0.patch
mpfr-2.3.0.tar.bz2
uClibc-0.9.29.tar.bz2

$ls dl
bash-3.2.tar.gz binutils-2.18.tar.bz2 binutils.tar.bz2 buildroot buildroot-snapshot.tar.bz2
busybox-1.9.1.tar.bz2 ccache-2.4.tar.gz fakeroot_1.9.tar.gz gcc-4.2.0.tar.bz2 genext2fs-1.4.tar.gz
glibc-2.2.4.tar.gz gmp-4.2.2.tar.bz2 linux-2.6.23.tar.bz2 mpfr-2.3.0.patch mpfr-2.3.0.tar.bz2
uClibc-0.9.29.tar.bz2

now the process of building the tool chain starts

************************************************
ncurses development library is needed for make menuconfig to work
about:
ncurses is a programming library providing an API, allowing the programmer to write text user interfaces in a terminal-independent manner
************************************************

$make menuconfig
select the configuration options u wish from the options and save the configuration
$make
The following programs are needed for the building the tool chain by make.
Hopefully these will be preinstalled in the system.If not installed system will prompt you to install the required programs after u run make.

************************************************
bison not found
about bison :
Bison is a general-purpose parser generator that converts an annotated context-free grammar into an LALR(1) or GLR parser for that grammar. Once you are proficient with Bison, you can use it to develop a wide range of language parsers, from those used in simple desk calculators to complex programming languages.

Bison is upward compatible with Yacc: all properly-written Yacc grammars ought to work with Bison with no change. Anyone familiar with Yacc should be able to use Bison with little trouble. You need to be fluent in C or C++ programming in order to use Bison.
installed bison with documentation

************************************************
flex not found
about flex:
Flex

Flex (The Fast Lexical Analyzer)
Flex is a fast lexical analyser generator. It is a tool for generating programs that perform pattern-matching on text. Flex is a non-GNU free implementation of the well known Lex program.

installed flex
************************************************
makeinfo not found
about:
makeinfo is a program for converting Texinfo files into Info files. Texinfo is a documentation system that uses a single source file to produce both on-line information and printed output.
************************************************
After running make wait for some time u will get the output if every thing is correct other wise with error message as happened to me.
Lets learn by experimenting so start experimenting Today.

C program with out main()

*********************************
writing C program without main()
*********************************

I am using the following program to compile and run with out main()

//MyFile.c
#include<stdio.h>
#include<stdlib.h>

int MyMain(){
printf("Program with out main");
exit(0);
}

compile the program with gcc using the following options

gcc -o MyFile -nostartfiles -e MyMain -lc MyFile.c

u can execute the MyFile using ./MyFile

***********************************************
the options mean this
***********************************************

-o name create a executable with name

-nostartfiles
Do not use the standard system startup files when linking. The
standard system libraries are used normally, unless -nostdlib or
-nodefaultlibs is used.


-e entry
--entry=entry
Use entry as the explicit symbol for beginning execution of your
program, rather than the default entry point. If there is no sym‐
bol named entry, the linker will try to parse entry as a number,
and use that as the entry address (the number will be interpreted
in base 10; you may use a leading 0x for base 16, or a leading 0
for base 8).

-lc link with the standard c library

***********************************************

problem faced :


if u dont call the function exit(0) at the end it will give a segmentation fault.

when tried to create object file separetely with no startupfiles option and link using the linker(ld) the output file created is not executing.

gcc -c -nostartfiles MyFile.c
ld -e MyMain -lc MyFile.o

if u see the object dump of both files genereted both are same.

objdump --disassemble a.out
objdump --disassemble MyFile

please tell me whats wrong with second procedure.