Older blog entries for mchirico (starting at number 37)

Create your own custom Live Linux CD

These steps will show you how to create a functioning Linux system, with the latest 2.6 kernel compiled from source, and how to integrate the BusyBox, utilities including the installation of DHCP. These steps include compiling in the OpenSSH package.

The CD will be completely loaded into RAM -- which means it loads as a rw filesystem. In fact, the CD can be removed for boot-up on a second computer. You can take over any PC using this method.

13 Mar 2005 (updated 14 Mar 2005 at 00:03 UTC) »
Recursion in Bash?

The following counts to 5, then, quits.

#!/bin/bash
sleep 1
declare -x n
let n=${n:=0}+1
[ $n -le 5 ] && echo "$n" &&  exec $0

There are some real-life applications for this technique, as follows:

#!/bin/bash
declare -x N
declare -x n
N=${N:=$(od -vAn -N1 -tu4 < /dev/urandom)}
let n=${n:=0}+1
[ $(($n%2)) -eq 0 ] && echo "She Loves Me!" || echo "She Loves Me NOT!"
[ $n -lt $N ] &&  exec $0

Your results may vary ...

Help

Could you please review the following article on creating a live Linux CD?

http://prdownloads.sourceforge.net/souptonuts/instructions_boot_system.txt

Potentially, I think, this could help you distribute your applications by putting a whole Linux system, plus your application, on one CD. Your target audience doesn't have to install anything; instead, they can evaluate your software by simply booting off the CD.

I think this solution is easier than re-mastering the KNOPPIX CD, which contains a lot of additional software that you probably don't need. Plus, I think, the documentation is easier to follow. On the other hand, maybe the base install should have more libraries - or maybe it's completely unusable, hard to follow, or just flat out misses the mark.

I'm specifically looking for a critical critique from potential users. What's needed to make it usable for your applications?

Thanks,

Mike Chirico

For those who still use Linux...

100+ Linux Tips There are over 145 Linux tips and tricks from using encryption, tar, cpio, setting up multiple IP addresses on one NIC, tips for using man, putting jobs into the background, using shred, watch who is doing what on your system, listing system settings, IPC status, how to make a file immutable so that even root cannot delete, ssh key pair generation, keeping 12 months of backups in the system logs, low level tap commands (mt), mount an ISO image as a filesystem, getting information on the hard drive, setting up cron jobs, look command, getting a bigger word dictionary, find out if a command is aliased, ASCII codes, using elinks, screen commands, FTP auto-login, Bash brace expansion, Bash string operators, for loops in Bash, diff and patch, script, change library path (ldconfig), monitor file usage, --parents option in commands, advance usage of the find command, cat tricks, guard against SYN flood attacks and ping, special shell variables, RPM usage, finding IP and MAC address, DOS to UNIX conversion, PHP as command line scripting language, Gnuplot, POVRAY and making animated GIFs, plus a lot more...

