Browsed by
Month: February 2011

Setting a Static IP and DNS in Debian/Ubuntu over the CLI

Setting a Static IP and DNS in Debian/Ubuntu over the CLI

Some times you just need a static IP but have no GUI to easily set one up. Well it is not so hard to do in Debian-based distributions.

  1. Open /etc/network/interfaces in your favorite editor. I like nano.
  2. Find the line that starts with iface [interface]. The interface you are looking for is most likely eth0 or something similar.
  3. Change the line to read iface [interface] inet static.
  4. After it add your IP information. I have included a common example but just replace my information with your own.
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
  5. Open /etc/resolv.conf.
  6. In it use the nameserver directive to specify your name server(s). The nameserver directive(s) will be searched in the order entered here. Here is an example:
    nameserver 192.168.1.2
    nameserver 192.168.1.3
  7. Restart networking with sudo /etc/init.d/networking restart.

[Edit] 2013.08.10
Thanks to Renat Zaripov for pointing out my mistake in typing /etc/resolve.conf instead of /etc/resolv.conf.

Use GRUB2 to Boot ISOs off a Flash Drive

Use GRUB2 to Boot ISOs off a Flash Drive

I will soon need to build a few new PCs that do not have optical drives (one will be a firewall, for example). They do not need the drives for day-to-day usage but I do need to get an OS on them. Since virtually all consumer boards now have USB and I have piles of unused flash drives laying around I decided not to spend the money on an external drive and go the flash drive route.

Here are the steps I took to get my Linux ISOs to boot off a USB flash drive. For these exact steps to work you will need an existing Linux installation (a LiveCD will work just fine).

  1. Create a new, formatted partition big enough to store your ISOs. I am using EXT4 but any filesystem supported by GRUB2 will work. I prefer to use GParted for this.
  2. Mount your new partition. Most Linux desktop distributions will do this automatically for you if you just unplug the device and plug it back in.
  3. Install GRUB2: grub-install --force --no-floppy --root-directory=[path partition was mounted] /dev/sdX where X is the flash drive.
  4. Copy over any ISOs you want to be able to boot to the root of your new partition.
  5. Create [path partition was mounted]/boot/grub/grub.cfg and add the lines

    set timeout=5
    set default=0

  6. In [path partition was mounted]/boot/grub/grub.cfg add any of the following example entries for your favorite distributions:

    menuentry "Ubuntu 10.10 Desktop i386" {
    loopback loop /ubuntu-10.10-desktop-i386.iso
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/ubuntu-10.10-desktop-i386.iso noeject noprompt splash --
    initrd (loop)/casper/initrd.lz
    }

    menuentry "Ubuntu 10.10 Server i386" {
    loopback loop /ubuntu-10.10-server-i386.iso
    linux (loop)/install/vmlinuz boot=casper iso-scan/filename=/ubuntu-10.10-server-i386.iso noeject noprompt splash --
    initrd (loop)/install/initrd.gz
    }

    menuentry "Darik's Boot And Nuke" {
    loopback loop /dban-2.2.6_i586.iso
    linux (loop)/DBAN.BZI nuke="dwipe" iso-scan/filename=/dban-2.2.6_i586.iso silent --
    }

    menuentry "Memtest 86+" {
    linux16 /memtest86+.bin
    }

I could not, for the life of me, get any Windows ISOs to boot using GRUB2. On top of that I came across a number of people trying to do the same thing whom all failed. If anyone gets this working please post in the comments. I may be able to chainload into another boot loader but that is for another day.

[Source]

Update 2011.02.18
I found this. It may be nothing but it also may be a jumping off point from which to boot from a Windows ISO.

Update 2021.06.16
I finally figured out how to get the Windows installer to boot from a USB flash drive. Thank you to Doc in the comments for kicking me off in the right direction!

  1. First create an NTFS partition. I made mine a second 8GB partition which fit everything comfortably.
  2. Download the Windows 10 ISO from Microsoft. (I know it feels dirty but Microsoft is offering this for free and legit so why not take advantage?)
  3. Copy the entire contents of this ISO onto your new NTFS partition (not the ISO itself).
  4. Add the following to [path partition was mounted]/boot/grub/grub.cfg

    menuentry "Windows 10" {
    set root=(hd0,msdos2)
    insmod ntfs
    insmod chain
    ntldr /bootmgr
    }

Note the line set root=(hd0,msdos2). msdos2 must be set to whichever partition you copied the Windows 10 files to (counting starts at 1, not 0). Also note this is still using MBR, not GPT/UEFI. Maybe I will update with that at a later date but it should not be too hard to figure out.

You will need to disable Secure Boot for any of this to work.

Working Around JavaScript Shortcomings

Working Around JavaScript Shortcomings

I am working on a real-time, JavaScript only project. I do not want to give too much away right now but I will say this: JavaScript was not designed for what I want it to do. The timers are not accurate enough and relying solely on synchronous or asynchronous communication between components simply will not work at all. What it comes down to is this is what C or C++ was meant for.

