Computer Magic
Software Design Just For You
 
 

Installing Linux to a USB drive

December 22nd, 2005

First thing is to get Linux installed to the USB drive. The USB drive (again, can be any type of USB device that shows up as a drive in My Computer when plugged in) needs to have enough space for the install that you are requesting. For Red Hat Linux, we try to do a more complete install by picking custom or server options. This requires 4-7 gig of available space.

I installed on a Disk Go 120 Gig hard drive that supports both USB 2.0 and Firewire (but not both at the same time!).

Normally, you don’t get the option to install to removable or external drives. To turn this feature on, you need to type “expert” in at the boot prompt. This is the screen where you can see the FC Picture on the top of the screen, and text at the bottom that shows you the F keys that you can hit.

Once you type “expert” and continue, you will follow the install steps normally. At the point where you can partition your drives, you should see a new drive (/dev/sda or /dev/sdb) available for use. This is the USBdrive. USB Drives are mounted as sd? just like SCSI devices are.

Continue witht the rest of the installation normally. When asked where to instlal the boot loader (grub or lilo), pick the /dev/sd? drive! If you pick /dev/hd? you will mess up your existing operating systems boot loader. To make this change, you will have to pick the advanced settings button.

Once the install is done, if your motherboard supports booting directly from the USB device, then go into that bios and change the boot order. If everything works as it should, you should be able to boot strait to Linux from your USB device. To boot back to windows, go back into your bios and change the boot order back or unplug your USB device before booting your computer.

For those of you who don’t have a bios that supports booting from a USB device, then you will have to make a boot disk (putting the boot loader on your hard drive won’t cut it). Read the next topic for instructions on creating a boot disk.

Ray Pulsipher

Owner

Computer Magic And Software Design

Boot To USB Background

December 22nd, 2005

Ever look for clear information on how to do something in Linux? Some times information can be a bit difficult to decode. Here is a bit of background on what this project encompased.

As the instructor of the IT 190 Into to Linux class at Peninsula College, one of the biggest hurdles to overcome is how to make Linux available to the students when they are off campus. Making a server availalable is one solution, but I would prefer that they use Linux in their own homes.

We gave them each a copy of the Knoppix distribution and let them try it out. Unfortunatly, the fact that Knoppix runs off CD means that it doesn’t always preform the best. The other issue is that since it boots from CD, everything is mounted into a ram drive or read off the CD directly. This prevents students from just saving their work and forgetting about it. They have to mount floppies, USB drives, or even their current hard drive to preserve the work that they did.

Another option is for the students to use VM Ware of Virtual PC. Virtual PC is a good solution since your campus has an MSDN education license which makes MS owned software available to us. The main problem with VPC though is speed. Since it emulates an operating system within another computer, you need a decent speed computer with a LOT of memory (with a 2.7ghz computer and 2g ram, it runs pretty good for me). Another hang up is that some of the kernels need to be patched to work properly in VPC (want a prebuilt vhd file with FC3 already installed and patched, email me and we can work out how to send it, it is almost 600mb). VMWare performs better, but costs more.

The other option is for the student to work out the hard drive space to install Linux directly on their box (either by resizing existing partitions, or buying a new physical HDD). Some opt for this route and in the end have the most fun and success I think. The biggest issue is the risk and/or requirement of loosing existing data on their windows drive when partitions need to be resized or when learning, the student accidentally kills a partition they shouldn’t.

The last option, and the one we will explore further here, is to install Linux onto a USB drive (memory stick, external drive, anything as long as it has enough room).

Check the boot disk tutorial for more technical information.

Ray Pulsipher

Owner

Computer Magic And Software Design

PHP Tutorial – Lesson 5 Variables are those little furry creatures right?

December 21st, 2005

Now it is time to do some real programming… sort of. We want to start talking about the concept of a variable. Variables are simply places to hold information while the programming is running. Notice that I said “while the program is running”. Computers have memory, and they have hard drives. These are the primary storage mediums in a computer. Hard drives are cool, they store stuff permanently. Anything that is on the hard drive is still there if the power goes out. Memory is cool, it stores stuff in memory until the power goes out (power spike, turning off/rebooting the computer, etc).

