Installatie wxwidgets op Debian / Ubuntu

February 20th, 2009
Comments Off

1° Voor het installeren van nodige pakketten, dienen we de sources.list bij te werken :

(Ga naar tekstverwerker al dan niet met sudo of gksu.)

De file /etc/apt/sources.list aanvullen met :

# wxWidgets/wxPython repository at apt.wxwidgets.org

deb http://apt.wxwidgets.org/ DIST-wx main

deb-src http://apt.wxwidgets.org/ DIST-wx main

opgelet : hardy, dient gebruikt te worden ipv het woord DIST,  intrepid bestaat nog niet.

Haal de key op via volgend bevel in een terminalvenster :

curl http://apt.wxwidgets.org/key.asc | sudo apt-key add -

Eventueel is curl nodig.

sudo apt-get install curl

2° volgende pakketten moeten geïnstalleerd worden (b.v. Via synaptic) :

python-wxgtk2.8

python-wxtools

python-wxaddons

wx2.8-i18n

libwxgtk2.8-dev

libwxbase2.8-0

libwxsmithlib0

wx-common

wx2.8-doc

wx2.8-examples

wx2.8-headers

wx2.8-i18n

wxformbuilder

3° Om te verhinderen dat je manueel alle code dient aan te passen (In een terminalvenster en al dan niet met sudo) :

cd /usr/include

ln -s ./wx-2.8/wx/ wx

4° In code blocks dienen twee parameters toegevoegd te worden (eventueel via een copy-paste vanuit deze file voor de juiste backquotes) :

`wx-config –cxxflags` MET BACKQUOTES !

bij compiler instellingen - other options

`wx-config –libs` MET BACKQUOTES !

bij linker instellingen - other options

5° Compileer (menu Build - Build) en doe een voorbeeldprogramma draaien

6° In de wizard van het nieuwe project kies je voor wxsmith !!!!

7° in Code::Blocks zit voorlopig een kleine bug, die al of niet voorkomt in jouw versie

In de wizard voor het WX project MOET je advanced options aanzetten (vinkje én de twee vinkjes daaronder)

Dit doet ogenschijnlijk niets, maar een bepaalde systeeminstelling heeft er last van.

tux de luxe C++

Floats, hoe werk je met een komma ?

January 31st, 2009
Comments Off

Floats, hoe werk je met een komma ?

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
char string1[80];
char string2[80];
cout << “Geef een getal : “;
cin >> string1;
cout << “Geef nog een getal : “;
cin >> string2;
string stringx = string1;
string stringy = string2;
string stringz = (”,”);
stringx.replace(stringx.find(stringz),stringz.length(),”.”);
cout << stringx << endl;

return (0);
}

tux de luxe C++

E-notatie oplossen

January 30th, 2009
Comments Off

Je kan spelen met

cout << setprecision(5) << Variable << endl;

Hierbij duidt je aan hoeveel cijfers je na de komma wil zien.

Je hebt ook nog :

Unless you tell your C++ program otherwise, floating point values will be output according to default output settings. For example, large floating point values will be output in scientific notation, so that a number like 123456789.5 may be output as 1.234567E+08. Also, if the floating point number is a whole number, C++ doesn’t print the decimal point. So 96.0 prints as 96 .

To change these default actions, the programmer should include the following two statements in the program before any floating point output occurs:

   cout.setf(ios::fixed, ios::floatfield);
   cout.setf(ios::showpoint);

The first statement indicates that standard notation should be used rather
than scientific notation.  The second statement forces C++ to show the

decimal point for all floating point numbers.

tux de luxe C++

Oefeningen op Floating Point

January 30th, 2009
Comments Off

Oefening 1

Schrijf een klasse die strings gebruikt om floating-point getallen weer te geven in het formaat zoals in het voorbeeld hierbij.

Je moet kunnen lezen, schrijven, optellen, aftrekken, vermenigvuldigen en delen met floating-point getallen.


#include <iostream>
#include <iomanip>

int main()
{
// two number to work with
float number1, number2;
float result;               // result of calculation
int   counter;              // loop counter and accuracy check

number1 = 1.0;
number2 = 1.0;
counter = 0;

while (number1 + number2 != number1) {
++counter;
number2 = number2 / 10.0;
}
std::cout << std::setw(2) << counter <<  ” digits accuracy in calculations\n”;

number2 = 1.0;
counter = 0;

while (true) {
result = number1 + number2;
if (result == number1)
break;
++counter;
number2 = number2 / 10.0;
}
std::cout << std::setw(2) << counter <<    ” digits accuracy in storage\n”;
return (0);
}


