Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, 1 May 2015

Howto install smokeping on lighttpd on ubuntu 15.04 linux

Smokeping is a great network and service monitoring tool. But it only configures correctly if you are using apache.

I want to run a very light web server and therefore you need to do some manual configuration to make it work.

1. Install lighttpd.

sudo apt-get install lighttpd

2. Ensure that http://localhost works. You should get page like this:




3. Install smokeping

sudo apt-get install smokeping

4. Enable Lighttpd CGI module

sudo lighttpd-enable-mod cgi

5. Reload Lighttpd

sudo /etc/init.d/lighttpd force-reload

6. Ensure that this link brings up a semi-functional page

http://localhost/cgi-bin/smokeping.cgi

Icons and graphs probably do not work.



6. Create a directory link in /var/www/ as smokeping to smokeping static page files:

sudo ln -s /usr/share/smokeping/www /var/www/smokeping
7. For some reason, lighttpd base directory is /var/www/html. This needs to be changed to /var/www (which I suspect other packages will be expecting).

Edit /etc/lighttpd/lighttpd.conf

Change this line:
server.document-root = "/var/www/html"

to:

server.document-root = "/var/www"

8. Restart lighttpd and smokeping

sudo /etc/init.d/lighttpd restart
sudo /etc/init.d/smokeping restart

Did you get this?



Update to enable fastcgi.

I don't know what fastcgi is, but compared to cgi is is fast.

On my laptop, it is 5 times faster!

1. Copy smokeping.fcgi.dist as smokeping.fcgi

sudo cp /var/www/smokeping/smokeping.fcgi.dist /var/www/smokeping/smokeping.fcgi

2. Edit smokeping.fcgi to point to your smokeping.cgi script

exec /usr/lib/cgi-bin/smokeping.cgi /etc/smokeping/config

NOTE: my file had smokeping_cgi. This seems to be wrong and must be changed to smokeping.cgi

3. Modify /etc/lighttpd/conf-available/10-fastcgi.conf

Add this:

fastcgi.server += ( 
  "smokeping.fcgi" => ((
    "socket"   => "/var/run/lighttpd/fcgi.socket", 
    "bin-path" => "/usr/share/smokeping/www/smokeping.fcgi"
  ))
)

4. Enable Lighttpd FastCGI module

sudo lighttpd-enable-mod fastcgi

5. Reload Lighttpd

sudo /etc/init.d/lighttpd force-reload

6. This link should now work

http://localhost/smokeping/smokeping.fcgi

Sunday, 16 December 2012

Building and using a Linux UML environment

Intro

I want to test a script that randomly creates files all over a file system.

Naturally, I don't want to test this on my Linux system.

I tried fakechroot fakeroot chroot and schroot but I could not get them to do what I wanted.
fakechroot fakeroot chroot in particular allowed access to all files using '/..' - not what I wanted at all.

Method

I'm using pbuilder because it seems easy (once you know how).

  • It can also be run as a user.
  • It does not take up much space since UML environment is in a tar gzip file.
  • Changes within UML can be saved or lost (default).

To construct your sandpit

I called it 'sandpit', but you can call it what you like. Just replace sandpit with your preferred name.
Also, there is nothing stopping you making multiple sandpits.

pcreate -a amd64 -d lucid sandpit

I was running 64 bit Linux so I choose amd64
I did not care what distro I used so I choose lucid

To put/copy files into your sandpit

Files in ~/Projects/sandpit are available within your sandpit

cp ~/Projects/sandpit/

To get into your sandpit

ptest -p sandpit

After you exit, any changes will be gone.

To save changes in your sandpit

ptest -p sandpit --save


Saturday, 19 February 2011

Boot a Real Mac OS-X Partition under Linux and VirtualBox

This should be easy, but Apple make it hard.

I have a MacBook Pro. I have OS-X Leopard 10.5.2 installed as well as Ubuntu 10.10 linux.

I wanted to get my OS-X partition to run as a virtual machine.

After many false starts I got something to work.



