Stan Kurkovsky, PhD

Linux Notes

CS 355 - Fall 2007 - Introductory notes on using Linux (Knoppix) by Michael Graff

Getting Started

To download knoppix, head to http://www.knoppix.org. From there you can get a download of the latest live CD. The CD is a decent size, but the download moves fairly quickly over bit torrent.

If you're comfortable with making changes to the package, you can add or remove features. In particular you might want to remove the loud 'startup' voice from the CD to avoid hearing it during every boot.

Once you've obtained a CD, boot to it from the start of your computer. (Probably requires you to hit a key like F8 or F12 to get the boot menu) After booting from the CD you'll reach a screen with a knoppix splash screen and a small command prompt. From here you can pass booting options to knoppix. If you leave this screen unattended for too long it may start up in the default mode. You can mix most of the startup options, some useful ones are:

Knoppix

Default Startup

knoppix 2

Command Line startup only

knoppix my config = scan

Load a saved knoppix configuration

knoppix desktop=[wallpapername]   

Load /w a different wall paper.

If you're on a laptop and would like to turn down the sound before it begins the startup, you can enter runlevel 2 with the knoppix 2 option and then run xaumix from the prompt, which will allow you to turn down the volume.

Working with the Command Line

You may switch back and forth between the command line only mode and the x-windows system by typing telinit # to switch the runlevel.

  • telinit 2 - switch to command only
  • telinit 5 - switch to x-windows

One stipulation about the command line however is that you need to precede file names with a ./ (period slash) when you intend to run an executable in the current directory. For example if you have just compiled a program into an executable in the current directory and you wish to execute it you will likely have to type ./executable-name in order to run it, otherwise a file not found error will occur. This combination in Linux is telling the root shell to look in the current directory for the file.

Useful Shell Commands

Ls [-l]

Display Directory Contents

Cd

Change Directory

Pwd

Display Current Directory Path in full

Ps -a

Display all running processes

login [login name]    

Login as a user

telinit [number]

Change runlevel

FTP

Open command line ftp client

BC

Run the Unix Calculator (exit w/ Ctrl D)

Working with the X-windows System

You may want to begin by setting the root password, which is required for some super-user tasks. You can set this from the knoppix menu, set root password. Once you've set the root password you may also wish to create a number of user accounts, which will be needed later to test any programs that deal with handling multiple users.

The actual x-windows environment is fairly straightforward. There is a program menu in the lower left-hand corner, and a taskbar at the bottom of the screen. There are also multiple desktops, which programs can occupy.

Knoppix comes with several different text editors, but no development environment by default. A text editor and the GCC will suffice however. The default text editor is Kwrite (although you may consider using its variant, Kate, which has a collapsing terminal window for compiling and executing). Kwrite and its variants will do syntax highlighting, line numbering, and collapsing of code blocks. There are also shortcuts for commenting out code and indenting. The best part of the editor however, is that the GUI is very easy to use and intuitive, as opposed to grappling with the steep learning curve of one of the command line editors.

Knoppix is usually pretty intelligent about detecting most hardware. Wireless cards for laptops can be tricky however. In the best case knoppix will do all the work for you, in the worst it will not work at all. The network submenu, underneath the knoppix menu contains most of the programs you'll need to get it working. Start with the wireless configuration utility.

Knoppix -> Network -> WaveLan (wlcardconfig)

Field

Recommended Value     Description

SSID

SSID or Any SSID of network to connect to

Cell ID

Blank  

Channel

Blank Channel, empty for auto

Frequency

Blank Frequency, empty for auto

Encryption     

Key Encryption key if needed (No passcode support)

Misc.

Misc. if needed See iwconfig in man pages

If you've managed to find a proper card and set it up, netcardconfig (also in the network menu) will allow you to set or discover the ip. With that done you should open Kwifimanager, which will show the connection if it was successful. If the card doesn't seem to be detected properly, you may have to try a different driver, or use the ndsiswrapper with a windows driver. It might be best to consult the knoppix forums for further help on this. A USB flash drive is a good place to keep your files if you don't have a ready disk partition for holding them, and is easily set up. The USB drive should have an appropriate icon on the desktop. Right clicking on it and selecting properties will allow you to un-set the option for read-only. You may now mount and use the drive by right clicking and selecting mount, or double clicking. This applies similarly to hard drives. If the drive was already mounted (has a green arrow in the lower corner on the drive's icon) when you tried to change the read only status, you may have to un-mount and remount the drive in order for the change to take effect. In my tests knoppix seems to respect NTFS partitions, and will readily read from them. It appears to write to them safely as well, but I can't readily prove this, and any writing you do to your NTFS volume from knoppix is at your own risk.

Once you have a place where you are going to store your files, whether this is a USB drive or a hard drive partition, you can choose to save your current knoppix configuration to a file in your storage space. This will preserve your user settings, root password, user lists, desktop settings, and various program settings for next time. You can then restore this exact configuration by using knoppix myconfig=scan (scan or hda1, usb1, etc) during knoppix boot. You can also choose to create a persistent knoppix disk image, but this is a much more complicated method than simply saving the configuration periodically.

Writing Your First Linux Program

Open up Kwrite and type in

    main()
    {
        printf("Woof!");
    }

Save the file as hellodog.c in your working directory. Now go to your working directory and verify that the new file is there. From the file browser tools menu (the file explorer is called konqueror), select open konsole, which will open new knoppix shell that starts in the current directory. You can accomplish this by hitting F4 from konqueror. The konsole does not require a ./ to precede local executables, although it lacks some abilities that the root shell does have.

From the konsole command line, type:

    gcc hellodog.c -o hellodog

and hit return (That is a oh and not a zero after the dash). The GCC compiler should run and compile your code into an executable called hellodog. You can now execute it from the konsole by typing hellodog.

It's not recommended to use the int main() form, or void. If your file name happens to be long or you have multiple files you may want to consider using a makefile. Create a new text file in your working directory where your program's files are, and name it simply makefile. The format of the make file should go as follows:

Format:

    <desired executable-name>:
    cc -o <executable name again> file1.c file2.c.. etc.

An example:

    filesize:
    filesize.c cc -o filesize filesize.c

Just a two lines, and then save the file. From the konsole you can now simply enter 'make' and the program will compile along the guidelines set in the makefile. This should be enough to get you started with writing your own programs and working with the programs in the book.