Monday, June 29, 2015

The Porteus Alternative

I wrote a few months back on using Puppy Linux on a USB stick in the classroom. This post will follow in the same vein though instead of Puppy, I will be using the Porteus distribution. Puppy seems a little out-dated and I never had any luck installing the Pygame package. I probably would have turned to Porteus earlier had it not been for a quirk in the search engines. 'USB linux' doesn't return anything linking to Porteus. A search of 'portable linux' puts links to Porteus very high among the results. The most recent version of Porteus dates back to December last year and ranks in the top 50 or so at Distrowatch. Somehow, I missed it last year when I was doing the basic research for Puppy. I'm glad I now have the chance to talk about it.

Porteus starts out at this page where one 'builds' the .iso from scratch. A unique system that seems to work well. I left the settings pretty much at default except for changing the local time zone and choosing the XFCE desktop environment, a vast improvement over what Puppy had to offer, by the way. The size of the .iso is comparable to Puppy, (~200 MB) and takes only a few minutes to download.

Once the .iso is downloaded, Porteus can be installed on the USB. Again the process is a little different from what I've been used to. It's described here. As the link says in the 'Installing Porteus to a USB Flash Drive' section, "you must extract or mount the .iso file in order to copy the /boot and /porteus directories to your target device." Extract and copy those two folders to the root of the USB. Once done, navigate to the /boot folder on the USB and open a terminal there. Execute the following: "sudo sh Porteus-installer-for-Linux.com" and provide a password when prompted. The Porteus USB is now ready to boot.

On starting Porteus, there are a few changes to be made. First off, it's necessary to make the USB persistent. After that, any changes made (like WIFI passwords, newly installed applications, data files etc) will not disappear after shutting down. I found it rather tricky. The menu item "Porteus Save file manager" starts a wizard to create a 'save file' where changes can be saved. It works smoothly. I created the file 'porteussave.dat' in the 'porteus' folder. The next step is to navigate to the /boot/syslinux folder and open a terminal. The file 'porteus.cfg' should be there and it needs a little altering. Open the file as root: 'sudo mousepad porteus.cfg' should do it. 'toor' is the root password. Look for the information about XFCE in the porteus.cfg file and edit the entry to look like this: 'changes=/porteus/porteussave.dat'. Only the information /porteus/porteussave.dat' needs to be added, the rest of the line can be kept as is. Create some empty text files or connect to WIFI. If the connections and the files persist after rebooting, your efforts have been successful.

The next step is to download and install a number of applications not included in the original .iso. They are Python, Tkinter, Pygame, Geany and the Gimp. The package manager doesn't seem to work, so the following should be downloaded from the http://pkgs.org site. Search the site in the Slackware 14.1 (or 14.0) section.

From these pages:
http://pkgs.org/slackware-14.1/slackware-i486/python-2.7.5-i486-1.txz.html
download Python in .txz format.
http://pkgs.org/slackware-14.0/salix-i486/pygame-1.9.1-i486-3gv.txz.html
download Pygame in .txz format.
http://pkgs.org/slackware-14.1/slackware-i486/pygobject-2.28.6-i486-2.txz.html
download PyGobject in .txz format.
http://pkgs.org/slackware-14.1/slackware-i486/pygtk-2.24.0-i486-1.txz.html
download GTK in .txz format.
http://pkgs.org/slackware-14.1/slackware-i486/tk-8.6.1-i486-1.txz.html
download TK in .txz format.
http://pkgs.org/slackware-14.1/slackware-i486/tcl-8.6.1-i486-1.txz.html
download TCL in .txz format.
http://pkgs.org/slackware-14.1/slackware-i486/gimp-2.8.6-i486-1.txz.html
download GIMP in .txz format.
http://pkgs.org/slackware-14.1/salix-i486/geany-1.23.1-i486-1gv.txz.html
download GEANY in .txz format.

Once these files are downloaded, they can be moved to the /porteus/modules folder and converted (txz2xcm) into the .xzm format. Then they should be activated. Both operations can be done by right-clicking on the file and selecting the option from the menu. Once activated, the application should be ready to use.

