When I upgraded to Ubuntu Intrepid Ibex I installed it clean on a new harddrive that I installed alongside my old Hardy hard drive (that was totally unintentional – but hilarious). I then mounted the old hard drive, which was much bigger, via fstab so that I could have access to more storage and my older files, but then a funny thing started happening… occasionally when booting the mount would fail and upon inspection it was because the hard drives labeling had been swapped around. One HD is SATA and the other older one is IDE, when I was setting things up the SATA drive was hda and the IDE was given hdb, the problem was that on subsequent boots this would be reversed !!! I’m not sure if this is a linux thing or a bios thing but either way it was screwing up my system so I needed a solution, thankfully this was very simple – all i had to do was find the UUID of the harddrive in question using one of the following two commands
ls -las /dev/disk/by-uuid/
blkid /dev/hda1
Then it was as simple as editing my /etc/fstab to replace the reference to /dev/hd[ab]1 with a reference to the uuid and I was done
/dev/hda1 /data ext3 defaults,errors=remount-ro 0 1
to
UUID=21819e49-70fa-477e-9937-bd04e0550aab /data ext3 defaults,errors=remount-ro 0 1
Thanks to f241vc15 for pointing me in the right direction.
I couldn’t for the life of me figure out how to do it until I came across this web site: http://www.troubleshooters.com/linux/vifont.htm
Considering that it is GRAPHICAL vim and there is a graphical selection of the font/size/etc, you’d think they’d have an option for saving the settings you choose right? Wrong, instead after selecting the font you like, issue the command
:set gfm?
which returns something like
guifont=Nimbus Mono L 16
then edit your ~/.vimrc (creating it if it doesn’t exist) and add the following line (dont forget to escape the spaces)
set gfn=Nimbus\\\ Mono\\\ L\\\ 16
A lot of the work I do involves making a given piece of code do the same thing it used to do but in less time (some people call it optimisation). The first step in this is to accurately quantify the amount of time taken to perform some piece of work and to that end I have a nifty little piece of code which interogates the processor for the current value of the time stamp counter, this looks something like this.
inline unsigned __int64 RDTSC(void)
{
_asm _emit 0x0F
_asm _emit 0x31
}
This sends the processor opcode 0F 31 to the processor and returns the result, unfortunately, this doesn’t work so well when you move away from the windows environment due to the use of the non-standard “_emit” statement. Thankfully Chistrian Schueler has a nice way to do this with GCC
inline volatile long long RDTSC() {
register long long TSC asm("eax");
asm volatile (".byte 15, 49" : : : "eax", "edx");
return TSC;
}
If you are on a 192.168.*.* subnet the following should work for you
ifconfig | grep -e 192.168 | grep -o -e addr:[0-9]*\.[0-9]*\.[0-9]*\.[0-9]* | grep -o -e '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'
which gives you a nicely formated “192.168.0.1″ or whatever your ip address might happen to be
I’m running ubuntu linux as my main OS with a windows XP VM for all those things I just have to have windows for (like writing plugins for a must have application). The problem I sometimes have with this is that disk accesss can be terrible from inside the VM, like cleaning up 20 odd Gb of data that were cluttering up the disk image – thankfully if you shut down the VM you are able to mount the disk image natively and perform operations on it.
sudo mkdir /mnt/winxp_one
sudo vmware-mount.pl /var/vm/WinXP_One/Windows\ XP\ Professional.vmdk 1 /mnt/winxp_one/
And then suddenly I can navigate my C drive from that mount point and delete that 20Gb of files in 20 seconds instead of 20 minutes like it would have been under windows.
[dev@stoner:/mnt/winxp_one/BDK] ls ../
AUTOEXEC.BAT CONFIG.SYS MSDOS.SYS pagefile.sys ruby
BDK Documents and Settings NTDETECT.COM PDOXUSRS.NET System Volume Information
boot.ini dump.txt ntldr Program Files temp
Config.Msi IO.SYS OT RECYCLER WINDOWS
[dev@stoner:/mnt/winxp_one/BDK]
However, I did have to manually kill the process after I had finished in order to release the lock on the vmdk file
[dev@stoner:/mnt] ps -e | grep vm
6121 ? 00:00:00 vmnet-bridge
6143 ? 00:00:00 vmnet-netifup
6144 ? 00:00:00 vmnet-netifup
6163 ? 00:00:00 vmnet-natd
6170 ? 00:00:49 vmware-serverd
6191 ? 00:00:00 vmnet-dhcpd
6192 ? 00:00:00 vmnet-dhcpd
8049 pts/2 00:00:00 vmware-mount.pl
8059 pts/2 00:00:04 vmware-loop
8060 pts/2 00:00:00 vmware-loop
[dev@stoner:/mnt] sudo kill -9 8049 8059 8060
Last night I had a strange error, Azureus crashed and then would not start back up again. This was strange because it seemed to think that it was already running when clearly it wasn’t
Being a java application, azureus will spawn two processes
- the azureus executable
- the actual java virtual machine upon which it will run
Both these processes were definetly dead but I was still getting an error message like the following
StartServer ERROR: unable to bind to 127.0.0.1:PORT# listening for passed torrent info: Address already in use: JVM_Bind
StartSocket: passing startup args to already-running Azureus java process listening on 127.0.0.1: PORT#
where PORT# is the port that I’m running azureus on. Strange huh? So after a bit of googling I came up with a post by a couple of cluey fellows who have pretty much the same problem and came up with a solution. The forum post is here, but I’ll let you know how I figured it just in case it is handy for someone
The following is done as root (or sudo if you are running ubuntu)
fuser -n tcp PORT# -k
That simple
The fuser is used to identify processes using a particular resource (file or socket) and has an optional switch to kill any processes it finds using said resource. The above command tells it to find processes still holding up that particular tcp port and kill them.
Trying to share a folder on my fedora box with my new ubuntu box, couldn’t figure out why it wasn’t able to connect, until I remember good ole iptables (sigh). And the issue is complicated by the fact that nfs seems to start its various services on random ports (sigh)… still I found a good post here which got me through it.
cat >> /etc/sysconfig/nfs
LOCKD_TCPPORT=48620
LOCKD_UDPPORT=48620
MOUNTD_PORT=48621
STATD_PORT=48622
RQUOTAD=no
RQUOTAD_PORT=48623
^D
then put together a little script to allow the requisite ports to be opened via iptables
cat > ~/iptable-allow.sh
#!/bin/bash
for i in 111 2049 48620 48621 48622 48623
do
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $i -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport $i -j ACCEPT
done
^D
then a quick
chmod +x ~/iptable-allow.sh
~/iptable-allow.sh
and I was in business
So I was building a machine for my mother for her medical practice… nothing fancy just a regular sit-out-back headless server that she can have chugging away co-ordinating her office while the prettier looking machines get stuck out front for patients to see. Well while building it I noticed that she didn’t really require 500Gb of hard drive, 320Gb would be fine for her needs and luck just happened to have it that I had a spare 320Gb hanging around and a hankering for a 500Gb drive in my new desktop. A deal was made and my time was given over in return for a hard drive upgrade, I would install ubuntu on the new 500Gb drive, copy data over from the old one and then install windows XP on the 320Gb for her to install her new software packages on.
This all went swimmingly after I realised that the old 320 was formatted with Logical Volume Management (LVM) partitions and that I needed to install the LVM2 tools and then restart my new machine (thanks Fedora).
sudo apt-get install lvm2
So after finally realising that a reboot was required (I guess I’m spoilt by never having to restart normally), I finally managed to get the required data off the HD and onto the new 500. Phew…. problems over right? wrong!! When I built the new system and tried to install windows XP I got a rude shock… the cd-rom didn’t seem to like the boot cd and wouldn’t get any further than
Setup is inspecting your computers hardware... this may take a few minutes
Well I left that thing for hours and no joy it was most definitely hanging and was not about to progress any further, luckily being the technophile that I am I had a spare cd-rom (or 5) lying around and I swapped each and every one of those units in to no effect. Maybe the memory got buggered? memcheck passed! Maybe it’s the cd itself? Got a spare install media from work same edition, still no joy! Hmmm, where to next? Google! Turns out windows XP doesn’t play well LVM and in fact having an LVM partitioned hard drive in there will cause the entire process to summarily seize up!
The solution I ended up going with was to take an Ubuntu 7.10 live CD, start up and then use fdisk to remove all partitions on the disk and then “create a new empty DOS partition table”.
sudo fdisk /dev/sda
d 1 # delete partition 1
d 2 # delete partition 2
o # create a new empty DOS partition table
v # verify the partition table
w #write table to disk and exit
restart with the windows XP cd in the drive and things went perfectly… so kids the moral of the story is that, like gasoline and matches, Windows XP and LVM DO NOT MIX!!!
Was looking through the GUI options for a virtual machine I have and could not for the life of me figure out how to resize the hard disk. I originally thought that 10Gb would be sufficient for my windows image but that notion was quickly disabused after I’d installed Visual Studio and pulled down some data to work with. It would seem a fairly simple thing to do (memory and number of cpus allocated can be easily changed as long as the image is not currently running) but alas it would appear that you are stuck with what you originally budgeted for … if you are stuck in the GUI anyways.
The solution, as always involved a bit of command line magic. I store my images under /var/vm and the magic command was actually quite straight forward:
vmware-vdiskmanager -x 20GB /var/vm/WinXP/Windows\ XP\ Professional.vmdk
and voila after I’d restarted the vmware server console and rebooted the image there was 20Gb of space available!!! But wait…. the windows drive is only using 10Gb of it, how to get it using the whole thing. In the end our sysadmin came over with an Acronis Imager boot disk and we booted the image and quickly pulled up the boot ordering menu, selected “boot from cd” and then used the Acronis application for resizing a partition to use unallocated space. Reboot once more and then we were finally done!!
I’ve been using vi a lot lately and was bummed to have forgotten a very nice piece of .vimrc magic I used to have to autoindent an entire file at once. The way it works is you stick the following in your ~/.vimrc and then in any file you can just press — and it will properly indent the entire file, I finally tracked it down and am putting it here as a central location to come back to later.
" Stolen from some guy named ben
benoit.cerrina@writeme.com
fun BenIndent()
let oldLine=line('.')
normal(gg=G)
execute ':' . oldLine
endfun
map -- :call BenIndent()
I’m also going to put the rest of my vimrc up here just for completeness.
" .vimrc
"
" Copied from Smylers's .vimrc
" http://www.stripey.com/vim/
"
" use indents of 2 spaces, and have them copied down lines:
set shiftwidth=2
set shiftround
set expandtab
set autoindent
set smarttab
set bs=indent,eol,start " allow backspacing over everything in insert mode
" for C-like programming, have automatic indentation:
autocmd FileType c,cpp,slang set cindent
" show the `best match so far' as search strings are typed:
set incsearch
" Makefile sanity
autocmd BufEnter ?akefile* set noet ts=8 sw=8
autocmd BufEnter */debian/rules set noet ts=8 sw=8
" Map f11 to toggle background
map :let &background = ( &background == "dark"? "light" : "dark" )
" Map f5 to toggle search highlighting
map :set hls!set hls?
" Change the colorscheme
" colorscheme murphy
colorscheme elflord
" Stolen from some guy named ben
benoit.cerrina@writeme.com
fun BenIndent()
let oldLine=line('.')
normal(gg=G)
execute ':' . oldLine
endfun
map -- :call BenIndent()