First, the specs.
Hardware: MacBook Pro 4,1, early 2008, 2.4GHz, 200GB, 15"
http://en.wikipedia.org/wiki/MacBook_Pro
Host OS: Ubuntu 10.10
VM Manager: VirtualBox 3.2.8 OSE r64453
Guest OS: OS-X 10.5.2 Leopard (I don't bother to update it as I don't use it much and it have virtually nothing installed)
Overview

1. Get VirtualBox to list the physical partition in the Virtual Media Manager.
2. Setup the VM
3. Tweak it.
3. Run it.

1. Setup Disk Image

Please proceed at your own risk. Only do this if you have backed-up your disk partitions (with Time Machine for example, but don't forget about your linux partition) or your don't care about any data on your disk.

I used this information to create my VMM vmdk file.
http://ejs.seniejitrakai.net/2010/11/01/running-virtualbox-guests-from-physical-drive/
In my case, my hard drive is /dev/sda under linux.



phil@max:~$ VBoxManage internalcommands listpartitions -rawdisk /dev/sda

Oracle VM VirtualBox Command Line Management Interface Version 3.2.8_OSE(C) 2005-2010 Oracle CorporationAll rights reserved.
Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)1       0xee  1023/254/63  1023/254/63           200            12       0xaf  1023/254/63  1023/254/63        119102       4096404       0x83  1023/254/63  1023/254/63         11444    2443309763       0xaf  1023/254/63  1023/254/63         23167    343011768


The OS-X partition in my case is number 3. It is about 23GB.

Then I made the vmdk file like this:

phil@max:~$ VBoxManage internalcommands createrawvmdk -filename /home/phil/.VirtualBox/HardDisks/example.vmdk -rawdisk /dev/sda -partitions 3 -register 
Oracle VM VirtualBox Command Line Management Interface Version 3.2.8_OSE(C) 2005-2010 Oracle CorporationAll rights reserved.
RAW host disk access VMDK file /home/phil/.VirtualBox/HardDisks/example.vmdk created successfully.

This made this file - yours will be different, but it should have the same structure:

# Disk DescriptorFileversion=1CID=279c9811parentCID=ffffffffcreateType="partitionedDevice"
# Extent descriptionRW 1 FLAT "example-pt.vmdk" 0RW 409639 ZERO RW 243921336 ZERO RW 23437500 ZERO RW 75243292 ZERO RW 47448016 FLAT "/dev/sda" 343011768RW 262184 ZERO 
# The disk Data Base #DDB
ddb.virtualHWVersion = "4"ddb.adapterType="ide"ddb.geometry.cylinders="16383"ddb.geometry.heads="16"ddb.geometry.sectors="63"ddb.uuid.image="99ca08b3-6d2e-4ed4-8790-2430cfe5a57a"ddb.uuid.parent="00000000-0000-0000-0000-000000000000"ddb.uuid.modification="00000000-0000-0000-0000-000000000000"ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"

Now if you run Virtual Media Manager, you should now see a new hard drive entry for your physical partition.


That wasn't that hard, thanks to Sun/Innotek for making this easy.

2. Setup VM.

The key fields are these:
OS Type = Mac OS X
Use an existing hard disk - the one I created above: example.vmdk
The rest are the current defaults (which I will list below).
I also enabled 3D acceleration, but I can pick either.
Too easy, right?

3. Tweak VM

Apple OS-X checks to see if a special key is in a chip. VMs don't currently emulate this chip with the key, so you need to get the key off your machine and add it manually to the VirtualBox XML file that describes the VM.

The key is really a plea from Apple to not steal their OS. Here is their EULA for 10.5.

http://images.apple.com/legal/sla/docs/macosx105.pdf

It contains this clause:

A. Single Use. This License allows you to install, use and run one (1) copy of the Apple Software on a single Apple-labeled computer at a time. You agree not to install, use
or run the Apple Software on any non-Apple-labeled computer, or to enable others to do so. This License does not allow the Apple Software to exist on more than one
computer at a time, and you may not make the Apple Software available over a network where it could be used by multiple computers at the same time. 

I think this complies: One licensed and installed copy of OS-X on an Apple-labeled computer. I can't run it twice because that would do bad things to the file system.