Why use memory at all then? If the hard drive is permanent, what good is memory? Given our current discussion, it isn’t much good. Lets look at access speed though. A hard drive is measured in mili seconds. Most modern hard drives fall between 6-14 ms seek time. This the time it takes to locate a piece of data on the drive and start to read it. The problem is, hard drives are so huge, that the only way you can locate data on the drive (without scanning the whole thing) is to have an index that points to data locations. This index is your FAT table (FAT 32, NTFS, ext2, etc). This is great, but the problem is that you need to do a read of the index table to find the data before you can read it. Now, you have more than one seek possible. Once you have located a piece of data on your hard drive and the head is in position, the process of actually reading the data begins. If this data is large, it might take a while to actually transfer the data from the drive to the CPU (limited by bandwidth). Have you seen the UDMA 33, 66, 100, 133 ratings on drives? This corresponds to the bandwidth of the drive.

Now, lets talk about memory. The involved process of working with a drive isn’t the bad part, it is the seek time and bandwidth limits that causes the bottleneck. With memory, your seek time is measured in nano seconds and typically falls in the 6-14 range also. Additionally, memory doesn’t use an indexing algorithm to locate data, you simply keep track of the address and jump directly to the address. Since Memory has no moving parts, and a seperate index lookup isn’t required, memory is significantly faster. Memory bandwidth is also MUCH larger (bump that UDMA rating from 133 to 2000 or more!). The speed of memory is the reason that we have both a hard drive (for permanent storage) and memory (for temporary storage). Memory is our work space, hard drives are our file cabinents.

I mentioned in the previous paragraph that the memory is addressed directly rather than looked up. This means no nice file paths like a hard drive to keep track of our memory (c:\my documents\my picture.jpg). Do you want to remember AOFD243AA? That would be just madening (try doing some assembly language programming!). One way that programmers have come up with to ease the burden of keeping track of memory address is to set names. These named memory addresses are called variables. In PHP (and in all modern programming languages) you can simply use your variable without worrying where it is actually located.

Ok, enough theory… Lets do some code!!!



<?php
$first_name = "bob";
print "Your name is: $first_name";
?>

In PHP, you don’t actually have to create a variable. In some languages, you have to create a variable before using it. Here, to create a variable, you just assign it a value (“bob”). Notice that bob is in “s. Bob is data, not code, and therfore needs to be in “s. Also, notice that both lines (the assignment and the print) end with the ; symbol. Again, this is important to tell PHP that the current line is done (you can actually place them on the same line as long as the ; seperates them and it will work!).

To assign a value in PHP (and in most languages) you simply use the = sign. One thing that throws people new to programming is that the equation is written backwards. The value moves to the left. In kindergarden, we learned that 10+10=20. Here, we are learning that 20=10+10. It all still works, no change in the math, just a different way to write it.

All variables in PHP start with the $ symbol. This is a clue to PHP that the following word is a variable ($first_name). In the print line, notice that the variable is actually inside the quotes. This will still work (prints “Your name is: bob”) because the $ symbol tips PHP off that there is a varaible inside the string and it can replace the $first_name with the actual first name. A few other languages do this also (Perl for one).

Variables in PHP can be strings (a group of characters) or numbers. PHP handles the difference internally and has some great auto conversion features. All you have to do is assign the value and PHP handles it.



<?php
$var = 3;
$var = "Hi";
$var = "10";
$var = "the quick brown fox";
$var = 25;
print "The variable is $var";
?>

This will assign various values to the variable, and then print out the current value. Notice that only the last value is printed, as you assign a new value, the previous one is lost!

Once common usage for variables is to get the value send to the script. Here is an example:



<?php
$first_name = $_GET["first_name"];
$last_name = $_GET["last_name"];
print "Your name is $first_name $last_name";
?>

Add the ?first_name=bob&last_name=smith to the URL for this page, and watch it echo your name back to you. By grabbing the value out of the $_GET array to start with, it makes the code cleaner and easier to read later. It also gives you a chance to check the values coming in before you use them (what if they didn’t fill out the name at all, or if they injected some hacking code into it?).

There is LOTS more information on varaibles, look at other tutorials on the internet. I will be writing more on them soon (ever hear of variable varaibles?).

Ray Pulsipher

Owner

Computer Magic And Software Design

PHP Tutorial – Lesson 4 Tell me what to do!

December 20th, 2005

When writing a program, it is important to have the abillity to gather input from your users. Computers don’t really think for themselves, and they don’t read minds (which is good, because I mentally cuss at mine all day) so it is important to tell them what you want. We will use a simple example. How about http://www.amazon.com? More specifically, when you click to view the details of a particular book, you get a page that displays the detailed information about that book such as author, title, publisher, maybe a picture of the book, some comments from people who bought the book, a short description of the book, some reviews from professional reviewers, and the bank account of the guy who created amazon.