Oefening 2

Maak een klasse die fixed-point getallen gebruikt met een vast aantal cijfers na de komma, bvb 2.

tux de luxe C++

Oefeningen FILE I/O

January 9th, 2009
Comments Off

1° Maak een bestand dat het bestand /etc/hosts (onder Linux en Mac) of

c:\windows\system32\drivers\etc\hosts op het scherm weergeeft.

2° Maak een eenvoudige tekstverwerker, je moet tekst kunnen lezen, aanpassen en wegschrijven.

tux de luxe Basis

File I/O (alt)

January 9th, 2009
Comments Off

C++ File I/O

While redirection is very useful, it is really part of the operating system (not C++). In fact, C++ has a general mechanism for reading and writing files, which is more flexible than redirection alone.

iostream.h and fstream.h

There are types and functions in the library iostream.h that are used for standard I/O. fstream.h includes the definitions for stream classes ifstream (for input from a file), ofstream (for output to a file) and fstream (for input to and output from a file). Make sure you always include that header when you use files.

Type

For files you want to read or write, you need a file stream object, e.g.:

ifstream inFile;  // object for reading from a file
ofstream outFile; // object for writing to a file

Functions

Reading from or writing to a file in C++ requires 3 basic steps:

  1. Open the file.
  2. Do all the reading or writing.
  3. Close the file.

Following are described the functions needed to accomplish each step.

  1. Opening a file:In order to open a file, use the member function open(). Use it as:
    inFile.open(filename, mode);
    outFile.open(filename, mode);

    where:

    • filename is a string that holds the name of the file on disk (including a path like /cs/course if necessary).
    • mode is a string representing how you want to open the file. Most often you’ll open a file for reading (ios::in) or writing (ios::out or ios::app).

    Note that open() initializes the file object that can then be used to access the file. After opening the file, we should test the file object (e.g., with ! below) to make sure it was properly opened (e.g., an open may fail if we don’t have the correct permissions or the file doesn’t exist when opening for reading).

    Here are examples of opening files:

    ifstream inFile;
    ofstream outFile;
    char inputFilename[] = "in.list";
    char outputFilename[] = "out.list";
    
    
    inFile.open(inputFilename, ios::in);
    
    if (!inFile) {
      cerr << "Can't open input file " << inputFilename << endl;
      exit(1);
    }
    
    outFile.open(outputFilename, ios::out);
    
    if (!outFile) {
      cerr << "Can't open output file " << outputFilename << endl;
      exit(1);
    }

    Note that the input file that we are opening for reading (ios::in) must already exist. In contrast, the output file we are opening for writing (ios::out) does not have to exist. If it does not, it will be created. If this output file does already exist, its previous contents will be thrown away (and will be lost).


    Note: There are other modes you can use when opening a file, such as append (ios::app) to append something to the end of a file without losing its contents…or modes that allow you to both read and write.

  2. Reading from or writing to a file:Once a file has been successfully opened, you can read from it in the same way as you would read with cin or write to it in the same way as you write using cout.

    Continuing our example from above, suppose the input file consists of lines with a username and an integer test score, e.g.:

    in.list
    -------
    foo 70
    bar 98
    ...

    and that each username is no more than 8 characters long.

    We might use the files we opened above by copying each username and score from the input file to the output file. In the process, we’ll increase each score by 10 points for the output file:

    char username[9];  // One extra for null char.
    int score;
    
    ...
    
    while (!inFile.eof()) {
      inFile >> username >> score;
      outFile << username << " " << score+10 << endl;
    }

    In the while loop, we keep on reading usernameand score until we hit the end of the file. This is tested by calling the member function eof().

    The bad thing about using eof() is that if the file is not in the right format (e.g., a letter is found when a number is expected):

    in.list
    -------
    foo 70
    bar 98
    biz A+
    ...

    then >> will not be able to read that line (since there is no integer to read) and it won’t advance to the next line in the file. For this error, eof() will not return true (it’s not at the end of the file)….

    Errors like that will at least mess up how the rest of the file is read. In some cases, they will cause an infinite loop.

    One solution is to test against the number of values we expect to be read by >> operator each time. Since there are two types a string and an integer, we expect it to read in 2 values, so our condition could be:

    while (inFile >> username >> score) {
    ...
    }

    Now, if we get 2 values, the loop continues. If we don’t get 2 values, either because we are at the end of the file or some other problem occurred (e.g., it sees a letter when it is trying to read in a number), then the loop will end (>> will return a 0 in this case).


    Note: When you use eof(), it will not detect the end of the file until it tries to read past it. In other words, they won’t report end-of-file on the last valid read, only on the one after it.

  3. Closing a file:When done with a file, it must be closed using the member function close().

    To finish our example, we’d want to close our input and output files:

    inFile.close();
    outFile.close();

    Closing a file is very important, especially with output files. The reason is that output is often buffered. This means that when you tell C++ to write something out, e.g.,

    outFile << "Whatever!";

    it doesn’t necessary get written to disk right away, but may end up in a buffer in memory. This output buffer would hold the text temporarily:

    Sample output buffer:
    ----------------------------------------------
    | a | b  | c | W | h | a | t | e | v | e | r |
    ----------------------------------------------
    | ! |    |   |   |   |   |   |   |   |   |   |
    ----------------------------------------------
    |   |    |   |   |   |   |   |   |   |   |   |
    ----------------------------------------------
    |   |    |   |   |   |   |   |   |   |   |   |
    ----------------------------------------------
    ...

    (The buffer is really just 1-dimensional despite this drawing.)

    When the buffer fills up (or when the file is closed), the data is finally written to disk.

    So, if you forget to close an output file then whatever is still in the buffer may not be written out.


    Note: There are other kinds of buffering than the one we describe here.


