Showing posts with label Operating System. Show all posts
Showing posts with label Operating System. Show all posts

Wednesday, November 6, 2013

Make a Pendrive as Bootable Device

In this article we are going to see how to create a Bootable pendrive for Boot Windows 7 OS. Some time you were need this stuff,so note down the steps how to make a bootable pendrive for windows 7. Instead of booting Windows 7 OS from DVD we can make a boot from Pendrive. So to do this have a pendrive with or more than 4 GB

Following the Below Steps to make a pendrive bootable. Now Plugin the pendrive in your computer.

  •  Press Windows + R to get the Run (or) go to start up and type run and Enter.
  •  Now Type CMD in Run , and hit Ctrl + Shift + Enter.
  •  Next Type  DISKPART in command Window and ENTER
  •  Next Type  LISTDISK  
  • Type Select DISK 1  (Select Pendrive Disk as number )
  • Next Type CLEAN and Enter wait for few seconds.
  • Type CREATE PARTITION PRIMARY and press enter.
  • Type SELECT PARTITION 1 and Press enter.
  • Type ACTIVE and press enter
  • Type FORMAT FS=NTFS
     close the window 

Now my DVD drive is D:  and Pendrive is  H: , Type the following thing in the CMD window.Now load the windows 7 dvd 

Type CD "your dvd drive letter:\" and press enter. Ex: CD D:\ in cmd window
now it seems like follows in cmd windows for my dvd drive D:\. Now cmd window rediects to D drive.

Type D:\CD BOOT press enter.
Type BOOTSECT.EXE /NT60 H:   

Here H: refers pendrive, now copy the full setup of windows 7 to pendrive and boot it .







Sunday, July 28, 2013

Create a Bootable CD from Floppy image or from files

In this article we are going to see how to create a our own bootable CD. First thing we need following items
  • mkisofs
  • Source Floppy image to write to CD