I have spend hours, today alone and not mentioning yesterday, just reading. Reading on tricks to make your own timers, how Internet Explorer on Windows or Firefox on Linux might react or whatever and how reliably. But I am determined; I am determined to make what I envision work as I envision it with nothing more than what everyones browsers already have. A friend just suggested I use Flash but Flash has way too many issues with performance and cross-compatibility (say what you want I am sticking to that). In two words? Fuck. Flash.

I have written about how anal I am in the past. Especially when it comes to things like this. I refuse to be beaten by a scripting language never-the-less a scripting language built into a God damned web browser. If I may bring my ego into this– too late– it would also be great to be “the guy” who pulled this off. The guy who people copy. The guy who starts a bunch of copycat projects.

I have learned a lot thus far. I am convinced this is very doable. It is all just going to require some research, cursing, work, and cursing. This is going to be great.

Opening winmail.dat in Thunderbird in Linux

Opening winmail.dat in Thunderbird in Linux

Microsoft, being Microsoft, feels a need to not use the same standard that everyone else has been using for umpteen years. This, of course, creates problems for everyone. A great example of this is their TNEF format which we all see as winmail.dat files in e-mail attachments which does not even work correctly across different versions of Outlook in some cases.

Since I run Ubuntu in my day-to-day I needed a way around this. These are the steps I took.

  • Install the tnef package: sudo apt-get install tnef
  • Create a script in your home directory and make it executable: touch ~/tnef.sh;chmod +x ~/tnef.sh
  • In this newly created file stick

    #!/bin/bash

    SAVE_PATH=~/Desktop/winmail.dat
    mkdir $SAVE_PATH
    tnef -C $SAVE_PATH < $1

  • When you try to open the attachment in Thunderbird just tell it to open it with your new script.

Change SAVE_PATH to wherever you would like winmail.dat to be extracted to. You will have a new folder with the extracted contents where ever SAVE_PATH is pointing. If you wanted to, for example, have them extracted directly to your desktop you would want to comment out the mkdir line.

The Old vs The New

The Old vs The New

Back in the day computer programming was more of an ordeal than it is now.

A computer programmers job is to take an idea, turn it into a set of instructions, and write code in a programming language that tells the computer what those instructions are. The computer then takes the resulting program and does whatever it was told to do. All of these instructions contained in this program, at their lowest level, boil down to “stick these numbers into these memory locations, do some addition on them, stick the result in this memory location, rinse, repeat.” It often all appears to be much more than that but that is a computer programmers mission in life.

In most older languages– C comes to mind– a programmer had to first allocate the memory they wanted to use. After they were done using it they had to deallocate the memory. This was especially important because memory was expensive and, as a result, computers of the day did not have much of it. It was common for tricks, or hacks, to be used that were not ideal solutions because there was simply no other way with such a limited resource.

Fast forward to years ago when I first started with this discipline. The people who I had learned from– both in the form of teachers but much more commonly in the form of over-the-Internet searching– were the product of this era. As a result I have an almost religious obsession with managing resources myself. I tend to shy away from libraries that do a lot of the work for me simply because I can not see what they are doing, how they are doing it, and when they are doing it. In addition I do not control their resource usage which just irks the crap out of me. In an age when desktops with multi-gigabyte amounts of memory can be had for under $300 is this still a logical habit?

Many languages today have a feature called garbage collection. Very popular and common languages like PHP, Java, and the various .NET Framework languages all implement this. Not only do they implement it they nearly demand you rely on it. This always seems like the job of a programmer to me and not the machine. After all, the program needs to, in addition to whatever code I write, keep track of all memory allocated, variable types, scope of said variables, ect for garbage collection to work. It just seems like a lot of work being done using a lot of resources I could easily use somewhere else and a bad case of wag the dog. It is also worth mentioning that none of the above languages come anywhere near the speed and efficiency of C.

What brings all this up is a project I have had in the back of my mind for a year now. This project requires a lot of JavaScript. JavaScipt, for anyone who is unfamiliar, has a surprising amount of functionality missing from it. It can not, for example, trim excess whitespace from a string nor can it pad a string. These would be common programming tasks which you would have to write yourself.

I want to do something more complex than basic string manipulation. I want to create a scrolling, Google Maps-esk interface among other things. I could write all of the code myself (which I already did for some of another project) or I just could use a library like jQuery. jQuery has a lot of the smaller bits of what I need to do already done. Not only that but so many people who use it that one can safely assume that most of the bugs I would be likely to hit would already have been ironed out. It really seems like a win-win for both jQuery and myself.

Perhaps Jeff Atwood makes a good point when he says I am dangerous. Perhaps I have already answered my own question just by writing about it. The logical solution is to use the time-tested, rave-reviewed jQuery but there is just something inside me that does not want to give up the control. It just seems… wrong. I should be able to control every aspect of my software as to make it as efficient as possible. I should put in the work and have everything the way I know it should be without any questions about the guts or inner workings of something. On the other hand if I were a mechanic I would not be building my own combustion engine just because I could…

… I should stop being such an anal control freak.