Monday, December 31, 2007

Whitespace separated lists

I'm trying to figure out a nice way to do lists in F++ while not requiring commas as separators and also taking advantage of the difference between \n and " " to avoid a layer of parens. By lists I really mean function argument lists and elements (I won't call them statements) in blocks of code. It seems like I should be able to make \n mean "next item in implicit list" but it's a bit tricky figuring out which list is the implicit list. Below are some examples of what I'd like to be able to write and what I'd like it to be equivalent to.

With whitepsace Explicit Notes
f 1 2 3 f(1, 2, 3) Nothing special.
f(1 g 2 3 4) f(1, g(2, 3), 4) The \n at the end of the "g" line terminates the g() function call and moves us onto the next argument for f().
{ x = f 1 y = f 1 2 3 z = f 1 2 \ 3 w = f g 2 3 v = f g 2 3 } { x = f(1); y = f(1, 2, 3); z = f(1, 2, 3); w = f; # still not sure if that's f or f() g(2, 3); v = f; g(2, 3); } Here the "z" line uses \ for continuation and so the \n is treated as just as list-separator space. The "w" line does not grab the "g". Neither does the "v" line because indentation is irrelevant!.

So what rules will result in parsing the above the way I want? Perhaps any explicitly delimited list containing a raw \n (ie not preceded by \) gets treated as 1 element per line and that's that. Or I could make function calls special. I think that's mainly where the fun is. Since they always start with a symbol, you know when you've encountered a function and if the symbol isn't followed by "(" then it ends at the next raw "\n". I can say a function call is symbol "(" args* ")" # separated by any kind of whitespace or symbol args* # separated by any whitespace except raw \n

Friday, December 14, 2007

Bjorn Lomborg - climate denier

Interesting article about Bjorn Lomborg, pointing out many (seemingly respectable) people's opinion that he is a deliberate bullshitter. While I have no reason to doubt it, it seems odd that someone who seems so scientifically dubious would be asked to give the first "Opinion" segment in Nature's podcast (4th Oct 2007, mp3, transcript). They did say in the introduction that they were interested in giving a platform to interesting voices but still...

Friday, December 07, 2007

Letter to the editor: bio-fuels vs food

Most of this comes from George Monbiot's recent article entitled "An Agricultural Crime Against Humanity".

Sir,

James Gleason repeats his usual points about climate change (Monday
December 3rd) but for a change, I find we something to agree with -
the impact of bio-fuels on food supplies for the poorest people in the
world.

The use of bio-fuel made from organic waste or grown on idle
agricultural land might have helped to reduce our use of oil but that
is not what is happening. Instead, land previously used to grow food
is being converted to grow fuel crops, in some countries, tropical
forests are being slashed and burned for the same purpose.

When you factor in the energy needed to farm and refine them with
current technologies, the environmental benefits of bio-fuels are
quite slim. Burning a forest to plant fuel crops eliminates the
benefit entirely and turns the whole thing into a net loss for the
environment.

Some foods can also be fuel crops, for example Swaziland is now making
fuel from casava while 40% of its people are facing food shortage.

Even the IMF is warning that demand for bio-fuel is pushing up food
prices for those who can least afford it.

Western governments must reevaluate their policies and targets for
bio-fuels and at the very least end subsidies,

Update:Published without edits I think.

Sunday, December 02, 2007

Letter to the editor: more climate change

Sir,

Robert O'Sullivan complains about the "non-solution put forward" in my
letter. I put forward no solution at all in my letter, I am simply
trying to show that there is a real and urgent problem. He calls me an
"alarmist" but has yet to make any real argument that this is a false
alarm.

Mr O'Sullivan brings up Homer Simpson's again. I agree that Homer has
something valuable to contribute. How we will have hamburgers if we
have to kill all of the farting cows? A funny question but with a
serious side to it.

I believe many people who deny the reality of man-made climate change
do not do so on the basis of scientific argument. They deny the
reality because they do not want to face questions like Homer's or
questions like "how will I have my holidays in the sun if I have to
pay for the full impact of the pollution it will cause?".

The fact is that someone must pay for it. Maybe it's someone in a
flood in Bangladesh or someone in California who's house has been
incinerated or someone in Tuvalu who's home disappeared below below
sea-level a few years ago. Or maybe it's a member of your family in
the Ireland of the future.

These are hard questions and we might not like the answers but the
longer we avoid them the greater the pain we will have to endure when
we are finally forced to deal with them.

I enjoy hamburgers and I enjoy travel, although I have already cut
back on my travel. I hope we can all continue to enjoy them but this
requires immediate action, not prevarication and denial,

Update:Published with some edits that probably improved it. Some fun going on in the comments on that page too. Next day, someone else calls Robert O'Sullivan clueless.

Saturday, December 01, 2007

Debate on academic boycott of Israel

Justin Podur covers a debate on whether an boycott of Israeli academic institutions is a good idea. This was held in a Canadian university, I get the impression that this debate simply couldn't take place in the US. Those opposed don't make a very good case and the question of where is the academic freedom of the Palestinians is a very strong counter to many of the anti-points.

Saturday, November 24, 2007

Letter to the editor: there is no debate on climate change

Sir,

Robert O'Sullivan complains complains that the "save the planet" squadron only
quote from scientific sources with which they agree. He himself does
not quote from any scientific source, the best he can manage is a
quote from Homer Simpson.

What else can he do? The only explanation for climate change that has
stood up to scrutiny is that it is caused by man-made emissions of
greenhouse gases. It's a pretty simple. Greenhouse gases trap the heat
of the sun and humanity is pumping out greenhouse gases like never
before, while at the same time slashing and burning the forests that
might have soaked them up.

If you do the calculations based on what have burnt and what the Earth
can absorb, it all fits with what we observe in reality.

The few other explanations that have any scientific basis at all have
been debunked.

Every now and then someone puts forward a new possible cause,
frequently with much media coverage. Then over the course of a few
months the results are analysed, mistakes are found and the idea is
put to rest. Of course the debunking never gets the same news
coverage.

There have been "natural" climate changes in the past but this time
around we have a smoking gun and a bullet wound - declaring it to be
"natural causes" would require some extraordinary evidence and that
evidence simply has not been found,
Update: Published without my reference to the media's lack of interest in debunking theories and some other minor tweaks. Update: Another round, although I don't think he actually read my letter!

Tuesday, October 30, 2007

Letter to the editor: distracting our attention with driving license fiasco

Ted O'Keeffe suggests that the government created the provisional
license fiasco to divert attention from their unjustifiable pay-rises.
I suppose this government would actually have the cheek to use a
display of incompetence to divert attention from their greed.

It was, however, a risky move, at this stage we are so used to it, it
would really have to be something spectacular to get our attention.
They seem to have delivered.

Years of bad planning and questionable tax-incentives have forced
ordinary home-owners out of the cities and given them over to
investors. This has created massive commuters belts. We have public
transport policies that make people entirely dependent on their cars
for almost every aspect of their lives. With all that, threatening to
take away their ability to drive is truly a master stroke that
couldn't fail to divert our attention.

I have no idea what they'll do to top this but they have almost 5
years more in power so I'm sure they'll think of something,

Monday, September 24, 2007

Letter to the editor: followup to landills and incineration

James A Gleeson was annoyed that I hadn't debunked his entire letter, so here goes.

James A. Gleeson complains that I didn't comment on the main element
of his letter about landfills and incineration. I commented on what I
considered the most important claim, that global warming was not at
all caused by human activity.

Mr Gleeson's says his main claim was a "revolutionary method of
cleaning" that can be applied to "power stations, industry and
incineration". From the details he mentioned I think he means a
material called "LSCF", and the recently published research by Prof
Ian Metcalfe and co. This material can be used to extract pure oxygen
from the air and can withstand high temperatures.

LSCF makes it easy to burn methane gas in pure oxygen, avoiding the
pollution that arise by burning it in nitrogen-rich air and producing
only carbon-dioxide and water. These can then be easily separated and
if we could find something to do with the carbon-dioxide, this would
make methane an incredibly clean fuel.

LSCF is not a magic bullet for industry or waste incineration. Its
benefits depend on the fact that methane is a very simple molecule,
containing only carbon and hydrogen. It would not have the same effect
when incinerating domestic or industrial waste as these produce a wide
variety of nasty pollutants even if burnt in pure oxygen.

As for recycling the carbon-dioxide, Prof Metcalfe himself points out
that it is much cheaper to just release it into the atmosphere and
that recycling would only be economical under a carbon credit system
(http://tinyurl.com/2efafu).

On landfills, Mr Gleeson says that "the very same toxins and
chemicals, irrespective of world population, existed in a processed or
unprocessed state then, as now". This is simply not true.

We are burying toxins and chemicals in landfills now that do not occur
in nature. It is true that the materials from which these chemicals
are made have been around for billions of years but they were never
before combined in these ways.

To ignore how the materials have been processed and combined is to
ignore the difference between C-O2 and C-O (carbon-monoxide) or
between H2-0 (water) and H2-O2 (peroxide bleach). In both cases the
basic materials are the same but the difference is life or death.

Human-created landfills tend to be located close to large population
centres, so their toxins (natural and man-made) have a much greater
effect than those buried deep in the earth's crust.

Landfills and incineration are probably both necessary evils but far
better than either is to reduce the amount of waste we produce and
where that waste is unavoidable, to use materials which can be
recycled,

Wednesday, September 12, 2007

Letter to the editor: climate change science

James Gleeson's points about landfills and climate change do no stand
up to examination.

He claims that landfills are a natural phenomenon, citing bogs and
landslides as examples. Neither bogs nor landslides involve the
burying of masses of toxic and volatile chemicals with all the
resultant dangers and so the comparison is invalid.

He cites Dr Antonio Zichichi's comments this year, saying that he
pointed out that climate change is driven by natural phenomena. Dr
Zichichi is not a climate scientist but has published a paper pointing
out problems with current climate modelling. His paper is available
online and contains the following, emphasised in bold text: "it is not
possible to exclude that the observed phenomena may have natural
causes. It may be that man has little or nothing to do with it." Even
if Dr Zichichi is right (and all of the thousands of climate
scientists are wrong), he is simply saying that their methods are
wrong. His paper does not put forward any evidence that humans are not
actually to blame.

The claim that "Human activity has less than 10pc impact on
environment" also comes from Dr Zichichi. Consider that a few thousand
years ago there were vastly fewer humans on the planet and each one
had a far smaller impact than humans today. So in the blink of the
planet's eye we have gone from having almost zero impact to 10pc. This
is an enormous, unprecedented change. It's hard to imagine how this
could occur without a significant impact on the planet!

Mr Gleeosn also cites Dr David Bellamy's stance on global warming. Dr
Bellamy wrote to the Sunday Times on 2005 to say he had "decided to
draw back from the debate on global warming". Before that he made
incredible claims about the worlds glaciers in a letter to New
Scientist. When Guardian journalist George Monbiot pressed him for his
source material it turned out he'd seen the figures on a website run
by a climate sceptic, who in turn could not provide any source for
them. You can read the details at
http://www.monbiot.com/archives/2005/05/10/junk-science/.

The fact is that climate scientists are so sure about the human role
in climate change that the UN IPCC has been able to get their
conclusions accepted by countries such as the USA and Saudi Arabia who
have a vested interest in business as usual. That just would not be
possible if there was any serious doubt that we are to blame.

Update: Published with the Monbiot paragraph omitted.

Update: He wasn't happy with my reply so I had to reply again.

Sunday, September 02, 2007

Pilger, Israel and the "coup" in Palestine

I'm seeing more and more about boycott Israel, including an article by John Pilger talking about how the boycott movement is picking up steam. The most interesting thing in the article was a reference to an article by Kathleen Christison, an ex-CIA analyst, and her explanation of the "civil-war"/"coup" in Palestine. I've only read a small bit of it so far but it seems to pin the blame on Elliott Abrams and the US.

Tuesday, August 21, 2007

Boycotting Israel and other stuff

Here is an article very clear explaining why a boycott of Israel is justified, despite Israel not being the only country doing bad things. I think the strongest argument though is that it could work. Israel wants to be part of the Western world and it's citizens have influence over their government. Most of the other countries worth boycotting are already officially boycotted or under sanctions and the people who would be hit by the boycott are not in any position to change things. This is why South Africa was the subject of a popular boycott but Cambodia was not.

Jonathon Cook writes another interesting article this time following up on the Israeli invasion of Lebanon, including evidence that Hizbollah were not launching rockets from town centres.

Sunday, August 19, 2007

Letter to the editor: Sikhs and Garda Uniforms

Sir,

as usual, it takes an outsider to teach us what we really love. The
Gardai changed its uniform on 1st July 2005, nobody cared. Some time
while nobody was looking, Gardai on bikes started wearing t-shirts,
cycling-shorts and cycle-helmets, again nobody protested. It has taken
a Sikh, giving up his free time to help make this country a better
place to wake us up to exactly how much we love the Garda uniform. We
love it so much that we would rather reject this man's energy and hard
work than change a single thing about this uniform. What a proud
moment to be Irish.

The minister for integration and several correspondents on your
letters page believe that since immigrants have chosen to move here
they should accept our culture and that we should not accommodate
theirs. While there is a certain logic to this argument, it misses a
very important point. Some time in the future, a Sikh man, born and
raised in Ireland, an Irish citizen all his life, will join the Gardai
or Reserves. What excuse will we make then?

Update: they published the second paragraph.

Chomsky and morality

Here's a good interview with Chomsky where he points out pretty clearly the double standards of morality applied by the west. A pretty blatant and almost funny example is from the Nuremburg trials

So, for example, the bombing of urban concentrations was not considered a crime. The bombings of Tokyo, Dresden, and so on—those aren’t crimes. Why? Because we did them. So, therefore, it’s not a crime. In fact, Nazi war criminals who were charged were able to escape prosecution when they could show that the Americans and the British did the same thing they did. Admiral Doenitz, a submarine commander who was involved in all kinds of war crimes, called in the defense a high official in the British admiralty and, I think, Admiral Nimitz from the United States, who testified that, ‘Yeah, that’s the kind of thing we did.’ And, therefore, they weren’t sentenced for these crimes. Doenitz was absolved.

Interesting too, the comments on the punishment of researchers and journalists. The point being that it is unimaginable that we would ever apply those standards to ourselves.

I must try find someone actually trying to argue against Chomsky. I come across people dissing him and I've heard of people arguing against his misquotes but never anyone arguing anything specific.

Sunday, August 05, 2007

25,000 Jews living happily in Iran

Another very interesting piece by Jonathan Cook asks: if Iran is the next Nazi Germany then why are 25,000 Jews living happily in Iran? In fact not only living happily but refusing the ever growing incentives from Israel to move, like $60,000 for every family, cheap loans etc. And not just politely declining, they are responding with

If you think Judaism and Zionism are one, it is like thinking Islam and the Taliban are the same, and they are not.
and
The identity of Iranian Jews is not tradeable for any amount of money. Iranian Jews are among the most ancient Iranians. Iran’s Jews love their Iranian identity and their culture, so threats and this immature political enticement will not achieve their aim of wiping out the identity of Iranian Jews.
Why is Israel so keen to take them in? Cook says it's because their existence contradicts Israel and the US's claims that Iran is intent on genocide. Seems plausible. What are the counter arguments to that?

Lots of other titbits in there too, including claims about previous black ops by Israeli-backed Zionists to force Jews out of other countries. No references though - not every writes like George Monbiot!

Sunday, July 01, 2007

Suspected al-Qa'ida militants

Another Indo article tells us according to a US army spokesperson, "22 suspected al-Qa'ida militants were killed in the early hours of fighting". What does that mean? Obviously it means 22 people are dead but if that was all it meant then they would just say "22 people". Of course it doesn't really mean much more than that, there's no way to know if they were on a list of suspects who were being hunted or whether they are became "suspects" right around they time they were shot. The meaning is not at all clear. The implication however is quite clear - they were bad-guys and they had it coming. In fact it's kind of surprising that they even used the word "suspected". They wouldn't say that if they had any evidence at all.

So there they are, 22 dead people who's entry in the history books will be "suspected al-Qa'ida militant".

Deniers of evolution

Once again, the Indo letters page does my head in, I suppose it's not the Indo's fault that this country is full of idiot. this guy claims there is "no scientific evidence whatsoever" for natural selection. I guess then that he's not worried about MRSA for example.

It seems funny to me that "people of faith" claim there is no evidence for it and then get upset that scientists believe in it anyway, I mean if they're right and there really is no evidence then that makes scientists "people of faith" too.

Monday, May 28, 2007

Solution to ATI 9100 IGP TV-out with ubuntu feisty

Problem

I upgraded my "telly box" to the latest Ubuntu not knowing that the bastards in ATI no longer support my graphics card (9100 IGP, it's the one built in on my Shuttle ST61G4). The newest fglrx drivers don't work for my card and the older ones that do work, don't work with xorg 7.2.0 that comes with Ubuntu 7.04 (feisty).

Non-solutions

I tried downgrading to edgy's xorg (6.8 I think) as described by one user, that didn't work for me although I never got the fglrx drivers happily installed so maybe it would have worked eventually.

I tried applying the GATOS tv-out patch to xorg 7.2.0. With some tweaking, I managed to get this to compile and even output sane messages from X about setting my output to PAL but never got working output (there was a flash of the Ubuntu colour-scheme but it looked like it was running at the wrong refresh rate). I never tried getting the GATOS patch working before now so I have no idea whether it should have worked or not. If anyone is interested in playing around with it, my updated version is here - remember, this exists as a patch because the GATOS license isn't compatible with xorg's license.

I spent some time monkeying around with X and fbdev but didn't get any joy from that. I couldn't even get fbset to change the console settings

Solution

Finally I tried something that I'd thought of ages ago but never got around to doing because I assumed it would suck. I switched X to use the vesa driver. I did dpkg-reconfigure xserver-xorg , chose vesa as my driver and accepted all the defaults and happy days ensued. It even seems to use far less CPU when playing back mpeg2 files!

For reference, here's the xorg.conf I'm using

# /etc/X11/xorg.conf (xorg X Window System server configuration file) # # This file was generated by dexconf, the Debian X Configuration tool, using # values from the debconf database. # # Edit this file with caution, and see the xorg.conf(5) manual page. # (Type "man xorg.conf" at the shell prompt.) # # This file is automatically updated on xserver-xorg package upgrades *only* # if it has not been modified since the last upgrade of the xserver-xorg # package. # # If you have edited this file but would like it to be automatically updated # again, run the following command: # sudo dpkg-reconfigure -phigh xserver-xorg Section "Files" FontPath "/usr/share/fonts/X11/misc" FontPath "/usr/share/fonts/X11/cyrillic" FontPath "/usr/share/fonts/X11/100dpi/:unscaled" FontPath "/usr/share/fonts/X11/75dpi/:unscaled" FontPath "/usr/share/fonts/X11/Type1" FontPath "/usr/share/fonts/X11/100dpi" FontPath "/usr/share/fonts/X11/75dpi" # path to defoma fonts FontPath "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType" EndSection Section "Module" Load "bitmap" Load "ddc" Load "dri" Load "extmod" Load "freetype" Load "glx" Load "int10" Load "vbe" EndSection Section "InputDevice" Identifier "Generic Keyboard" Driver "kbd" Option "CoreKeyboard" Option "XkbRules" "xorg" Option "XkbModel" "pc105" Option "XkbLayout" "ie" EndSection Section "InputDevice" Identifier "Configured Mouse" Driver "mouse" Option "CorePointer" Option "Device" "/dev/input/mice" Option "Protocol" "ImPS/2" Option "ZAxisMapping" "4 5" EndSection Section "InputDevice" Driver "wacom" Identifier "stylus" Option "Device" "/dev/input/wacom" Option "Type" "stylus" Option "ForceDevice" "ISDV4" # Tablet PC ONLY EndSection Section "InputDevice" Driver "wacom" Identifier "eraser" Option "Device" "/dev/input/wacom" Option "Type" "eraser" Option "ForceDevice" "ISDV4" # Tablet PC ONLY EndSection Section "InputDevice" Driver "wacom" Identifier "cursor" Option "Device" "/dev/input/wacom" Option "Type" "cursor" Option "ForceDevice" "ISDV4" # Tablet PC ONLY EndSection Section "Device" Identifier "ATI" Driver "vesa" BusID "PCI:1:5:0" EndSection Section "Monitor" Identifier "Generic Monitor" Option "DPMS" HorizSync 28-50 VertRefresh 43-75 EndSection Section "Screen" Identifier "Default Screen" Device "ATI" Monitor "Generic Monitor" DefaultDepth 24 SubSection "Display" Depth 24 Modes "800x600" "640x480" EndSubSection EndSection Section "ServerLayout" Identifier "Default Layout" Screen "Default Screen" InputDevice "Generic Keyboard" InputDevice "Configured Mouse" InputDevice "stylus" "SendCoreEvents" InputDevice "cursor" "SendCoreEvents" InputDevice "eraser" "SendCoreEvents" EndSection Section "DRI" Mode 0666 EndSection

Wednesday, May 16, 2007

Iran, Iraq US and hostages

Stunningly, it seems that US forces attempted to grab 2 senior Iranian security personnel who were in Iraq on the invitation of the Iraqi president! Patrick Cockburn writes about it here and here. They failed to grab their main targets and instead took 5 Iran officials who's regular job seems to have been issuing travel documentation to Kurds doing business with Iran.

It's pretty amazing that they would do this and puts the sailor abductions in perspective.

Wednesday, January 31, 2007

Watching Japanese TV in Dublin

ssh terebi mkfifo pipe ssh terebi cat pipe | mplayer -

then in another window
ssh terebi mencoder -oac lavc -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=100:acodec=ac3:abitrate=64 /dev/video0 -o pipe

gives me watchable live tv.

I think I should really be using some variety of vlc but that's another day's work

Tuesday, January 30, 2007

Useful things when you've wiped you partition table (conclusion)

This is the concluding part of my earlier post on recovering after wiping the partition table and the first 30k or so of my harddisk. It has a happy ending.

It didn't take much more effort in the end to rebuild my laptop's partition table. It turns out that gpart was not terribly useful as I had used extended partitions and nuked the first one. It found my 2 linux partitions but refused to rebuild the partition table. It also outputs the location of the partitions in MB which is no use at all. This patch

diff -ur gpart-0.1h/src/gpart.h ../gpart-0.1h/src/gpart.h --- gpart-0.1h/src/gpart.h 2001-01-30 23:07:29.000000000 +0000 +++ ../gpart-0.1h/src/gpart.h 2007-01-03 05:07:06.000000000 +0000 @@ -171,7 +171,7 @@ struct disk_geom *disk_geometry(disk_desc *); int reread_partition_table(int); -#define s2mb(d,s) { (s)*=(d)->d_ssize; (s)/=1024; (s)/=1024; } +#define s2mb(d,s) { (s)*=(d)->d_ssize; } #define align(b,s) (byte_t *)(((size_t)(b)+(s)-1)&~((s)-1)) #include "gmodules.h"

makes it output bytes instead which I could then divide by 512 to get sectors. I had to compile it on a Debian box (not sure what vintage), it wouldn't compile under Ubuntu.

Next I used sfdisk -d /dev/sda to dump a partition table from another machine as an example and then edit that to look like

# partition table of /dev/sda unit: sectors /dev/sda1 : start= 63, size= 39053952, Id=83 /dev/sda2 : start= 39070143, size= 3903728, Id=82 /dev/sda3 : start= 42973938, size= 72260370, Id=8e /dev/sda4 : start=115234308, size= 1975932, Id=83, bootable

I worked out the sizes by subtracting the start values from each other. Saving that in a file and doing sfdisk < my_partitions.txt gave me a new partition table which amazingly worked. Of course /dev/sda1 wasn't recovered properly because it had also been partially overwritten by the format but luckily I had nothing useful on that partition.

Saturday, January 27, 2007

Get The Focaccia!

I spotted a focaccia (Italian bread with veggies and maybe bits of bacon) shop while in Courmayeur a few days ago and got a great idea for a franchise. Kinda along the lines of It's A Bagel. As with all franchises you need a snappy name. I think

GET THE FOCACCIA!


has a certain ring to it. The menu would explain all the different types of focaccia available and so would be titled

WHAT THE FOCACCIA?


The opening hours, the recipe book and the store locator would be named along similar lines.

Saturday, January 13, 2007

Memoising a complete parser

Not sure if "complete" is the correct term but I mean a parser that finds all possible parses of the stirng by the grammar. Usually very expensive but by memoising the application of rule A at char N in the string it becomes cheaper. The key is the value that you store. For memoised recursive descent, you just store the parsed value or FAIL. For this you have to store an object that can generate parsed values in the correct order and which caches any previously generated ones. Not so bad really. There are some questions though about quantifiers. It might be worth trying to share data between X{4} and X{5} applied at the same char. But maybe not.

Wednesday, January 03, 2007

An alternative to a recovery floppy

Does anybody ever make a recovery disk these days after installing Linux. I certainly don't and now I'm regretting it! It's too inconvenient to root out a floppy or a blank CD and even if I had made one, I wouldn't have it with me here in Tokyo so I'd be just as badly off. Basically they are not terribly helpful.

The amount of non-redundant information stored on a recovery disk is quite small, basically it's your MBR and partition table and maybe some special boot params. Really all you need is a safe copyof your MBR and partition table. With that you can boot from a generic recovery CD, fix the partition table and MBR and then reboot as normal (or maybe fix the data on your partitions first now that you can access them).

So the world would be a better place if instead of offering to make a recovery CD, Linux distros offered to email you a copy of your MBR and partition table. If you use gmail then that's the end of it, it'll be there in your gmail account should the need arise. Download it and use dd to install it. Bingo. If you store your email on the computer itself then you need to copy that mail to somewhere else but that's still much easier that creating a floppy/CD that you're going to lose.

I'm off to file some bugs (just as soon as I get my data back!).

Useful things when you've wiped you partition table

Doh! While trying to get my slax distro onto a USB key, I fucked up big time and dos formatted (mkfs.vfat) my hardrive (my head is still in the era where hard disks are hdX, not sdX).

gpart can try to guess where your partitions were but it doesn't know LVM2

LVM2 partitions have a sector which begins with "LABELONE" as documented in these slides (thanks to agk on #lvm!). I invoked the following script with ./lvm.pl /dev/sda to get a list of all the sectors that contains that string.

#! /usr/bin/perl use strict; use warnings; my $buf; my $sector = 0; my $f = shift; open(F, $f) || die "couldn't open '$f', $!"; while(read(F, $buf, 512)) { if ($buf =~ /^LABELONE/) { print "sector = $sector\n"; } $sector++; } print "last sector was $sector\n";

Stuffing all those sector numbers into $ss and then doing

for s in $ss; do sudo perl -e 'open(F, "/dev/sda"); seek(F, shift()*512, 0); read(F, $buf, 512); print $buf' > sec.$s $s; done
gets me all the sectors in sec.XXX files. I can then
for s in $ss; do echo $s; echo; hexdump -c sec.$s; echo ;done|less
to take a look at them without trashing my console. The important thing to remember is that LABELONE will be followed by a secotr number. If it's 1 then this is sector 1 of the partition but really I'm looking for sector 0 so I need to subtract 1.

Tuesday, January 02, 2007

Making a secure bootable cd with sshd and my ssh keys

Update: ddclient doesn't seem to work. I don't have time to figure out why, the rest works fine though. Update: slax is currently "frozen", I've updated the links in this doc to point to the legacy hosting service. Also, it seems that they have messed with the sshd config and possibly broken it in the latest version.

I've built a headless box that's going to live in Japan when I go back to Ireland. There'll be no one in Japan to fix it if it goes bad. The best I can do is get someone to insert a CD and reboot but after some searching and some asking it seems none of the bootable CDs will boot the machine into a useful state for remote admin. slax was recommended to me on TLUG as a good customisable distro. It turned out to be pretty easy thanks to slax's rootcopy feature which allows you to make minor modifications without digging around (too much) in the compressed package files. I've broken the process down into a few steps, with a quick bash script for each one.

Create a directory to work in and cd into it

mkdir slax cd slax

Get a copy of the .iso

You need slax-frodo-x.y.z.iso, you can get it from the slax download page. The frodo edition is the minimal version on which all the others are based.

Make a copy of the files from the CD

This is necessary because we need to add some files. So I ran this as ./prep_image.sh ~/slax-frodo-5.1.8.iso

#! /bin/bash iso=$1 shift if [ "$iso" = '' ]; then echo 1>&2 Usage: echo 1>&2 "$0 " exit 1 fi mkdir slax.mnt mount -t iso9660 $iso slax.mnt -o loop cp -v -Tr --preserve=all slax.mnt slax umount slax.mnt

Enable SSH

It's disabled by default (rc.sshd is not executable), so I replace it with one that is executable. I also turn off password logins because everyone knows the root password for slax. Finally I include an authorized_keys file so that I can ssh in with my ssh key. I ran this script as ./enable_ssh.sh ~/.ssh/authorized_keys

#! /bin/bash auth_keys=$1 shift if [ "$auth_keys" = '' ]; then echo 1>&2 Usage: echo 1>&2 "$0 <path/to/auth_keys_file<" exit 1 fi # make rc.sshd executable and stop root logins using a password # # extract rc.sshd from the module and tweak the permissions mkdir 02_core.mnt mount -t squashfs slax/base/02_core.mo 02_core.mnt -o loop mkdir -p rootcopy/etc/rc.d cp 02_core.mnt/etc/rc.d/rc.sshd rootcopy/etc/rc.d chmod 700 rootcopy/etc/rc.d/rc.sshd # disable password logins mkdir -p rootcopy/etc/ssh cp 02_core.mnt/etc/ssh/sshd_config rootcopy/etc/ssh cat >> rootcopy/etc/ssh/sshd_config <<EOM # since we're starting sshd by default, don't allow root logins with # passwd, must use ssh keys PasswordAuthentication no EOM # install keys file mkdir -p rootcopy/root/.ssh chmod 700 rootcopy/root/.ssh cp $auth_keys rootcopy/root/.ssh chmod 600 rootcopy/root/.ssh/authorized_keys cp -r --preserve=all rootcopy/* slax/rootcopy umount 02_core.mnt

Update a dyndns entry

The machine is on a cable modem and doesn't have a fixed IP, so I need to know where it is. I downloaded the ddclient module and the following script puts it in place, puts your ddclient.conf file into /etc and makes sure that it gets started on boot (I assumed it would start by itself actually, I'm not sure if that's a bug or not). I invoked this script as ./ddclient.sh ddclient.conf

#! /bin/bash conf=$1 shift if [ "$conf" = '' ]; then echo 1>&2 Usage: echo 1>&2 "$0 " exit 1 fi cp ddclient_3_7_0.mo slax/base mkdir -p rootcopy/etc/ cp $conf rootcopy/etc/ddclient.conf mkdir -p rootcopy/etc/rc.d cat > rootcopy/etc/rc.d/rc.local <<EOM #! /bin/bash /etc/rc.d/rc.ddclient start EOM chmod 755 rootcopy/etc/rc.d/rc.local

Add any other modules

There doesn't appear to be an editor in the slax-frodo image so I grabbed joe and copied the .mo into slax/base/

Move files into place and create a new .iso

So far everything we've done has been in a rootcopy/ directory in the current directory. Now it's time to move that into place in slax/ and invoke the iso building script with the following script which outputs it to slax-ssh.iso in the current directory.

#! /bin/bash rm -rf slax/rootcopy cp -r --preserve=all rootcopy slax cd slax ./make_iso.sh ../slax-ssh.iso

Test it in qemu

qemu -cdrom slax-ssh.iso should boot up. I never figured out how to get qemu bring up a real IP interface - the virtual machine can connect to the outside world but I can't connect to it. I tested it by setting up an ssh tunnel connecting port 22 on the VM to port 2022 on the host machine with ssh -R2022:localhost:22 fergal@my.host.machine.ip. Then I did ssh -p 2022 root@localhost with my ssh keys loaded and in I went. When my keys aren't loaded, I don't get a password prompt so I can't get in. Perfect.

Monday, January 01, 2007

deep 0.3

Finally got deep onto code.google.com/hosting/ and onto the python package repo CPAN-alike thingy, which means that it's just an easy_install deep away whenever I want it.