One more item is to ensure that the files are accessible to Windows without booting. As with Puppy, the /etc/rc.d/rc.local_shutdown needs to be edited with an additional line of code. First, unlike Puppy, the file needs to be made executable. Navigate to /etc/rc.d/ and open a terminal. Then type 'sudo chmod +x rc.local_shutdown' followed by the password 'toor' when prompted. Then 'sudo mousepad rc.local_shutdown' and add the following line to file:

cp -r /home/guest/homework/* /mnt/sdb1/homework/

Finally, copy an files you want into a 'homework' folder in the guest folder then go to the root folder and create another new folder 'homework'. It should sit between /boot and /porteus. I decided against copying the contents of the accessible root homework folder to the inaccessible guest homework folder for security reasons. Users will have to remember to transfer any work done outside Porteus (like in Windows) to the guest homework folder.

The XFCE desktop, the fonts, menus, panels and wallpapers can now be edited to taste. And the USB is complete.

Thursday, May 21, 2015

Bypassing the UEFI

I'd like to outline the procedure to install dual booting Windows/Linux on computers with the UEFI security system This abominable bit of malware can be found on recent models produced by HP and Acer etc. It seems to be associated with Windows 8. The required procedure is a departure from that of the straight forward BIOS machines, and following those original procedures will meet with failure. It's not difficult to bypass the UEFI but I struggled with it, spent a frustrating day consulting many difficult and confusing HOWTOs such as this one. I've done installations hundreds of times on pre-UEFI computers. It's possible to follow basically the same procedure once the UEFI has been bypassed. Here's how: Once you switch on the computer, having backed up any precious data in preparation, check very quickly for the key to enter the BIOS configuration. You'll only have a few seconds and there should be a message briefly displayed at the bottom of the screen. It's often F2 or the DELETE key, but it varies from machine to machine. Once in BIOS, a screen something like the following should displayed:

 Select the security tab:
 
And create a supervisor password. It doesn't have to be elaborate. Just ensure it's memorable. Once the password is created, select the boot tab:
 
Now the 'secure boot' option can be disabled. And the 'UEFI booting' option can be switched to 'legacy BIOS.' The booting sequence should also be altered at this point, so that USB containing the source iso should be given priority over the hard drive. The images used here will almost certainly differ from what is seen on your computer, but that's nothing to worry about. What's important is to 1) give yourself a supervisor password, 2) disable secure booting, 3) switch from UEFI to legacy BIOS, and 4) prioritize USB booting. Press F10 to save the settings. Now the computer is ready for normal installation. Use a 64bit Linux iso on these machines.

Saturday, May 9, 2015

I am the Game of Life. Play me.



## This post is meant to be copied and pasted into a text        
## file with a .py extension and run as a python programme.  
## If you are using Windows, you can download the  
## Windows X86 MSI Python 2.7.9 installer from the www.python.org   
## website. I wrote the programme, based on John Conway's  
## Game of Life to learn more about Python and especially Tkinter. 
## Tkinter is a bit of a disappointment but I'm pleased with
## the results.       
##               
## It was John Conway, the Liverpudlian mathematician, who
## invented the game in 1970. He first played it on paper and
## pencil rather than computer, and even the thought of this is
## exhausting. It's not hard to see what computers have done
## for new fields of math. The Game of Life is credited to have
## helped in opening up the study of Cellular Automata. It's
## really not a game in the conventional sense, but it's fun
## to watch.
##
## Each red cell, or square, is a living organism. And each cell
## is surrounded by 8 other neighbouring cells. If a living red 
## cell is surrounded by 0 or only 1 other red cell, that cell will
## die in the next generation. Die of loneliness, I suppose. To
## die means to be replaced by a yellow cell. Similarly, if the
## red cell is surrounded by 4 to 8 other red cells, that cell
## will die in the next generation of over-crowding. A red cell
## will survive and continue to live in the next generation if it
## is surrounded by 2 or 3 neighbouring red cells. One more rule,
## if a yellow cell is surrounded by exactly 3 red cells, it will
## come to life in the next generation and be replaced by a red 
## cell. You can read Martin Gardner's original introduction to 
## the game in his 1970 column in Scientific American. 
##  
#!/usr/bin/env python2

import Tkinter as tk

def quitgame():
    root.destroy()

def advance1():
    gen_number = 1
    advance(gen_number)
    
def advance10():
    gen_number = 10
    advance(gen_number)

def advance100():
    gen_number = 100
    advance(gen_number)

def advanceinfinity():
    gen_number = 100000
    advance(gen_number)

def advance(gen_number):
    global tally
    for k in range (gen_number):
        ##main loop to check neighbours
        for x in range (25):
            for y in range (42):
                Matrix[x][y][1] = 0

                if Matrix[x][y][0] == 6:        
                    colour_flag = 'red'
                    tally_neighbours(x,y)
                else:
                    colour_flag = 'yellow'
                    tally_neighbours(x,y)

                if (tally>3 or tally < 2) and colour_flag=='red':
                    Matrix[x][y][1] = 7
                    A=tk.Button(frame2, bg='yellow')
                    A.grid(row=x,column=y)
                    frame2.grid()

                if tally == 3 and colour_flag == 'yellow':                    
                    Matrix[x][y][1] = 5
                    A=tk.Button(frame2, bg='red')
                    A.grid(row=x,column=y)
                    frame2.grid()

                tally = 0
            root.update()

        for x in range (25):   
            for y in range (42): 
            ## transferring info from 3rd to 2nd dimension
                if Matrix[x][y][1] == 5:
                    Matrix[x][y][0] = 6
                if Matrix[x][y][1] == 7:
                    Matrix[x][y][0] = 0

def tally_neighbours(x,y):
    global tally
    if x!=0 and y !=0 and Matrix[x-1][y-1][0]==6:
        ## for checking surrounding 8 squares
        ## of middle cell
        tally = tally + 1                              
    if x!=0 and y !=0 and Matrix[x-1][y][0]==6:
        tally = tally + 1
    if x!=0 and y !=0 and Matrix[x][y-1][0]==6:
        tally = tally + 1
    ## these try statements make sure
    ## no error message occurs when i
    ## overstep the bounds positively.
    ## Negative overstepping is not OK
    try:                                                
        if x!=0 and y !=0 and Matrix[x+1][y+1][0]==6:   
             tally = tally + 1                          
    except IndexError:                                  
        pass
    try:
        if x!=0 and y !=0 and Matrix[x][y+1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x!=0 and y !=0 and Matrix[x+1][y][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x!=0 and y !=0 and Matrix[x-1][y+1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x!=0 and y !=0 and Matrix[x+1][y-1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
########################
## for checking 5 squares surrounding
## top row cell
    if x == 0 and y != 0 and Matrix[0][y-1][0]==6:      
        tally = tally + 1                               
    try:
        if x == 0 and y !=0 and Matrix[0][y+1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x == 0 and y !=0 and Matrix[1][y][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:              
        if x == 0 and y !=0 and Matrix[1][y-1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x == 0 and y !=0 and Matrix[1][y+1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
#########################
## for checking 5 cells surrounding
## left column cell
    if x != 0 and y == 0 and Matrix[x-1][0][0]==6:      
        tally = tally + 1                               
    try:
        if x != 0 and y == 0 and Matrix[x-1][1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x != 0 and y == 0 and Matrix[x][1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x != 0 and y == 0 and Matrix[x+1][0][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x != 0 and y == 0 and Matrix[x+1][1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
#################
## for checking 3 cells surrounding
## top left cell
    if x == 0 and y == 0 and Matrix[0][1][0]==6:       
        tally = tally + 1                               
    if x == 0 and y == 0 and Matrix[1][0][0]==6:
        tally = tally + 1
    if x == 0 and y == 0 and Matrix[1][1][0]==6:
        tally = tally + 1
    return tally
## for choosing (and correcting) initial configuration
def startMove(i,j,event):               
    if Matrix[i][j][0]== 0:
        event.widget.config(bg='red')
        Matrix[i][j][0]=6
    else:
        event.widget.config(bg='yellow')
        Matrix[i][j][0]=0
    
root = tk.Tk()

Matrix = [[[0 for z in range(2)] for y in range (42)] for x in range (25)]

tally = 0

frame1 = tk.Frame(root)
frame2 = tk.Frame(root)

instruct = tk.Label(frame1, text="Initialize the game by clicking on a few yellow squares. ")
instruct.pack(side=tk.TOP)
onebutton = tk.Button(frame1, text="Advance 1 generation", command=advance1)
onebutton.pack(side=tk.LEFT)
tenbutton = tk.Button(frame1, text="Advance 10", command=advance10)
tenbutton.pack(side=tk.LEFT)
hundredbutton = tk.Button(frame1, text="Advance 100", command=advance100)
hundredbutton.pack(side=tk.LEFT)
infinitybutton = tk.Button(frame1, text="Advance forever", command=advanceinfinity)
infinitybutton.pack(side=tk.LEFT)
quitbutton = tk.Button(frame1, text="Quit", command=quitgame)
quitbutton.pack(side=tk.LEFT)
frame1.grid()

for x in range (25):
    for y in range (42):
        A=tk.Button(frame2, bg='yellow')
        A.grid(row=x,column=y)
        frame2.grid()
        A.bind('', lambda e, x=x, y=y: startMove(x, y, e))

root.title("Martin's Conway's Game Of Life")
root.mainloop()

Saturday, March 14, 2015

Clone That Puppy

If you read my previous post on the Live USB Puppy for Python education, you may have noticed at least two problems with it. I will address them here.


The first is that the Python graphics package Tkinter is not designed to deal with animation. I tried anyway, it was awkward, and I abandonned the idea. I installed the Pygame package and have been working happily with that instead. Since I believe that writing simple games and animation are the best way to teach programming to youngsters, something like Pygame is essential. There's a .deb package available for download here. And there is a pretty good introductory tutorial here. Pygame can be installed on Puppy clicking on the .deb file, same as outlined for the other packages in the previous post.

The second problem lies in using the USB in the classroom rather than anything to do with the USB itself. It takes about 25 minutes at least to prepare a USB in the manner I outlined. For a class of 10 students, that means the teacher is facing hours of tedious and attention demanding time at the terminal, if each student is to get their own USB. Intuitively, I'd just like to simply copy whatever is on the Puppy and paste it onto an empty USB. However, this doesn't work. I have something else in mind. Something that works. I found that I can cut down the time it takes to reproduce a USB to around 7 minutes. Still tedious and attention demanding, and fraught with the dangers of destroying valuable data at just about every step, but I managed to get the hang of it after only a couple of false starts. What we want to do is called cloning a drive or partition. You can also make an image of the USB and go from there, but it seems cloning is a little easier and no slower than going down the image route.

Download Clonezilla, (~160MB) and put it on a USB following these instructions. I followed the GNU/Linux method B and found it surprisingly easy. Prepare a target USB stick, where you intend to put the cloned copy. The source will be the 'original' USB created following the instructions in the previous post. Once Clonezilla is booted, I inserted the other two sticks. It's important to know which is the source with your Puppy on it and which is the target which should be empty. You also need to know how to identify the USB with Clonezilla on it, and also the hard drive and the partitions on it. I'm leery about altering my hard drive in any way, so my method only involves USB sticks. On this Toshiba laptop, that means every USB slot (all 3) is in use. Still the possiblilty exists of doing damage to data on the hard drives, so take care to identify them when presented with the chance. Here is an accurate walk-through of the cloning process. As I say, it takes around 7 minutes. Good luck and take care.

Friday, March 6, 2015

A Puppy in the Classroom

I've been quite busy over the past few months working with my computer. Something I'd like to present here is an arrangement (dare I say an invention) for teaching computer programming to young students. The classroom I have in mind has only one computer, that of the teacher. In my case, I have a Raspberry Pi connected to a large television set. The students have pens and notebooks and a USB memory stick prepared by the teacher.



This article is about the memory stick and how to make your own.

My goal is to teach elementary programming skills with the Python language, and the Tkinter modules for graphical user interface - buttons and menus etc. The Idle integrated development environment is included for convenience. A text editor like Notepad is all that is necessary, but Idle will help the programmer with tasks like indentation, parentheses balancing and identifying syntax errors. I'm using the Python 2.7 version, which is still pretty ubiquitous, rather than the newer and incompatible Python 3. Other languages are also possible.

I suppose each student could have their own laptop with them in class, but I don't believe this solution is practical, desirable, or necessary. Laptops are expensive and not every family has one. Those that do may well be reluctant to pack it up and allow their 12 year old child to take it back and forth to class. Every student with their own laptop in class would also create a lot of avoidable distraction and classroom clutter, never a good thing.

My solution is the Raspberry Pi with screen suitable for classroom use, and equipping each student with a USB memory stick. These memory sticks can be used in the classroom and at home, or anywhere else there's a computer, whether it's Windows, Apple or Linux. My design should also be reasonably easy to use and prepare and as safe as can be expected. If they are lost, they can easily be replaced in about 20 minutes. Technically, I think the most difficult task might be the changing of the booting sequence in BIOS at startup. This page should help in that regard.

Getting down to specifics, what I'm proposing here is putting an operating system on a USB memory stick. It can be installed on a stick as small as 1 GB, or even less, and to access the data therein, booted or simply be plugged into an already running system, whether it's Windows or whatever. The Live CD or Live USB that many linux distributions make available seem only meant as a test drive vehicle and not something permanent. A USB that holds an operating system with persistence, ie permanently saves any data files, WIFI passwords etc, created during the session is rare. The technical name for this is a persistent live USB. It's also possible to install an operation system onto a USB as though it were a hard disk drive, but I found these installs slow and prone to problems. All the software necessary is listed down below. No alteration to the parent's computer is needed except for the change to the BIOS booting sequence.

I must have tried out at least 10 different Linux distributions before settling on Puppy Linux. Lubuntu was a runner up and had some advantages over Puppy, more up-to-date for one, but Puppy did everything I wanted without any fuss. I've used Puppy for years now on my older computers, installed on the hard drive. It's fast and stable. At about 150 MB it's extremely light weight, yet requires very little extra software for my intended use. I have listed all the necessary downloads below, in total well under half a gigabyte, about half the size of the Lubuntu .iso file.

I will explain here how a teacher with any computer can prepare the student's USB. First, might as well download all 9 files listed below. Keep them together in a safe place. Then, using the windows .exe file Universal USB Installer, create a bootable thumbdrive by loading the file 'precise-5.7.1.iso.' There's a menu and there's an entry for 'precise' under the Puppy heading.  Preparing the USB will take a couple of minutes.

Once complete, reboot with the USB in place. To boot from the thumbdrive, you may need to change the booting sequence of the computer. On switching the computer on, press the F2 key and this should bring up the BIOS screen which allows the user to change the booting priorities among other things. Different computers may use a different key than F2. Look carefully and quickly at the messages at the bottom of the screen for instructions before the Windows starts to boot. It's all covered in the link I provided above. Booting from USB should be given top priority so that an inserted USB rather than the DVD or hard disk will be booted. This setting can be kept without any inconvenience to normal usage of the computer as long as you are aware that the computer will always attempt to boot whatever is in the USB slot on startup. For normal use, it's best to remove anything from the USB slots on startup. Attempting to boot a non-bootable (ie normal) thumbdrive may result in an error and necessitate a power down and restart.

Now you should have booted the Puppy Linux. You can connect to internet and make any adjustments in time and date if you want.  This is not necessary for the usage I have in mind. Maybe leave it to the more curious students to further explore the system. Beware it is possible to do real harm to the host computer such as formatting the hard drive using a programme like Gparted but that kind of risk remains with any system.

At the root of the USB drive, accessed by single clicking one of the drive icons at the bottom left of the Puppy Linux desktop screen, probably the one labelled 'sdb1,' create a folder called 'homework,' or whatever and copy any of your working files into it. This is done by right-clicking on the desired location and following the instructions to create a new folder. There will also be another folder, probably called 'UUI.' The new homework folder should appear beside 'UUI.' In my homework folder I have some pdf tutorials and other documentation and some projects both complete and incomplete. Also into the USB root, beside 'homework' and 'UUI,' copy the previously downloaded "devx_precise_5.7.1.sfs" file.

 Now single click on menu button, bottom left corner of the desktop, then choose 'Setup' then 'SFS-Load on-the-fly.' Follow the dialogue to load the 'devx_precise_5.7.1.sfs' file just copied to the USB root.The python language modules will now be ready.

The biggest challenge I faced designing the USB was to allow users to access data on the stick without booting, simply by plugging into an already running system, probably Windows. Here is my solution, Single click on the 'File' icon, top left hand corner of the desktop screen. This takes you to the Puppy home folder. Keep the 'Choices' and 'Startup' folders, the rest can be optionally deleted. Less clutter, more clarity is my mantra. Create a folder here, again right-clicking and following the instructions, called 'homework,' exactly like the one created a couple of paragraphs ago. There will now be a 'homework' folder in the USB root and one in the Puppy home.

Copy the following:

#!/bin/bash
# my start up

mv /mnt/home/homework/* ~/homework/

# put following in /etc/rc.d/rc.shutdown (at end)
# mv ~/homework/* /mnt/home/homework/


into a new text file and call it 'my_startup.' Again right-clicking and following instructions to create a file this time. In scripts like this lines beginning with # are comments and not executed. The action is all in the third line which on startup moves the homework folder in the USB root to the homework folder in the Puppy home. Save and store the 'my_startup' file in the 'Startup' folder. To take care of the shut down, navigate to the 'etc' folder. This can be found in the next level up from your present location in 'home.' Click on the up arrow of the file manager. From 'etc' enter the 'rc.d' folder then find the file (not folder) called 'rc.shutdown.' Edit this file by adding the following line to the end:

mv ~/homework/* /mnt/home/homework/

Save the changes. On shutdown now, the contents of the 'homework' folder in the Puppy 'home' will be moved to the 'homework' folder in the USB root. The data on the USB will be easily accessible from any computer.

Almost finished now. Click on the partition icon at bottom left of desktop screen. The icon should be 'sda1' or something like this and navigate to where you stored the 6 smallish '.deb' files downloaded earlier. Click (not double click) on one, (the order doesn't seem to matter) and follow the brief dialogue to install. Continue with the other five. Tkinter and Idle are now installed.

Go to the Menu => Desktop => Desktop drive icons manager. Untick the boxes, This removes the icons from the desktop that give easy access to the hard drive. This amounts to 'child proofing' the system and ideally, I'd like to go further, also removing potentially dangerous software, but I want to do this as quickly and easily as possible.While you are at it, you can optionally remove as many of the desktop icons as you wish. None of them are necessary.

You can also put an 'Idle' icon on the desktop. Go to Menu => File System => 'ROX-Filer file manager,' Navigate to 'usr' at the Puppy root then 'share' then 'applications.' Simply find the 'idle.desktop' icon file and drag and drop it to the desktop.

That's about it. If you want to connect to the internet or adjust time and locality setting etc, it's possible. I typically change the desktop background picture and remove superfluous icons from the desktop. Note that Puppy is a complete system and it's possible to surf the web, watch and download videos, and do whatever is normally done with computers.

When ready, go to the menu to shut down. On shutting down for the first time, you must create a save file. It takes a couple of minutes. My own is a fairly modest-sized 128 MB. I don't need any bigger and the larger the file, the longer the booting time.

That's it. For now, anyways.

from here:
download "precise-5.7.1.iso"  (156 MB)
AND from same place download "devx_precise_5.7.1.sfs"   (148 MB)

from here:
download the following: "blt_2.4z-4.2ubuntu1_i386.deb" (1.5 MB)

from here:
download the following: "idle_2.7.3-0ubuntu2.2_all.deb" (3 KB)

from here:
download the following:"idle-python2.7_2.7.3-0ubuntu3.5_all.deb"   (254 KB)

from here:
download the following:"python-tk_2.7.3-1_i386.deb"  (27 KB)

from here:
download the following:"tcl8.5_8.5.11-1ubuntu1_i386.deb" (1.1 MB)

from here:
download the following:"tk8.5_8.5.11-1_i386.deb" (1 MB)

finally from here:
download the following:"Universal-USB-Installer-1.9.5.9.exe"   (1 MB)