These pages that display this book information aren’t static. Every time you click on a different book, you actually get the same page. The only real difference is the book information pertains to the book you clicked. How does it know the difference? How does it know you want book A instead of book B? Lets look at an HTTP URL for some answers.


HTTP://www.cmagic.biz/wordpress/index.php?cat=3

The first part of this URL is the HTTP. HTTP specifies the protocol to use (posibilities include FTP, HTTP, LDAP, etc..). All web traffic (and I mean web pages, not email and such) travels over the HTTP protocol. It simply is the mechanism to get a page from one location to the other. Referring to our last discussion on output, the HTTP protocol would ship the output generated by our script to the browser.

The next part of the URL is the computer where the information is kept. In this case, it is www.cmagic.biz. This computer is the actual web server. This may or may not include the leading www. There are no real rules as to how many parts can make up a computer name (www.cmagic.biz,
www.email.cmagic.biz, bob.cmagic.biz,
abc.efg.hijk.lmnop.qrs.tuv.wx.yz.cmagic.biz; all valid names for computers). The few rules that do exist for computer names include rules on special characters. Numbers and dashes/underlines are ok, but not any other special characters. This means that when we hit the first / (other than the two after the protocol – ://) that we know we have moved from the name of the computer to a folder or file on that computer.

Once we hit the /, things change a bit. From here on out we are dealing with a file/folder path on that computer. For instance, if your web server was pointing to the c:\www directry on your hard drive, then the url path (the whole http://www.cmagic.biz portion is left out to avoid carpal tunnel
syndrome on my part) /index.php would be looking for the index.php file
located in the c:\www folder on your drive. If the url path was
/myfiles/index.php, then it would look for a sub folder of myfiles in the c:\www folder and then try to locate a file called index.php in that folder.
Lastly, after the folder/file path, we see a ?. This doesn’t always have to be there. The ? signifies that input is coming. A web page doesn’t hook directly to your keyboard, and it doesn’t directly hook to your screen.
Because of this, some ways had to be devised that would allow you to tell the script (page) what you want. After the ? is a name=value pair. You can send any name=value pair that you want. You can even send multiple name=value pairs if you seperate them with a & symbol. These symbols just give clues as to what is coming next (e.g. input data comes after the ?). To tell amazon which book you want to look at, there is a whole URL (with some extra information in it) and at the end is ?n=283155. The number is some internal indentifier that is assigned to that book. Often in the case of books, an ISBN number is appropriate. One of the things you might find on a URL is that some items are encoded (%20 is a space). This is so that characters can be put on the URL without messing up the order of things (what if you use the = sign in your value?).

Ok, now that we have talked about urls, lets look at a script.



<?php
print "Your name is: " . $_GET["name"];
?>

Upload this file to the server, and type in your URL to access the file. It should say “Your name is:” and end there. To actually have it display your name, add a ?name=bob on the end of the url and see what happens.

PHP is great because it does much of the tedious stuff for you, like when your script runs, it has already pulled all the information from the URL for you. This information is placed in an array. You can refer to any Name=Value pair that was passed to the script simply by substituting the name. For example, what if we changed things to first and last name?



<?php
print "Your first name is: " . $_GET["first"] . " and your last name is: " . $_GET["last"];
?>

Now change the URL to ?first=bob&last=smith. Notice that the in the array, we use first for the first name and last for the last name (same as on the URL). All variables (this includes arrays) starts with the $ sign. By using the [] we specify an item in an array. PHP supports keyed arrays which allows us to specify a slot by name (versus numbers). We will talk more about arrays later. Just know that you can get the value of any item on the URL by using $_GET[“your value name”]. It is inportant to put the name inside the quotes.

That is the basics of supplying input to a script. The other main wait to supply input to a script is via a POST rather than a GET. When you see stuff on the URL, it is almost always a GET. When you see data on the URL (stuff after the ?) it is always a GET. We will discuss this topic more in the
future. From the programming perspective, there is no real difference for retrieve information sent via a POST than retrieving information send via a GET. All information supplied on the URL is accessed through the $_GET array, and all information submitted via a POST is accessed through the $_POST array. Pretty simple.

One last note, when you don’t care where the information comes from (via
POST or GET), then you can use the $_REQUEST object. It is a combination of POST and/or GET variables, so it won’t matter which way the data was sent. We will demonstrate POSTing information in another tutorial.

Ray Pulsipher

Owner

Computer Magic And Software Design

PHP Tutorial – Lesson 3 Print statements everywhere!!!

December 19th, 2005

Welcome to tutorial 3. Today we are going to cover the concept of output. This is an important topic to understand and will compliment the information covered in the last tutorial.

All programs (web, application, windows, Linux, dos, etc..) have I/O
(Input/Output). For a Dos program (that black screen with white writing for you noobs… start -> run -> cmd), the input is the keyboard and the output is the console (that black screen again). Some programs do not
require any input. The fact that you are starting the program might be
enough. I have written scripts to process a web server log file (how many visitors, hits, etc…) and generate neat graphs and statistics. This was a very special custom script that worked great on my system, but would probly not work on yours. Why not? Because I hard coded all the information the script needed to function right into the script. The main thing it would need to know would be the location of the log file
(c:\windows\log_files\mylog.log). If you put this script on your computer and tried to make it run, it probly couldn’t find your log file because you keep yours in a different spot than mine.

We could add some Input capabilities and have it wait for you to type in the path to your log file. We could simply read the next line typed in at the keyboard. This sounds like a good idea, except that the user would be
sitting there staring at a blank screen. Their first reaction… “stupid
free internet code, this stuff is crap!”. What is wrong? The program is
sitting there with a blinking cursor waiting for input, but the user doesn’t know what to do. We need to prompt the user with some output. Something like “Please enter the file path to your log file:” should do it. We can do this by simply using your languages print statement. This print statement sends the stuff you tell it to print to the current default or standard output (the screen for a console program, or the browser for a PHP script).


<?php

print "Please enter the file path to your log file: ";
?>

In the script above, we tell the php script to output the prompt to the
requesting browser. Notice that the data (the text we want to print) is all contained in the “s. Since this is a PHP block, we have to contain all NON PHP code in “s. Take a look at this next PHP script.


Please enter the file path to your log file:

In this script, there are no PHP tags. Since there are no PHP tags, the PHP engine treats this as regular HTML. How does PHP deal with regular HTML? It simply treats it as if you had use the print statement to send it to the browser. Try them both out, they will have the same output: Please enter the file path to your log file:

Now, lets mix and match…


<?php

print "PHP Print 1
";
?> HTML Print 1
still HTML printing... <?php
print "PHP Print 2
";
?> HTML Print 2....
<?php
print "PHP Print 3
";
?> <?php
print "PHP Print 4
";
?> HTML print 3....

This script outputs text from both HTML and PHP. Notice that they happen in order. You don’t get all the PHP, then all the HTML, you get them in the order that the PHP processor finds them. This is a nice feature as it can be some what difficult to put a large quantity of HTML inside of “s. Very hard to read.

The point of all this is that the ultimate purpose of any PHP script is to generate some output and send it to the browser for review. It all happens through a series of print statements (either manual or automatically). This also means that you can do some cool stuff with the output before it gets shipped off. As an example, PHP allows you to compress your pages before sending it out on the wire and save you some bandwidth (as long as the
client browser understands zipped content). I myself have code that captures the output so that I can process it further before it goes to the browser (toss in number of page views, add a template to the page automatically,
etc.).

You might ask, if PHP can create its own output, then what does HTML have to do with anything? If you looked at these scripts, then you will know that they look pretty plain. By adding some HTML, we can liven things up and
make them look nice. HTML is not a language, it is a formatting
specification. We can create tables, set background images, and show links to more information. This is what makes HTML useful and why we use it in
conjunction with PHP. It is common for PHP to generate HTML on the fly by using various print statements. Think about ebay.com or amazon.com. They
both use a dynamic engine like PHP to generate their pages on the fly. Part of that is the outputting of HTML to turn the plain data into a killer website. The data is the information extracted from a database by the scripting engine and contains the book or item details, but the part that lines it up and adds some pictures and color is the HTML.

Notice that you can open/close many different PHP blocks in one script. You can do this as many times as you see fit. The best way to figure this stuff out is to play with it. Get some server space and upload some scripts and see what they do. Good luck 🙂

Ray Pulsipher

Owner

Computer Magic And Software Design


Home | My Blog | Products | Edumed | About Us | Portfolio | Services | Location | Contact Us | Embedded Python | College Courses | Quick Scan | Web Spy | EZ Auction | Web Hosting
This page has been viewed 871025 times.

Copyright © 2005 Computer Magic And Software Design
(360) 417-6844
computermagic@hotmail.com
computer magic