So, I'll continue...

In my case the XML file is /home/phil/.VirtualBox/Machines/example/example.xml

This is what it might look like:


<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.11-linux">
  <Machine uuid="{0db68b53-a452-40bd-bb83-ad8952411320}" name="example" OSType="MacOS" snapshotFolder="Snapshots" lastStateChange="2011-02-19T08:34:33Z">
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <Hardware version="2">
      <CPU count="1" hotplug="false">
        <HardwareVirtEx enabled="true" exclusive="true"/>
        <HardwareVirtExNestedPaging enabled="true"/>
        <HardwareVirtExVPID enabled="true"/>
        <PAE enabled="true"/>
        <HardwareVirtExLargePages enabled="false"/>
        <HardwareVirtForce enabled="false"/>
      </CPU>
      <Memory RAMSize="1024" PageFusion="false"/>
      <Firmware type="EFI"/>
      <HID Pointing="USBTablet" Keyboard="USBKeyboard"/>
      <HPET enabled="true"/>
      <Chipset type="ICH9"/>
--- SNIP --- 


  </Machine>
</VirtualBox>

As you can see, the whole configuration of a VM is, more-or-less, understandable.

But wait! To do the next bit, you have to run the VM once. Until you do this scary thing, the XML file is missing bits that make the next part easier.

So, start the VM. When you see lots of text you can close the window and shutdown the VM.


This is all safe it seems.

My example VM XML file now looked like this - the highlighted bits are what we want to see:


<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.11-linux">
  <Machine uuid="{57d6a1c9-833f-4fb7-b765-f4c37793bc56}" name="example" OSType="MacOS" snapshotFolder="Snapshots" lastStateChange="2011-02-19T08:27:47Z">
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <ExtraData>
      <ExtraDataItem name="GUI/LastCloseAction" value="powerOff"/>
      <ExtraDataItem name="GUI/LastGuestSizeHint" value="1024,768"/>
      <ExtraDataItem name="GUI/LastNormalWindowPosition" value="400,61,1024,815"/>
      <ExtraDataItem name="GUI/LastWindowPostion" value="37,53,1024,815"/>
      <ExtraDataItem name="GUI/MiniToolBarAlignment" value="bottom"/>
      <ExtraDataItem name="GUI/SaveMountedAtRuntime" value="yes"/>
      <ExtraDataItem name="GUI/ShowMiniToolBar" value="yes"/>
    </ExtraData>
--- SNIP --- 
  </Machine>
</VirtualBox>

To tweak it, I followed these instructions:
http://www.takwing.idv.hk/tech/virtual/vb320_macvm/page3.html

Modify your VM's xml file by adding the following line to the section:

<ExtraDataItem name="VBoxInternal2/SmcDeviceKey" 
value="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>



Mine then looked like this:

<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.11-linux">
  <Machine uuid="{57d6a1c9-833f-4fb7-b765-f4c37793bc56}" name="example" OSType="MacOS" snapshotFolder="Snapshots" lastStateChange="2011-02-19T08:27:47Z">
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <ExtraData>
      <ExtraDataItem name="GUI/LastCloseAction" value="powerOff"/>
      <ExtraDataItem name="GUI/LastGuestSizeHint" value="1024,768"/>
      <ExtraDataItem name="GUI/LastNormalWindowPosition" value="400,61,1024,815"/>
      <ExtraDataItem name="GUI/LastWindowPostion" value="37,53,1024,815"/>
      <ExtraDataItem name="GUI/MiniToolBarAlignment" value="bottom"/>
      <ExtraDataItem name="GUI/SaveMountedAtRuntime" value="yes"/>
      <ExtraDataItem name="GUI/ShowMiniToolBar" value="yes"/>
      <ExtraDataItem name="VBoxInternal2/SmcDeviceKey" value="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>
    </ExtraData>
--- SNIP --- 
  </Machine>
</VirtualBox>    

4. Run it.

That's it.

Let me know if it worked for you, and if you have a different hardware, host, guest configuration.