tux de luxe Basis

File I/O

January 9th, 2009
Comments Off

Input/Output with files

C++ provides the following classes to perform output and input of characters to/from files:

  • ofstream: Stream class to write on files

  • ifstream: Stream class to read from files

  • fstream: Stream class to both read and write from/to files.

These classes are derived directly or indirectly from the classes istream, and ostream. We have already used objects whose types were these classes: cin is an object of class istream and cout is an object of class ostream. Therfore, we have already been using classes that are related to our file streams. And in fact, we can use our file streams the same way we are already used to use cin and cout, with the only difference that we have to associate these streams with physical files. Let’s see an example:

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}
[file example.txt]
Writing this to a file

This code creates a file called example.txt and inserts a sentence into it in the same way we are used to do with cout, but using the file stream myfile instead.

But let’s go step by step:

Open a file

The first operation generally performed on an object of one of these classes is to associate it to a real file. This procedure is known as to open a file. An open file is represented within a program by a stream object (an instantiation of one of these classes, in the previous example this was myfile) and any input or output operation performed on this stream object will be applied to the physical file associated to it.

In order to open a file with a stream object we use its member function open():

open (filename, mode);

Where filename is a null-terminated character sequence of type const char * (the same type that string literals have) representing the name of the file to be opened, and mode is an optional parameter with a combination of the following flags:

ios::in Open for input operations.
ios::out Open for output operations.
ios::binary Open in binary mode.
ios::ate Set the initial position at the end of the file.
If this flag is not set to any value, the initial position is the beginning of the file.
ios::app All output operations are performed at the end of the file, appending the content to the current content of the file. This flag can only be used in streams open for output-only operations.
ios::trunc If the file opened for output operations already existed before, its previous content is deleted and replaced by the new one.

All these flags can be combined using the bitwise operator OR ( |). For example, if we want to open the file example.bin in binary mode to add data we could do it by the following call to member function open():

ofstream myfile;
myfile.open ("example.bin", ios::out | ios::app | ios::binary);

Each one of the open() member functions of the classes ofstream, ifstream and fstream has a default mode that is used if the file is opened without a second argument:

class default mode parameter
ofstream ios::out
ifstream ios::in
fstream ios::in | ios::out

For ifstream and ofstream classes, ios::in and ios::out are automatically and respectively assumed, even if a mode that does not include them is passed as second argument to the open() member function.

The default value is only applied if the function is called without specifying any value for the mode parameter. If the function is called with any value in that parameter the default mode is overridden, not combined.

File streams opened in binary mode perform input and output operations independently of any format considerations. Non-binary files are known as text files, and some translations may occur due to formatting of some special characters (like newline and carriage return characters).

Since the first task that is performed on a file stream object is generally to open a file, these three classes include a constructor that automatically calls the open() member function and has the exact same parameters as this member. Therefore, we could also have declared the previous myfile object and conducted the same opening operation in our previous example by writing:

ofstream myfile ("example.bin", ios::out | ios::app | ios::binary);

Combining object construction and stream opening in a single statement. Both forms to open a file are valid and equivalent.