For Windows user you can download it here ftp://ftp.berlios.de/pub/cdrecord/alpha/win32/ 

  • Go to the location where floppy image is located
         cd  ~/myos

  • Create a directory to store the contents of the CD
         mkdir  cddir

  • Copy the contents that are need to be added in the CD
         cp bootfiles/* cddir

  • Copy the floppy image inside the directory         
         cp  floppy.img cddir

          Here  
               -o        indicates output file
               -v        indicates label of the CD
               -b        floppy image
              cddir   where all files should be taken from.

  • Create a CD image from Floppy image
         mkisofs -o  osboot.iso -v myos -b floppy.img cddir

our_kernel  is the name of your kernel 

Command line to create a Bootable cd with out floppy image
   mkdir  -p  $ISO_DIR/boot/grub
   cp  $GRUB_BIN/stage2_eltorito $ISO_DIR/boot/grub
   cp menu.lst $ISO_DIR/boot/grub
   cp  our_kernel $ISO_DIR

         mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot-boot-load-size 4 -boot-info-table -o          bootcd.iso  $ISO_DIR

I Hope from this article you can learn how to create a bootable CD , by having the source as floppy image or files.

Thursday, July 25, 2013

Operating System - Boot Sequence and Sample

     
    

From this article we are going to see  Creating a Boot loader with hanging , Print a Char and Print a custom string on system start up.

      Let we see the Operating systems and there booting sequence, so this part starts from the basics. In early days booting are done through the floppy disks.Floppy disks are 512 bytes . Here we use the NASM Netwide assembler to assemble the code.

         When we power on the computer we will note that computer do a self test that is known as POST  (Power On Self Test), Which have so many activities including search for bootable device. A device is bootable if and only it carries the following things


  1. Boot Sector with Byte Sequence 0x55, 0xAA , When we see this in bytes 511, 512 
  2. Boot Sector  is loaded into memory location  , Normally in location 0, 0x7c00 some bios are loaded into 0x7c00 to 0
[BITS 16]          - by this we are indicating the assembler that this is 16 bit.
[ORG 0x7C00]  - by this we are indicating the assembler where the code will be in memory after  loaded


At start the boot sector will look like this
ORG 0
jmp    0x7c00:start
start;

(or)

ORG 0x7c00
jmp    0x0000:start

start;


MBR table Entries uses, 16 bytes per entry this is written by Disk Partition program.

Offset
Size (bytes)
Description
0x00
1
Boot Indicator (0x80=bootable, 0x00=not bootable)
0x01
1
Starting Head Number
0x02
2
Starting Cylinder Number (10 bits) and Sector (6 bits)
0x04
1
Descriptor (Type of partition/filesystem)
0x05
1
Ending Head Number
0x06
2
Ending Cylinder and Sector numbers
0x08
4
Starting Sector (relative to beginning of disk)
0x0C
4
Number of Sectors in partition

Now we see an example how to make  a bootable from a floppy using NASM.
CPU must starts in Real Mode . BIOS load the code at address 0 to 0x7c00 . This porgram will Filling the 512 bytes with zeros 

; bootsec.asm
hanging:
    jmp hanging 
    times 512-($-$$)db 0


Now we make a boot signature at the End 0xAA,0x55

bootsec.asm
hanging:
    jmp hanging 
    times 510-($-$$) db 0  reduce the 2 bytes for boot signature
db 0x55
db 0xAA

You can see the that cursor is blink in the screen and load is done , If you press the Ctrl+Alt+delete to make a reboot. How this is happening an Interrupt is being generated 0x09. 

How we can avoid the restart ?
We can clear the interrupt flags.by place the key CLI

bootsec.asm
     cli
hanging:
    jmp hanging 
    times 510-($-$$) db 0  reduce the 2 bytes for boot signature
db 0x55
db 0xAA

Now you cant reboot with Ctrl+Alt+Delete. Now you assembled the code in NASM and use partcopy to copy the files to floppy or hdd .Now we see the full source code 

Open a Text editor and save the following code as bootloader.asm

Try Hanging BootLoader
*****************************************************************

[BITS 16]
[ORG 0x7C00]

JMP $      ; Infinte loop

TIMES 510 - ($ - $$)  db 0
DW  oxAA55

*****************************************************************
1.  JMP $ - Means jump to the same location that means goes for infinite loop
2.  Times 510 -($ - $$) - A boot loader is always 512 bytes , so we need to resize of memory using Times        Directive $ stands for start of instruction and $$ stands for start of program . ($ - $$) Length of our              program.
3.  DW 0xAA55 indicates boot signature. if this is not present that indicate this in invalid boot loader.

*****************************************************************
Try Compile using NASM 
nasm bootloader.asm -f bin -o boot.bin

Try Copy to floppy
partcopy boot.bin 0 200 -fo                  - Windows user
dd if=boot .bin  bs=512  of=/dev/fdo    - Linux user , Insert the floppy don't mount it

*****************************************************************
Now insert the floppy in system and see it will hanged.Same for Disc copy the boot file to CD
*****************************************************************

Print a character in Boot Loader:
For printing we will use BIOS video interrupt int 0x10.
To use this interrupt we need to set some values for following  register.

AL  -    ASCII Value of character to display
AH  -   0x0E, What character we want to print on screen
BL   -   Text Attribute (Forground and Background) 0x07
BH  -    Page number 0x00

Save the following code as bootloader.asm

[BITS 16]
[ORG 0x7C00]

MOV  AL, 65
CALL Print 
JMP    $

Print:
MOV AH,0x0E
MOV BH,0x00
MOV BL,0x07
INT    0x10               ; Call video interrupt
RET                          ; Return to called procedure

TIMES 510 - ($ - $$)  db 0
DW  oxAA55


*****************************************************************
Try Compile using NASM 
nasm bootloader.asm -f bin -o boot.bin

Try Copy to floppy
partcopy boot.bin 0 200 -fo                  - Windows user
dd if=boot .bin  bs=512  of=/dev/fdo    - Linux user , Insert the floppy don't mount it

*****************************************************************
Now insert the floppy in system and see it will print A and hanged.Same for Disc copy the boot file to CD
*****************************************************************

Print a String in Boot Loader:
*****************************************************************
[BITS 16]
[ORG 0x7C00]

MOV  SI, Hello
CALL String
JMP    $

Print:
MOV AH,0x0E
MOV BH,0x00
MOV BL,0x07
INT    0x10               ; Call video interrupt
RET                          ; Return to called procedure


String:

Next:
MOV AL,[SI]
INC   SI
OR     AL,AL            ; check AL value is 0
JZ       exit_function    ; IF End then return
CALL Print                ; Else Print Char
JMP    Next
exit_function:               ; End Lablel
RET                            ; Return

;DATA 

Hello  db  'Hello  Rajesh', 0   ; Hello Rajesh string ending with 0

TIMES 510 - ($ - $$)  db 0
DW  oxAA55

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

From this article we can learn how to create a basic boot loader and print our string in the system boot.I hope this will help all of them to understand clearly about boot loader.