Thursday, October 16, 2014

How to Install Any Version of Windows from Other Network Computers

Talk about a complex thing to do: installing Windows over the network. Even installing it via a USB drive is simpler. However, this doesn’t mean it cannot be done. Using a free tool named Serva and a bit of time and attention, anyone can set up his/her network environment so that Windows installations are performed with ease, from one network computer. Here’s how the whole process works!

VERY IMPORTANT Prerequisites

There are many things you need to prepare beforehand, so that everything works smoothly. Please don’t skip any of these elements or the likelihood of failure will be high:
  1. You need to download and extract a little tool named Serva. Download the appropriate version for your operating system (32-bit or 64-bit). You will notice that there are a "Non-Supporter" version and a "Supporter" version. The free one is the "Non-Supporter" version. It includes a small annoyance when you start it, plus a few limitations that won’t impact you unless you are a network admin or IT professional who needs to install lots of operating systems on many network computers. If you are such a professional, go ahead and purchase the "Supporter" version which costs a fair $29.99.
  2. This software is a bit finicky. It doesn’t like long folder structures and installation folders, spaces and special characters. Therefore, extract it in a folder with a short name, directly on the root of one of your computer’s partitions. For example, I extracted it at "D:\SERVA". Choose a similar path on your computer. How to install Windows over the network with Serva
  3. You need the original installation files for the operating system(s) you want to install over the network. Have them at hand as you will need to copy them to a special folder, as they are, without modifications.
  4. For the computers where you are about to install Windows over the network, identify their exact network card model(s). Then, download the appropriate drivers for the Windows version you are about to install on them. By default, Windows setup programs support a limited number of network cards. If your system is rather new, then it is very likely that it won’t support its network card and the installation procedure will fail.
  5. Every time you run Serva, run it as administrator. This way it has the required permissions to create files, save the settings you make, etc.
  6. When you run Serva, make sure that it is not blocked by your firewall. The application must be set as allowed on the computer where it runs, otherwise it won’t be able to transfer anything over the network.
  7. The computer where the installation files are stored and the one where you want to install Windows must be part of the same network. This means that you have a router on your home network, managing network IP addresses and network traffic. If not, then you should directly connect the two computers with a crossover cable.

Step 1 - Run Serva & Make Its Initial Configuration