To check if a file stream was successful opening a file, you can do it by calling to member is_open() with no arguments. This member function returns a bool value of true in the case that indeed the stream object is associated with an open file, or false otherwise:

if (myfile.is_open()) { /* ok, proceed with output */ }

Closing a file

When we are finished with our input and output operations on a file we shall close it so that its resources become available again. In order to do that we have to call the stream’s member function close(). This member function takes no parameters, and what it does is to flush the associated buffers and close the file:

myfile.close();

Once this member function is called, the stream object can be used to open another file, and the file is available again to be opened by other processes.

In case that an object is destructed while still associated with an open file, the destructor automatically calls the member function close().

Text files

Text file streams are those where we do not include the ios::binary flag in their opening mode. These files are designed to store text and thus all values that we input or output from/to them can suffer some formatting transformations, which do not necessarily correspond to their literal binary value.

Data output operations on text files are performed in the same way we operated with cout:

// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile ("example.txt");
  if (myfile.is_open())
  {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();
  }
  else cout << "Unable to open file";
  return 0;
}
[file example.txt]
This is a line.
This is another line.

Data input from a file can also be performed in the same way that we did with cin:

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string line;
  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 

  return 0;
}
This is a line.
This is another line.

This last example reads a text file and prints out its content on the screen. Notice how we have used a new member function, called eof() that returns true in the case that the end of the file has been reached. We have created a while loop that finishes when indeed myfile.eof() becomes true (i.e., the end of the file has been reached).

Checking state flags

In addition to eof(), which checks if the end of file has been reached, other member functions exist to check the state of a stream (all of them return a bool value):

bad()
Returns true if a reading or writing operation fails. For example in the case that we try to write to a file that is not open for writing or if the device where we try to write has no space left.
fail()
Returns true in the same cases as bad(), but also in the case that a format error happens, like when an alphabetical character is extracted when we are trying to read an integer number.
eof()
Returns true if a file open for reading has reached the end.
good()
It is the most generic state flag: it returns false in the same cases in which calling any of the previous functions would return true.

In order to reset the state flags checked by any of these member functions we have just seen we can use the member function clear(), which takes no parameters.

get and put stream pointers

All i/o streams objects have, at least, one internal stream pointer:

ifstream, like istream, has a pointer known as the get pointer that points to the element to be read in the next input operation.

ofstream, like ostream, has a pointer known as the put pointer that points to the location where the next element has to be written.

Finally, fstream, inherits both, the get and the put pointers, from iostream (which is itself derived from both istream and ostream).

These internal stream pointers that point to the reading or writing locations within a stream can be manipulated using the following member functions:

tellg() and tellp()

These two member functions have no parameters and return a value of the member type pos_type, which is an integer data type representing the current position of the get stream pointer (in the case of tellg) or the put stream pointer (in the case of tellp).

seekg() and seekp()

These functions allow us to change the position of the get and put stream pointers. Both functions are overloaded with two different prototypes. The first prototype is:

seekg ( position );
seekp ( position );

Using this prototype the stream pointer is changed to the absolute position position (counting from the beginning of the file). The type for this parameter is the same as the one returned by functions tellg and tellp: the member type pos_type, which is an integer value.

The other prototype for these functions is:

seekg ( offset, direction );
seekp ( offset, direction );

Using this prototype, the position of the get or put pointer is set to an offset value relative to some specific point determined by the parameter direction. offset is of the member type off_type, which is also an integer type. And direction is of type seekdir, which is an enumerated type ( enum) that determines the point from where offset is counted from, and that can take any of the following values:

ios::beg offset counted from the beginning of the stream
ios::cur offset counted from the current position of the stream pointer
ios::end offset counted from the end of the stream

The following example uses the member functions we have just seen to obtain the size of a file:

// obtaining file size
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  long begin,end;
  ifstream myfile ("example.txt");
  begin = myfile.tellg();
  myfile.seekg (0, ios::end);
  end = myfile.tellg();
  myfile.close();
  cout << "size is: " << (end-begin) << "
bytes.\n";
  return 0;
}
size is: 40 bytes.

Binary files

In binary files, to input and output data with the extraction and insertion operators ( << and >>) and functions like getline is not efficient, since we do not need to format any data, and data may not use the separation codes used by text files to separate elements (like space, newline, etc…).

File streams include two member functions specifically designed to input and output binary data sequentially: write and read. The first one ( write) is a member function of ostream inherited by ofstream. And read is a member function of istream that is inherited by ifstream. Objects of class fstream have both members. Their prototypes are:

write ( memory_block, size );
read ( memory_block, size );

Where memory_block is of type “pointer to char” ( char*), and represents the address of an array of bytes where the read data elements are stored or from where the data elements to be written are taken. The size parameter is an integer value that specifies the number of characters to be read or written from/to the memory block.

// reading a complete binary file
#include <iostream>
#include <fstream>
using namespace std;

ifstream::pos_type size;
char * memblock;

int main () {
  ifstream file ("example.bin", ios::in|ios::binary|ios::ate);
  if (file.is_open())
  {
    size = file.tellg();
    memblock = new char [size];
    file.seekg (0, ios::beg);
    file.read (memblock, size);
    file.close();

    cout << "the complete file content is in memory";

    delete[] memblock;
  }
  else cout << "Unable to open file";
  return 0;
}
the complete file content is in memory

In this example the entire file is read and stored in a memory block. Let’s examine how this is done:

First, the file is open with the ios::ate flag, which means that the get pointer will be positioned at the end of the file. This way, when we call to member tellg(), we will directly obtain the size of the file. Notice the type we have used to declare variable size:

ifstream::pos_type size;

ifstream::pos_type is a specific type used for buffer and file positioning and is the type returned by file.tellg(). This type is defined as an integer type, therefore we can conduct on it the same operations we conduct on any other integer value, and can safely be converted to another integer type large enough to contain the size of the file. For a file with a size under 2GB we could use int:

int size;
size = (int) file.tellg();

Once we have obtained the size of the file, we request the allocation of a memory block large enough to hold the entire file:

memblock = new char[size];

Right after that, we proceed to set the get pointer at the beginning of the file (remember that we opened the file with this pointer at the end), then read the entire file, and finally close it:

file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();

At this point we could operate with the data obtained from the file. Our program simply announces that the content of the file is in memory and then terminates.

Buffers and Synchronization

When we operate with file streams, these are associated to an internal buffer of type streambuf. This buffer is a memory block that acts as an intermediary between the stream and the physical file. For example, with an ofstream, each time the member function put (which writes a single character) is called, the character is not written directly to the physical file with which the stream is associated. Instead of that, the character is inserted in that stream’s intermediate buffer.

When the buffer is flushed, all the data contained in it is written to the physical medium (if it is an output stream) or simply freed (if it is an input stream). This process is called synchronization and takes place under any of the following circumstances:

  • When the file is closed: before closing a file all buffers that have not yet been flushed are synchronized and all pending data is written or read to the physical medium.

  • When the buffer is full: Buffers have a certain size. When the buffer is full it is automatically synchronized.

  • Explicitly, with manipulators: When certain manipulators are used on streams, an explicit synchronization takes place. These manipulators are: flush and endl.

  • Explicitly, with member function sync(): Calling stream’s member function sync(), which takes no parameters, causes an immediate synchronization. This function returns an int value equal to -1 if the stream has no associated buffer or in case of failure. Otherwise (if the stream buffer was successfully synchronized) it returns 0.

tux de luxe C++

Grub Troubleshooting

January 6th, 2009
Comments Off

Opstartlader Grub

Opstartlader Grub herstellen of verwijderen

Inhoud:

(deze lijst is niet aanklikbaar; naar beneden bladeren voor de toelichting op elk punt)

1. Inleiding

2. Grub herstellen (de Windows-CD heeft Grub overschreven)

3. Grub verwijderen (terug naar uitsluitend Windows)

1. Inleiding

Grub, oftewel de Grand Unified Bootloader, is de meestgebruikte opstartlader in Linux. Dat is niet voor niets: het ding start werkelijk alle denkbare besturingssystemen op. Alle Linux-distro’s, alle Windows-soorten, alle DOS-soorten, alle BSD-soorten, Apple Mac OS/X, noem maar op.

Op mijn meervoudig opstartbare flaptop staan 10 verschillende besturingssystemen in de menulijst van Grub: gebroederlijk naast elkaar op één harde schijf….

Grub is bewijs voor de kracht van de eenvoud: het programmaatje is zeer eenvoudig maar tevens krachtig en veelzijdig.

Toch kunt u wel eens tegen een probleempje aanlopen met Grub. Hier staan de meest vóórkomende beschreven, met de oplossing erbij.

2. Grub herstellen (de Windows-CD heeft Grub overschreven)