If it didn't work, then I probably can't help - but you you want me to explain anything that I did in more detail then please ask.

BTW, if this kills you disk, damages your data, or generally make your life a misery then you will recall that I warned you, right?

Friday, 21 January 2011

Mac to Linux: Ubuntu is better than good enough.

When I purchased my first Mac in 2005, my intention was to get some good hardware, avoid any Microsoft tax and run Linux.

The closest I came was Ubuntu 9.04 in 2009, but I was tied to iTunes for my Ipod Touch and a little stuck with iPhoto.

I tried again in 2010 but I could not get Ubuntu 10.04 working well enough.

More recently I purchased a Nexus One Android phone and gave away the iPod. To do this I had to divorce iTunes. This turned out to be easy. I hardly needed any apps or games and I never purchased any music. So all I had to do was copy music files from the iTunes directory into the Nexus One.

A good friend (who is really my beta tester for... well... everything) got Ubuntu 10.10 working nicely on his Mac and I quickly tagged along. I have not run OSX for 2 weeks now and I don't miss it.

Ubuntu is better than good enough.

Here is his How-To.

I am now moving my iPhoto pictures to Picasa and onto the web using 20GB of Google storage for $5/year. Then I'll clean up my files on OSX and do something else with the partition. I still have another small OSX partition to allow me to upgrade any Apple firmware and to check hardware such as the battery. It also means I have OSX should I need it.

I wonder if OSX will run under VirtualBox?

Sunday, 25 October 2009

Google's ChromeOS

In case you missed the news, Google has announced that it will build a secure operating system for, well, any device: desktops, netbooks, tablets, phones.

Basically, it is
"Google Chrome running within a new windowing system on top of a Linux kernel"
and for security they are
"completely redesigning the underlying security architecture of the OS so that users don't have to deal with viruses, malware and security updates."
As you might imagine, this has stirred quite some commentary from magazines and bloggers: gizmodo, techcrunch and Wikipedia always has something to offer.

But I think most have missed the other key ingredients - everyone but ToxProX at least.

Google is not just working on a new OS. It is also working on at least two other related projects: Native Client and O3D.

O3D

I'll cover O3D first since I don't have much to write. The web site suggest that this stands for 'Open web standard for 3D graphics'.

It is a browser plugin that allows web developers to add 3D graphics to their application. I think the short video demo describes it best.

Basically, GPU accelerated 3D graphics for your browser.

Native Client

Native Client also known as NaCl (but never as Salt) is a way to run 'normal' programs safely.

A normal program is a word processor; a game; a photo editor; a VoIP client; a movie maker; or a 3D earth browser. Most of the software you use are normal programs and they are usually compiled to machine code for your CPU type and for your operating system.

What is Native?

A native program runs on the CPU and not in another program that decodes the instructions and then performs the operation.

That's not very clear so I will try a metaphor:

It is like reading a book. A book written in English is easily read by someone who understands or natively speaks English. Give them a book in German, and a German-English dictionary, and they could also read the book - but much slower.

For each word that they have not seen before, they would have to look up the word in the German-English dictionary, read the English meaning and then decode the meaning of the German sentence. They would have to do this for every sentence.

Initially they would be slow, but as their German vocabulary grows their sentence translation speed would improve because they are optimising the process of looking up the English meaning of a German word by memorizing it. But they will never be as fast as a native speaker since they are always translating.

Many programs written in Java, JavaScript, Python, Ruby, C#, lisp, perl and flash work this way. The program is written in a non-native language and another piece of software does the translation. Fast CPUs and cleaver optimizing techniques allow them to run quickly, but a native program that did the same thing would run at least twice as fast, but more often at least 10 times faster.

(A side note here is that CPUs are not getting that much faster any more which is why all language developers are working on ways to make their interpreter work faster or getting their compiler to generate faster and often smaller code.)

So, why aren't all programs written to run natively? The answer is portability. Interpreted programs can generally run on any operating system and on any CPU. Speed is traded for portability. It also means that we often loose the benefits of hardware accelerated graphics.

Native Client CPU Support