More? Well, yes. How to push and pull ssh, using dd to write tar files, redirecting Apache web pages, samba mount through ssh, music on Fedora Core 3, check Microsoft PPTP connections with nmap (on Linux), monitor IP traffic, (matt's traceroute, and tcpdump tricks), resetting Linux passwords, finding a file type, sending email from telnet, plus a lot more.

In 8 Months there will be over 300 tips...

Happy Reading...

It took me 20 minutes to write the following title and paragraph - I think it explains what I'm trying to do

Creating a Live Linux CD and BusyBox System with Compiled OpenSSH

These steps will show you how to create a functioning Linux system with the
latest 2.6 kernel compiled from source, and how to integrate the BusyBox
utilities; plus, you see how to setup users, install DHCP and compile ssh
on this small live system that, when booted, runs completely in RAM.
It's so hot in this room, and I'm falling asleep. I wanted to finish writing this tutorial because creating your own live Linux system on a cdrom is pretty handy. Plus, I love BusyBox; so simple so powerful.

It is great if you go to the library and need a PC, since there is usually one with a defunct HD. There is always a broken on that no one uses that you Just slip in the cd and boot. Hmm, a thought just occured to me. May be I should add Elinks to the base install. Normally, I ssh into my home computer; but, Elinks might be handly for other people.

I think including the whole development environment with needed libraries was a good idea. This way people can following along with something real to check their progress.

It's going to take another 6 days on the documentation, at least. And I should add in a cooling off period. Let's see add in more hints for kernel compiling, add in references, add fluff, take out fluff, correct spelling. I just have to look at this as a labor of love. Not something that is going to bleed me dry.

Boy it's hot in here. .

2.6 USB Kernel Project

I ordered another Delcom-Engineering USB Numeric Display, so that I could write an article on how to build a 2.6 kernel module for it, which you can find here...that's code with some documentation.

For the most part, that driver works pretty well. I plot the position of the moon. And it buzzes 10 minutes before shinning through my window, giving me the exact position every second. I modified moshier's code to get this information.

There is a lot of cool stuff that you can do with this device. It sells for about $64 dollars... no I do not work for delcom-eng and yes that is a bit expensive when you have 4 kids. But, they did good on their documentation.

lxr, glimpse, patchset - tools for reading the linux kernel source

I setup these tools on my home system. The instructions can be found here see (TIP 117). Yes, that document contains about 80 pages of Linux and open source tips.

Having a local version of lxr is nice, because the on-line version of lxr does not have the 2.6.10 kernel. If you got the January 2005 edition of Linux Magazine, Mel Gorman has an article on how to set this up, however, a few steps were missing. Well, I had to do a few more steps.

The SQLite Tutorial was published on freshmeat. I get a lot of question on using the sign function when sqlite supports boolean expressions. If you see the comments at the end, you will see what I mean. The reason for this: most databases support the sign function and NOT Boolean expressions. Or they do not support boolean expressions fully in the group clause... MySQL, Microsoft SQL. However, I think this is more of an issue for me, since I do a lot of conversions between databases.

2005

As I was putting the kids into bed, I explained to them that tomorrow it will be 2005. They are only 4. I have 3 of them that are four years old. I have triplets. We got on the subject of what they wanted to be when they grow-up. And as a parent, you always want your kids to feel that they can achieve their goals. So I went around the room. Each had to tell me what they were going to be:

   "Dad, I'm going to be a tree"
   ..."I'm going to be a rabbit"
   ..."I want to be a fish"

Well, so much for long-term goal setting.

C++ Template Recursion

I thought the following program was kind of interesting. It calculates the base conversions for binary, octal, and hex during compile time by using template recursion.


#include <iostream> template <unsigned long N,int shft>

struct ybase { static unsigned const value = ybase<N/10,shft>::value << shft | N%10; };

template <int shft> struct ybase<0,shft> { static unsigned const value=0; }; int main(void) {

unsigned const eight = ybase<10,3>::value; // octal 2^3 unsigned const sixteen = ybase<10,4>::value; // hex 2^4 unsigned const three = ybase<11,1>::value; // binary 2^1

std::cout << eight << std::endl; std::cout << sixteen << std::endl; std::cout << three << std::endl;

return 0; }

Explained

Here is the key to understanding this: "<<" is a binary shift. So "<< 1" is the same as multiplying by 2. The "|" is a bitwise OR.

So, here is a breakdown of ybase<11,1>, which of course is 3, because 11 binary is 3 decimal. Take this slow or you'll miss the cool stuff. Remember this is done at compile time...this ain't no maco. It's a template!

 a.    ybase<11/10,1>::value << 1 | 11%10

which is the same as

       ybase<1,1>::value << 1 | 1

because 11/10=1 and 1%10=1. Then "ybase<1,1>::value" part gets evaluated as follows:

     ybase<1/10,1>::value << 1 | 1%10

where this whole expression is equal to "1" from 1%10. It is 0 OR'd 1 which is equal to 1. The OR is doing a "+" plus.

We can now substitute this "1" for binary<1/10>::value in step a. to give

          1 << 1 | 1

which is a 1 shifted to the left "Multiply by 2" OR'd with a 1 "again same as add 1". This is the same as 2 "+" 1 which is equal to a 3.

         11  in binary is a 3
Leap Second: Could Happen Dec 2005

Interesting. Rich Schmidt, Directorate of Time,USNO Washington, has commented as follows:

We knew it's been too good to last, looks like the Earth is getting ready to cough up another leap second. This to be applied at the end of Dec. 2005. (A year from now). [sic] Offical word should be out next year.

R. Schmidt

The link can be found here

This is a very big event. For me at least.

Because char, double, long etc. have to start on certain byte boundaries, struct A takes up 4 bytes more than struct B. Note that both struct A and B have two characters and a double. But, since a char appears before the double, there are 3 bytes of padding. Then after c2, still looking at struct A, there is 1 byte padding.

struct A {
  char c1;   /* Alignment */
  double d1;
  char c2;
};

struct B { char c1; char c2; double d1; };

int main(void) { printf("Sizeof(struct A)= %d \n",sizeof(struct A)); /* Sizeof(struct A)= 16 */ printf("Sizeof(struct B)= %d \n",sizeof(struct B)); /* Sizeof(struct B)= 12 */ return 0; }

I got this information out of Herb Sutter's book "Exceptional C++ Style. 40 New Engineering Puzzles, Programming Problems, and Solutions." I like this book.

28 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!