Als u eerst Linux installeert en daarna pas Windows, dan raakt u Grub kwijt. Daarom kunt u voortaan beter Windows als eerste installeren. Gelukkig is het probleem makkelijk op te lossen. Wel is het heel belangrijk, dat u de onderstaande instructie precies opvolgt.

Grub bestaat uit twee delen. Ten eerste het programmaatje zelf, dat in de MBR staat. De Master Boot Record is de eerste sector van de harde schijf. Ten tweede is er de opstart-menulijst met de verschillende besturingssystemen. Die menulijst staat niet in de MBR, maar in /boot/grub/menu.lst op de actieve Linuxpartitie.

Als u nu Grub herstelt in de MBR, dan moet u hem daarna dus weer even vertellen waar hij de al bestaande opstart-menulijst kan vinden.

Reparatie als volgt:

Start de computer vanaf de Ubuntu Desktop CD (Live-CD).

Open een terminalschermpje (Applications - Accessories - Terminal).

Tik in: sudo grub

en druk op Enter. Dit start Grub zelf op.

Typ root (hd0,0) en druk op Enter (als uw Linux rootpartitie op sda1 staat; Grub telt vanaf 0, vandaar dat het cijfer één lager is). Partitie 1 = 0, partitie 2 = 1, enzovoorts. Hoewel Ubuntu een harde schijf “sda” noemt, gebruikt Grub de aanduiding “hd0″.

Staat de Linux rootpartitie bijvoorbeeld op sda6, dan is de terminaltoverspreuk “root (hd0,5)”. Hiermee vertelt u Grub waar de actieve Linuxpartitie zit. Staat Ubuntu op een fysieke tweede harde schijf, dan is het niet hd0 maar hd1 voor Grub. Dus bijvoorbeeld root (hd1,5)

Tik in: setup (hd0)

en druk op Enter. Hiermee installeert u Grub (opnieuw) in de MBR.

Ook bij twee harde schijven geldt: Grub zelf moet in de MBR van de eerste harde schijf, dus dit commando blijft dan hetzelfde.

Tik in: quit

en druk op Enter.

Herstart de computer. Haal de CD eruit en start normaal op.

Nu ziet u alleen Linux staan in Grub, maar nog geen Windows. Die zult u er handmatig in moeten zetten. Zo zet u de Windowsregels alsnog in het menu van Grub: Windowsregels (onder punt 2)

3. Grub verwijderen (terug naar uitsluitend Windows)

Kort gezegd komt dit neer op het vervangen van Linux opstartlader Grub, door Microsoft opstartlader NT Loader, in de Master Boot record (MBR) van de harde schijf.

a. Met de Windows XP installatie-CD

Start vanaf een Windows XP installatie-CD en kies R voor herstellen of repareren. Er komt nu een consolescherm met een menu.

Kies het nummer van de windowspartitie (normaal gesproken 1 voor c:\windows ) en tik het administrator-wachtwoord in.

Installeer NT Loader met de achtereenvolgende twee opdrachten:

fixboot C:

fixmbr

Hierbij is C: de letter van de Windows-schijf.

b. Met de Windows Vista installatie-DVD

In Windows Vista gaat het iets anders dan in Windows XP. Namelijk als volgt:

1. Stop de Windows Vista installatieschijf in het DVD-station en start de computer.

2. Druk desgevraagd op een toets (spatiebalk is altijd veilig)

3. Kies een taal, tijd, valuta en andere onzin die niet relevant is voor een herstelprocedure, en druk op Next.

4. Klik op Repair your computer.

5. Klik op het besturingssysteem dat u wil “repareren”, en klik daarna op Next.

6. In de Systeemherstel-opties, klik op Command prompt.

7. Tik in:  Bootrec.exe /Fixboot en druk daarna op Enter.

(let op: er staat een spatie tussen Bootrec.exe en /Fixboot )

8. Tik daarna in: Bootrec.exe /FixMbr  en druk op Enter

c. Zonder Windows installatie-CD of -DVD

Geen installatie-CD of -DVD van Windows? Dan kunt u NT Loader ook terugzetten met behulp van de Super Grub Disk of de Ultimate Boot CD.
Met behulp van Google zijn deze gratis programma’s makkelijk te vinden.

Voor Windows XP kan het ook met een diskette: Start uw PC op met een opstartbare DOS-diskette en voer het volgende commando uit in een DOS-venstertje:  fdisk /mbr

(let op: er staat een spatie tussen fdisk en /mbr ).

tux de luxe Gevorderden

Grub Install Howto

January 6th, 2009
Comments Off