Most home and business computers use just 2 types of CPUs: x86-based and ARM based.

Intel, AMD and some other manufacturers make x86 CPUs which are generally used in servers, desktops and more recently netbook computers.

ARM licenses their designs to many manufacturers which integrate various modules and produce very low-powered chips for use in mobile devices such as ipods and mobile phones.

NaCl is being built for these two CPU architectures. This doesn't prevent future support for other CPUs like IBM's PowerPC or Sun's Sparc or Sony's Cell processor.

Native Client Security

Back to Native Client. This could be part of web 3.0: All applications loaded from the web, running securely in the browser at native application speeds? Maybe web 2.5?

NaCl tackled security in a new way. The programs are run in a sandbox. The sandbox disassembles the program, enforces memory access rules, rejects code that doesn't obey strict rules to prevent it jumping out of the sandbox, and only allows interaction with the real world through the limited API back to the browser or perhaps the ChromeOS.

This solution has some interesting benefits:
  • There is no need to enforce a trusted development chain so developers don't need a special, trusted compiler and developer certificate. Signed applications are unnecessary.
  • Buggy code can not crash the OS and nor can it do any damage since it is running in a sandbox which does not have access to hardware or the OS.
  • Malware can't make use of bugs to gain privileged access to the OS and the sandbox ensures all code stays in the sand. So, malware can not spread itself, access any file on the OS or leave the sandbox (or is it a salt box?). Could this be the end of Malware as we know it? I think Google thinks so.
Write Once, Run Anywhere

An unrealized dream of software architects is to write a program once, and to be able to run it on anything. Native Client makes this a reality. It will be a new program format that allows an application to run in any web browser (with a NaCL plugin I guess) on any operating system and on any hardware.

It also means that software will no longer need to be installed.

Enter Google Gears

Google Gears allows you to run your Google applications while off-line. It provides a database for local caching of data, HTML, images, JavaScript and perhaps NaCl programs as well.

Once you are back on the net, your locally generated data will synchronise with your on-line data.

Say someone creates a game for Native Client. You would agree to the license (if any), make any payment and run the game. The game would be cached locally so you won't need to download it each time you want to play, and this cache will allow you to use it when your computer is not connected to the web.

Now if the developer fixes a bug, or adds a new feature, the browser will check to see if the cached version is up-to-date. If not, it will automatically download and cache the latest version.

If this is how it might work, Google have just disrupted the whole universe of content distribution. There is no need for software installation. No need for update services. No need for fancy package management like Debian's APT. It will be like a universal version of iPhone applications.

So you can look forward to Google Earth, Picasa and Google Office applications all running from the web without having to install them and keep them up-to-date.

So, if programs run fast, run anywhere, are secure and don't crash the browser or OS, why wouldn't you use it for other parts of an operating system? Did I mention that NaCl also supports POSIX threading and IO? Now it just needs a hardware layer, device drivers and a GUI.

We already know that ChromeOS will be based on Linux so just the GUI remains to be built. Or does it?

Chrome is the GUI

What if Chrome (the browser) IS the GUI? It already has a window manager - we call them tabs. They can be pulled-out of the browser, minimised and resized - just like a window manager.

It already has a scripting language - JavaScript, and Chrome's V8 engine is fast.

It already supports HTML5 which covers-off video, audio and virtually everything that Adobe's Flash does.

And, it is getting hardware accelerated 3D graphics in the form of O3D.

A version of the Chrome browser was released for the Chrome OS recently. It was a deb package so it is designed for, most probably, Ubuntu. It is not much different from the standard Chrome browser, but it does have a clock display, battery indicator and a hint of network settings.

My guess - there is no window manager apart from the Chrome browser.

In Summary

Native Client promises much:
  • Programs will run fast.
  • Any compiler can be modified to produce NaCl code.
  • The compiler will make a program that will run on ARM and x86 (for now) CPUs.
  • The program will run in a sandbox that restricts what it can do.
  • Buggy programs can do no damage.
  • Malicious programs like viruses and worms can do no damage, nor can they spread or modify files on your OS.
  • May be enabling technology for ChromeOS