Run Serva as administrator. The free version will ask you to wait for 7 seconds before you can use it. Once the wait is over, click "Thanks, not today".
How to install Windows over the network with Serva
Its window is now open. Click Settings.
How to install Windows over the network with Serva
First, go to the DHCP tab. If your computers are part of the same network and the management of IP Addresses is taken care of by your router, enable these settings: proxyDHCP and BINL.
How to install Windows over the network with Serva
BINL is a special add-on that acts as a DHCP protocol extension and it is used by Serva during its preparation and maintenance procedures. proxyDHCP is a special setting that tells Serva that it doesn’t need to act as a DCHP server in order to provide IP addresses to the computers connecting to it.
Even though Serva’s developers don’t recommending enabling this setting, we have learned in our testing that it helps eliminate some issues. Therefore, also enable the box which says "Bind DHCP to this address" and leave the default IP address that is provided.
How to install Windows over the network with Serva
There is no need to modify other settings in this tab. Next, go to the TFTP tab.
TFTP comes from Trivial File Transfer Protocol and it is the protocol used by Serva to transfer files over the network. This protocol needs a bit of configuration as well.
First, check the box near TFTP Server. Then, you need to specify the so called "root" directory. This is the directory where you plan to store the Windows installation files. This folder can be the same folder where you extracted Serva or a new one. Keep in mind that you should use short paths and avoid using spaces and special characters (*, &, ", etc) in the directory name or its path.
How to install Windows over the network with Serva
To help eliminate problems in some networking environments, you might want to also check the box near "Bind TFTP to this address" and leave the default IP address unchanged.
How to install Windows over the network with Serva
Press OK to save your settings. Then close Serva and start it again (as administrator). During the restart, it will create a special folder structure in the root folder you specified.
How to install Windows over the network with Serva
Amongst those folders, you must find one named WIA_WDS and another named WIA_RIS. If they are not found inside the root folder you specified, something went wrong with Serva’s configuration. If all is well, go ahead and read the next section in this article.

Step 2 - Copy the Windows Installation Files

Go to the root folder you specified. Here, you need to copy the Windows installation files, as they are, without any modifications from your side.
If you want to install older versions of Windows like Windows XP or Windows 2000, you need to copy those files in the WIA_RIS folder. Since these operating systems are very old and we don’t recommend using them, we won’t provide specific instructions for them.
If you plan to install Windows Vista, Windows 7 or Windows 8, then open the WIA_WDS folder. There, create a new folder named according to the Windows version you want to copy. Use simple folder names, with no spaces or special characters. For example, I used Windows_7.
How to install Windows over the network with Serva
Create separate folders, with different names for all the Windows versions you plan to install over the network, using Serva.
Inside that folder, copy and paste all the installation files for the Windows version you want to install over the network. Simply go to the root of the installation disc, and copy its entire file and folder structure.

Step 3 - Start Serva

Start Serva again, as administrator and wait for it to detect the installation files you added. It will create its special folder structure, required to distribute the installation files over the network.
Then, close Serva and go to the next step.

Step 4 - Copy the Network Card Driver(s)

Next, you need to copy the network card drivers for the computer(s) on which you want to install Windows.
Go the folder where you copied the installation files. In my case it was "D:\serva" (both the root and Serva installation folder), followed by "WIA_WDS\Windows_7".
How to install Windows over the network with Serva
There, go to "$OEM$\$1\Drivers\NIC". If you can’t find these folders, create them yourself.
Then, extract the network card drivers and place them inside. If your drivers come as a setup.exe or as a self-extractable archive, extract it first. Make sure the driver’s ".inf" and ".cat" files are stored directly in the NIC folder.

Step 5 - Share WIA_WDS Folder with the Network

In order for Serva to distribute the Windows installation files over the network, they need to be shared with the network, so that other computers can access them. Unfortunately, Serva requires you to share the WIA_WDS folder (and not its subfolders or other folders) using a very specific share name: WIA_WDS_SHARE. Using any other share name means that the installation procedure is likely to fail.
How to install Windows over the network with Serva
To share this folder with the name we mentioned, you first need to enable advanced sharing in Windows and then share it. Here’s how advanced sharing works in Windows: Share Libraries or Folders Using Advanced Sharing.
You must give the user Everyone read-only permissions. You can also share this folder with specific user accounts, whose login details you will use later on, during the network installation process. Again, read-only permissions are enough.

Step 6 - Start Serva

Start Serva again, using administrator permissions. It will detect the network drivers you added and make a few changes, so that the drivers are distributed correctly when you launch the installation process on other computers. You can now leave it open and waiting for network connections.
Next, go to the computer(s) where you want to install Windows.

Step 7 - On the Target PC - Enable Lan Booting & Boot from the Network

Go to the computer where you want to install Windows and enter its BIOS. Make sure networking booting is enabled. This setting can be named "Boot from the network" or "Boot from PXE".
Then, start the computer and press the required key to bring up the Boot Menu. On most computers, you need to press F12 or F8, depending on the BIOS version. Select Network or PXE (again, this depends on your computer’s BIOS), to boot from the network, using Serva.
How to install Windows over the network with Serva
If all is well, you should see a screen similar to the one below, where the computer’s MAC is displayed and the network card requests an IP address via DHCP.
How to install Windows over the network with Serva
When the computer is connected to the network, Serva loads and displays a screen with the operating systems available for installation. Pick the one you want and press ENTER.
How to install Windows over the network with Serva
The installation files are loaded and a small window named ServaPENet is shown. At this step, Serva installs the network driver you added earlier, loads network resources and connects to the Windows installation folder. Depending on how you shared the WIA_WDS folder, it will ask you to provide a username and password to access it. Type the details of the user account you shared it with and connect.
If all went well, the Windows installation process is now started.

Step 8 - Install Windows Over the Network

Next, continue with the Windows installation, as usual. If you plan to install Windows 8, check this installation guide: How to Install Windows 8 RTM on Your Computer.
If you plan to instal Windows 7, check this article: How to Install Windows 7 - Complete Round of Installation Guides.

Troubleshooting Problems with Serva

If you don’t pay attention to all the steps in this procedure, some things are likely to fail. Here are some things we learned while experimenting with this tool:
  • If ServaPENet returns this error: "Failed No NIC/Driver, Aborting!", it means that you forgot to copy the network card drivers as instructed at Step 4. If you copied them and you still get the error, double check that you have the correct driver for the network card of the computer where you want to install Windows, for the Windows version you are about to install. Also, double check that you copied it to the correct folder. Then, restart Serva to make sure it detects the driver before the network installation procedure starts.
  • If, on the target computer, Serva is not able to load at all over the network, consider enabling the "Bind DHCP to this address" and "Bind TFTP to this address" settings in the DHCP and TFTP tabs.
  • If you connected two computers directly, with a crossover cable, you need to set Serva as DHCP server, in order for everything to work. This means setting the 1st address available in the IP pool, the pool size, and the subnet mask to be used when Serva assigns IP addresses. How to install Windows over the network with Serva
  • One last piece of advice is to check the Serva logs. The messages shown there can help you troubleshoot different problems.
Another good tip is to restart Serva every time you change any of its settings and every time you add something to its root folder.
Since we are not the developers of this software, we cannot provide support for it and help you with all the issues you might encounter. If our guide does not help you, then double check Serva’s documentation - Serva PXE/BINL - AN01: Windows Install and advanced configuration guide - Advanced Topics on TFTP.

Conclusion

As you can see from this guide, setting things up with Serva requires quite a bit of time and attention. However, it is the simplest way of installing any modern version of Windows over the network. It works great both for home networks and small or medium sized business networks.

Wednesday, September 17, 2014

Configuring FTP in CentOs



Fixing permissions


Thursday, August 7, 2014

Structure within structure in C

Nested structure in C is nothing but structure within structure. One structure can be declared inside other structure as we declare structure members inside a structure. The structure variables can be a normal structure variable or a pointer variable to access the data. You can learn below concepts in this section.
    1. Structure within structure in C using normal variable
    2. Structure within structure in C using pointer variable

1. Structure within structure in C using normal variable:

           This program explains how to use structure within structure in C using normal variable. “student_college_detail’ structure is declared inside “student_detail” structure in this program. Both structure variables are normal structure variables.
Please note that members of “student_college_detail” structure are accessed by 2 dot(.) operator and members of “student_detail” structure are accessed by single dot(.) operator.
#include 
#include 

struct student_college_detail
{
    int college_id;
    char college_name[50];
};

struct student_detail 
{
    int id;
    char name[20];
    float percentage;
    // structure within structure
    struct student_college_detail clg_data;
}stu_data;

int main() 
{
    struct student_detail stu_data = {1, "Raju", 90.5, 71145,
                                       "Anna University"};
    printf(" Id is: %d \n", stu_data.id);
    printf(" Name is: %s \n", stu_data.name);
    printf(" Percentage is: %f \n\n", stu_data.percentage);

    printf(" College Id is: %d \n", 
                    stu_data.clg_data.college_id);
    printf(" College Name is: %s \n", 
                    stu_data.clg_data.college_name);
    return 0;
}

Output:

Id is: 1
Name is: Raju
Percentage is: 90.500000
College Id is: 71145
College Name is: Anna University

Structure within structure in C using pointer variable:

           This program explains how to use structure within structure in C using pointer variable. “student_college_detail’ structure is declared inside “student_detail” structure in this program. one normal structure variable and one pointer structure variable is used in this program.
Please note that combination of .(dot) and ->(arrow) operators are used to access the structure member which is declared inside the structure.
#include 
#include 

struct student_college_detail
{
    int college_id;
    char college_name[50];
};

struct student_detail 
{
    int id;
    char name[20];
    float percentage;
    // structure within structure
    struct student_college_detail clg_data; 
}stu_data, *stu_data_ptr;

int main() 
{
  struct student_detail stu_data = {1, "Raju", 90.5, 71145, 
                                    "Anna University"};
    stu_data_ptr = &stu_data;

    printf(" Id is: %d \n", stu_data_ptr->id);
    printf(" Name is: %s \n", stu_data_ptr->name);
    printf(" Percentage is: %f \n\n", 
                         stu_data_ptr->percentage);

    printf(" College Id is: %d \n", 
                         stu_data_ptr->clg_data.college_id);
    printf(" College Name is: %s \n", 
                      stu_data_ptr->clg_data.college_name);

    return 0;
}

Output:

Id is: 1
Name is: Raju
Percentage is: 90.500000
College Id is: 71145
College Name is: Anna University

C – Passing structure to function

  • A structure can be passed to any function from main function or from any sub function.
  • Structure definition will be available within the function only.
  • It won’t be available to other functions unless it is passed to those functions by value or by address(reference).
  • Else, we have to declare structure variable as global variable. That means, structure variable should be declared outside the main function. So, this structure will be visible to all the functions in a C program.

Passing structure to function in C:

It can be done in below 3 ways.
    1. Passing structure to a function by value
    2. Passing structure to a function by address(reference)
    3. No need to pass a structure – Declare structure variable as global

Example program – passing structure to function in C by value:

           In this program, the whole structure is passed to another function by value. It means the whole structure is passed to another function with all members and their values. So, this structure can be accessed from called function. This concept is very useful while writing very big programs in C.
#include 
#include 

struct student 
{
            int id;
            char name[20];
            float percentage;
};

void func(struct student record);

int main() 
{
            struct student record;

            record.id=1;
            strcpy(record.name, "Raju");
            record.percentage = 86.5;

            func(record);
            return 0;
}

void func(struct student record)
{
            printf(" Id is: %d \n", record.id);
            printf(" Name is: %s \n", record.name);
            printf(" Percentage is: %f \n", record.percentage);
}

Output:

Id is: 1
Name is: Raju
Percentage is: 86.500000

Example program – Passing structure to function in C by address:

           In this program, the whole structure is passed to another function by address. It means only the address of the structure is passed to another function. The whole structure is not passed to another function with all members and their values. So, this structure can be accessed from called function by its address.
#include 
#include 

struct student 
{
           int id;
           char name[20];
           float percentage;
};

void func(struct student *record);

int main() 
{
          struct student record;

          record.id=1;
          strcpy(record.name, "Raju");
          record.percentage = 86.5;

          func(&record);
          return 0;
}

void func(struct student *record)
{
          printf(" Id is: %d \n", record->id);
          printf(" Name is: %s \n", record->name);
          printf(" Percentage is: %f \n", record->percentage);
}

Output:

Id is: 1
Name is: Raju
Percentage is: 86.500000

Example program to declare a structure variable as global in C:

           Structure variables also can be declared as global variables as we declare other variables in C. So, When a structure variable is declared as global, then it is visible to all the functions in a program. In this scenario, we don’t need to pass the structure to any function separately.
#include 
#include 

struct student 
{
            int id;
            char name[20];
            float percentage;
};
struct student record; // Global declaration of structure

void structure_demo();

int main() 
{
            record.id=1;
            strcpy(record.name, "Raju");
            record.percentage = 86.5;

            structure_demo();
            return 0;
}

void structure_demo()
{
            printf(" Id is: %d \n", record.id);
            printf(" Name is: %s \n", record.name);
            printf(" Percentage is: %f \n", record.percentage);
}

Output:

Id is: 1
Name is: Raju
Percentage is: 86.500000

Wednesday, August 6, 2014

Memory : Stack vs Heap

7. Memory : Stack vs Heap






Stack vs Heap

So far we have seen how to declare basic type variables such as intdouble, etc, and complex types such as arrays and structs. The way we have been declaring them so far, with a syntax that is like other languages such as MATLAB, Python, etc, puts these variables on the stack in C.

The Stack

What is the stack? It's a special region of your computer's memory that stores temporary variables created by each function (including the main() function). The stack is a "FILO" (first in, last out) data structure, that is managed and optimized by the CPU quite closely. Every time a function declares a new variable, it is "pushed" onto the stack. Then every time a function exits, all of the variables pushed onto the stack by that function, are freed (that is to say, they are deleted). Once a stack variable is freed, that region of memory becomes available for other stack variables.
The advantage of using the stack to store variables, is that memory is managed for you. You don't have to allocate memory by hand, or free it once you don't need it any more. What's more, because the CPU organizes stack memory so efficiently, reading from and writing to stack variables is very fast.
A key to understanding the stack is the notion that when a function exits, all of its variables are popped off of the stack (and hence lost forever). Thus stack variables are local in nature. This is related to a concept we saw earlier known as variable scope, or local vs global variables. A common bug in C programming is attempting to access a variable that was created on the stack inside some function, from a place in your program outside of that function (i.e. after that function has exited).
Another feature of the stack to keep in mind, is that there is a limit (varies with OS) on the size of variables that can be store on the stack. This is not the case for variables allocated on the heap.
To summarize the stack:
  • the stack grows and shrinks as functions push and pop local variables
  • there is no need to manage the memory yourself, variables are allocated and freed automatically
  • the stack has size limits
  • stack variables only exist while the function that created them, is running

The Heap

The heap is a region of your computer's memory that is not managed automatically for you, and is not as tightly managed by the CPU. It is a more free-floating region of memory (and is larger). To allocate memory on the heap, you must use malloc() or calloc(), which are built-in C functions. Once you have allocated memory on the heap, you are responsible for using free() to deallocate that memory once you don't need it any more. If you fail to do this, your program will have what is known as a memory leak. That is, memory on the heap will still be set aside (and won't be available to other processes). As we will see in the debugging section, there is a tool called valgrind that can help you detect memory leaks.
Unlike the stack, the heap does not have size restrictions on variable size (apart from the obvious physical limitations of your computer). Heap memory is slightly slower to be read from and written to, because one has to use pointers to access memory on the heap. We will talk about pointers shortly.
Unlike the stack, variables created on the heap are accessible by any function, anywhere in your program. Heap variables are essentially global in scope.

Stack vs Heap Pros and Cons

Stack

  • very fast access
  • don't have to explicitly de-allocate variables
  • space is managed efficiently by CPU, memory will not become fragmented
  • local variables only
  • limit on stack size (OS-dependent)
  • variables cannot be resized

Heap

  • variables can be accessed globally
  • no limit on memory size
  • (relatively) slower access
  • no guaranteed efficient use of space, memory may become fragmented over time as blocks of memory are allocated, then freed
  • you must manage memory (you're in charge of allocating and freeing variables)
  • variables can be resized using realloc()

Examples

Here is a short program that creates its variables on the stack. It looks like the other programs we have seen so far.
#include 

double multiplyByTwo (double input) {
  double twice = input * 2.0;
  return twice;
}

int main (int argc, char *argv[])
{
  int age = 30;
  double salary = 12345.67;
  double myList[3] = {1.2, 2.3, 3.4};

  printf("double your salary is %.3f\n", multiplyByTwo(salary));

  return 0;
}
double your salary is 24691.340
On lines 10, 11 and 12 we declare variables: an int, a double, and an array of three doubles. These three variables are pushed onto the stack as soon as themain() function allocates them. When the main() function exits (and the program stops) these variables are popped off of the stack. Similarly, in the functionmultiplyByTwo(), the twice variable, which is a double, is pushed onto the stack as soon as the multiplyByTwo() function allocates it. As soon as themultiplyByTwo() function exits, the twice variable is popped off of the stack, and is gone forever.
As a side note, there is a way to tell C to keep a stack variable around, even after its creator function exits, and that is to use the static keyword when declaring the variable. A variable declared with the static keyword thus becomes something like a global variable, but one that is only visible inside the function that created it. It's a strange construction, one that you probably won't need except under very specific circumstances.
Here is another version of this program that allocates all of its variables on the heap instead of the stack:
#include 
#include 

double *multiplyByTwo (double *input) {
  double *twice = malloc(sizeof(double));
  *twice = *input * 2.0;
  return twice;
}

int main (int argc, char *argv[])
{
  int *age = malloc(sizeof(int));
  *age = 30;
  double *salary = malloc(sizeof(double));
  *salary = 12345.67;
  double *myList = malloc(3 * sizeof(double));
  myList[0] = 1.2;
  myList[1] = 2.3;
  myList[2] = 3.4;

  double *twiceSalary = multiplyByTwo(salary);

  printf("double your salary is %.3f\n", *twiceSalary);

  free(age);
  free(salary);
  free(myList);
  free(twiceSalary);

  return 0;
}
As you can see, using malloc() to allocate memory on the heap and then using free() to deallocate it, is no big deal, but is a bit cumbersome. The other thing to notice is that there are a bunch of star symbols * all over the place now. What are those? The answer is, they are pointers. The malloc() (and calloc() andfree()) functions deal with pointers not actual values. We will talk more about pointers shortly. The bottom line though: pointers are a special data type in C that store addresses in memory instead of storing actual values. Thus on line 5 above, the twice variable is not a double, but is a pointer to a double. It's an address in memory where the double is stored.

When to use the Heap?

When should you use the heap, and when should you use the stack? If you need to allocate a large block of memory (e.g. a large array, or a big struct), and you need to keep that variable around a long time (like a global), then you should allocate it on the heap. If you are dealing with realtively small variables that only need to persist as long as the function using them is alive, then you should use the stack, it's easier and faster. If you need variables like arrays and structs that can change size dynamically (e.g. arrays that can grow or shrink as needed) then you will likely need to allocate them on the heap, and use dynamic memory allocation functions like malloc()calloc()realloc() and free() to manage that memory "by hand". We will talk about dynamically allocated data structures after we talk about pointers.

Return multiple values in C

Method 1 : Using Array
  • If more than two variables of same type is to be returned then we can use array .
  • Store each and every value to be returned in an array and return base address of that array.
Method 2 : Using Pointer and One Return Statement
  • Pointer Variable can updated directly using  Value at ['*'] Operator.
  • Usually Function can return single value.
  • If we need to return more than two variables then update 1 variable directly using pointer and return second variable using ‘return Statement‘. [ Call by Value + Call by Reference ]
EX:

#include

int* function2(int a){
    int* array = (int*)malloc(2);
    int b=(65*a)/100;
    int c=5*8;
    array[0]=b;
    array[1]=c;
    return array;
}

int main(void)
{
    int a=18,i;
    int* array;
    array=function2(a);

   for(i=0;i<2 div="" i="">
   {
        printf("array[%d]: %d\n",i,array[i]);
    }
    free(array);
    
     getch();  
}

Method 3 : Using Structure 
  • Construct a Structure containing values to be returned and then return the base address of the structure to the calling function.
EX:

#include

struct dont { int x; double y; };

struct dont fred(void)
{
        struct dont b;
        b.x = 1;
        b.y = 91.99919;
        return b;
}

int main(int argc, char **argv)
{
        struct dont look = fred();
        printf("look.x = %d, look.y = %lf\n", look.x, look.y);
        getch();
        return 0;
}

Array of Pointers in C

#include
#include

struct name {
   int a;
   float b;
   char c[30];
};

int main(){
   struct name *ptr;
 
   int i,n;
   printf("Enter n: ");
   scanf("%d",&n);
 
   ptr=(struct name*)malloc(n*sizeof(struct name));
/* Above statement allocates the memory for n structures with pointer ptr pointing to base address */

   for(i=0;i       printf("Enter string, integer and floating number  respectively:\n");
       scanf("%s%d%f",&(ptr+i)->c,&(ptr+i)->a,&(ptr+i)->b);
     
   }
   printf("Displaying Infromation:\n");
   for(i=0;i       printf("%s\t%d\t%.2f\n",(ptr+i)->c,(ptr+i)->a,(ptr+i)->b);
     
       getch();
   return 0;
}