Dit doe je trouwens met:

Code:
grub-install /dev/hda

Of vanuit grub zelf met:

Code:
grub> setup (hda)

tux de luxe Gevorderden

Grub Multiboot Howto.

January 6th, 2009
Comments Off

1. Waarom?

Ik wilde alle besturingssystemen kunnen booten zonder meerdere menu’s te doorlopen. Ik weet dat ik NT bovenop win9x bovenop DOS kan installeren. Ik zou het NT menu moeten doorlopen en vervolgens het win9x menu om DOS te kunnen booten. Ik wilde deze besturingssystemen onmiddellijk kunnen booten.

Het zag ernaar uit dat dit een behoorlijke uitdaging zou zijn. Het probleem met Microsoft besturingssystemen is dat ze allen vanaf de primaire partitie willen booten. Hier komt GRUB ter sprake. Het kan primaire partities verbergen. Je kunt tot 3 partities gebruiken om Microsoft besturingssystemen te installeren. GRUB zal de andere 2 partities zodanig verbergen dat de andere besturingssystemen het niet zullen zien. Dit betekent dat je een andere partitie nodig zal hebben om gegevens tussen DOS, Win9x en Windows 2000 te delen. De 4e partitie wordt gebruikt als extended partitie.

Ik wilde ook een menusysteem en GRUB voorziet hierin op fraaie wijze.

Een andere mooie faciliteit van GRUB is dat het reiserfs ondersteunt zodat ik mijn /boot bestand niet op een aparte ext2 partitie hoef te houden.

2. Installatieprocedure

2.1 Prepareren van de diskettes

Je hebt 3 diskettes nodig. Maak van de eerste diskette een DOS systeemdisk. Kopieer fdisk.exe en sys.exe naar deze diskette.

FORMAT /S A:
COPY FDISK.EXE A:
COPY SYS.EXE A:

Gebruik je tweede diskette om een Windows 98 rescuedisk te maken. Je zal spoedig de derde diskette voor GRUB gebruiken.

2.2 Linux installeren

Installeer je favoriete Linux-distributie. Je zal fdisk moeten gebruiken om je harddisk te partitioneren. Bereken vooraf hoeveel diskruimte elk van je besturingssystemen in beslag zal nemen.

Zo partitioneerde ik mijn harddisk:

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1             1         6     48163+  16  Hidden FAT16
/dev/hda2             7        19    104422+  16  Hidden FAT16
/dev/hda3            20       593   4610655   1b  Hidden Win95
FAT32
/dev/hda4           594      3737  25254180    5  Extended
/dev/hda5           594       848   2048256    6  FAT16
/dev/hda6           849      2123  10241406    7  HPFS/NTFS
/dev/hda7          2124      2140    136521   82  Linux swap
/dev/hda8          2141      2523   3076416   83  Linux

Mijn eerste partitie is voor het booten van Windows 2000. 10MG zou hier ruim voldoende voor moeten zijn. Op deze partitie zullen alleen de bestanden staan die nodig zijn om NT te booten, zoals boot.ini, ntldr, ntdetect.com, enz… NT zal voorkomen op partitie 6 in mijn voorbeeld. Deze partitie is een Hidden FAT16.

De tweede partitie is voor DOS. Ik achtte 100M voldoende. Ook dit is een FAT16

De derde partitie is voor Win9x. Ik kende het 5G toe en maakte er voor de performance een FAT32 van.

Maak vervolgens de extended partitie aan van de rest van je harddisk. Dit komt tevoorschijn als partitie 4 onder fdisk.

Maak een partitie van 2GB aan. Deze partitie wordt gebruikt om gegevens tussen alle besturingssystemen te delen. Zorg dat het totaal van alle bovenstaande partities minder is dan 8GB. Dit is een beperking van DOS.

Maak vervolgens je Windows 2000 partitie aan. Ik gaf het 10G aangezien deze windows een opgeblazen varken is. Voor de snelheid maakte ik er een HPFS/NTFS partitie van.

Voeg dan je swappartitie en linuxpartitie toe. Zorg dat je geen aparte partitie voor /boot hebt. Het ziet er in GRUB beter uit als je /boot in de rootpartitie houdt.

Ga je gang nadat je linux hebt geïnstalleerd en formatteer de fat16 partities:

mkdosfs /dev/hda1
mkdosfs /dev/hda2
mkdosfs /dev/hda6

2.3 GRUB installeren

Zorg dat je de laatste versie van GRUB hebt. Ik gebruik versie 0.5.96.1. De versie die met mijn distributie werd geleverd was verouderd en bezorgde me heel wat ongerief. Je kunt de laatste versie downloaden vanaf http://www.fsf.org.

Nu zal je GRUB op de diskette gaan installeren. Je installeert het nog niet op de harddisk omdat Windows 2000 het zal overschrijven.

grub-install '(fd0)'

Maak voor GRUB de volgende menu.lst aan. Dit bestand komt voor in /boot/grub.

#
# Voorbeeld van een configuratiebestand voor een bootmenu
#

# Boot automatisch na een minuut.
timeout 60

# Boot standaard het besturingssysteem in het tweede record.
default 1

# Val terug op het eerste record.
fallback 0

title Windows 2000
unhide (hd0,0)
hide (hd0,1)
hide (hd0,2)
rootnoverify (hd0,0)
chainloader +1
makeactive

# Voor het booten van Linux
title  Linux
root (hd0,7)
kernel /boot/vmlinuz-2.2.17 root=/dev/hda8 video=matrox:vesa:261

title Windows 98
hide (hd0,0)
hide (hd0,1)
unhide (hd0,2)
rootnoverify (hd0,2)
chainloader +1
makeactive

title DOS 6.22
hide (hd0,0)
unhide (hd0,1)
hide (hd0,2)
rootnoverify (hd0,1)
chainloader +1
makeactive

# Voor het booten van Linux
title  Linux (single user)
root (hd0,7)
kernel /boot/vmlinuz-2.2.17 root=/dev/hda8 video=matrox:vesa:261
single

title Partition 2 (floppy)
hide (hd0,0)
unhide (hd0,1)
hide (hd0,2)
chainloader (fd0)+1

title Partition 3 (floppy)
hide (hd0,0)
hide (hd0,1)
unhide (hd0,2)
chainloader (fd0)+1

Controleer of je linux met de diskette kunt booten. Als je problemen ondervindt dan kun je via de opdrachtregel van GRUB uitzoeken wat er aan de hand is. GRUB is zeer goed gedocumenteerd, dus als je problemen ondervindt, kijk dan alsjeblieft in de documentatie.

2.4 Windows 2000 installeren:

Voor het installeren van Windows 2000 moest ik de eerste partitie initialiseren. Doe de DOS systeemdisk in het diskettestation en start je computer opnieuw op. Zodra je de DOS-prompt krijgt, doe je het volgende:

FDISK /MBR
SYS C:

Nu kun je verdergaan en windows 2000 installeren. Op een bepaald moment zal Windows 2000 je vragen naar de partitie waarop je wilt dat het zal worden geïnstalleerd. De partitie die je met fdisk aanmaakte zal tevoorschijn komen als een beschadigde of ongeformatteerde partitie. Ga je gang en selecteer het.

Wijzig een bestand genaamd boot.ini dat te vinden zou moeten zijn op station C: om het Windows 2000 menu te verbergen.

[boot loader]
timeout=0
default=multi(0)disk(0)rdisk(1)partition(1)\WINNT
[operating systems]
...

2.5 DOS installeren

Doe de GRUB disk in het diskettestation. Doe de DOS systeemdisk erin zodra je het menu ziet. Selecteer partition 2 (floppy) uit het menu. Druk op Enter. Hiermee zal vanaf de diskette worden geboot en zullen de partities 1 en 3 verborgen worden.

Start FDISK en controleer of station C: partitie 2 is. Installeer vervolgens DOS:

SYS C:

2.6 Windows 98 installeren

Doe de GRUB disk in het diskettestation. Doe de Windows 98 rescuedisk erin zodra je het menu ziet. Selecteer partition 3 (floppy) uit het menu. Druk op Enter. Hiermee zal vanaf de diskette worden geboot en zullen de partities 1 en 2 verborgen worden.

Start FDISK en controleer of station C: partitie 3 is. Installeer vervolgens Windows 98:

SYS C:

2.7 De laatste loodjes

Test of alles functioneert vanuit GRUB:

Je zou alle 4 de besturingssystemen vanaf de GRUB diskette moeten kunnen booten.

Als alles er goed uit lijkt te zien dan kun je verder gaan en GRUB op je harddisk installeren. Typ vanuit Linux:

grub-install /dev/hda

Je zou nu vanuit het GRUB menu alle 4 de besturingssystemen moeten kunnen booten. Veel plezier!

tux de luxe Gevorderden

WordPress Loves AJAX