rss
twitter
  •  

Using libvirt with Xen on Debian Lenny

| Posted in Personal |

4

So it seems that my CentOS 5 Dom0 wasn’t stable. When building new virtual machines, the machine would hang and I’ve have to go back into the machine room to reboot it.

I have suspicions that it was due to the 3ware 8006 RAID controller, but instead of messing around with that, I’ve installed Debian Lenny as the Dom0 (using kernel 2.6.26 as opposed to kernel 2.6.18 with CentOS).

With this machine, I wanted to find the best way to support both Debian and CentOS machine, using a common method of installation. There seem to be two main ways to accomplish this.

You could use the (older) Debian route and use xen-create-image from xen-tools, which does a bootstrap of the OS on the filesystem, or use the newer virt-install from libvirt, to do an actual OS install. Libvirt seems like it’s the preferred method these days, which many of the distro’s now using for managing virtual machines using Xen, KVM or QEMU.

Using xen-create-image for Debian virtual machines has worked for me for a long time, but trying to use it for CentOS failed. The machine built, but I believe there were some packages missing from the install. I really didn’t want to have to mess around with the package lists, so I tried to use both xen-create-image for Debian and virt-install for CentOS. One problem with this is that virt-install doesn’t install the Xen config files into /etc/xen like the other tools do. Instead, it manages its own list, and contacts Xen directly using a Unix socket.

This would make management a pain, because you would have to use xm create <domain>to start a Debian VM, but then use virsh start <domain> for CentOS. I needed something simpler.

Then I discovered that Debian Lenny now has para-virtualisation support built into the Debian Installer.

This means that I could use virt-install to build Debian Lenny virtual machines, using the actual Debian installer.

With a quick install of the libvirt packages in the Debian Lenny’s repository:

apt-get install libvirt-bin virtinst

You’ve got all the libvirt stuff you need. Then, to create a Debian virtual machine using virt-install:

virt-install \
--name=debian-test \
--ram=512 \
--file-size=8 \
--nographics \
--paravirt \
--file=/var/lib/xen/images/debian-test.img \
--location=http://mirrors.uwa.edu.au/debian/dists/lenny/main/installer-i386

The important part is that last line. You can actually just throw a path to the install images of a Debian mirror, and virt-install is smart enough to boot a new VM from that. This then begins a Debian install, identical to what you would use on a standard machine. This also gives you full access to use the nice virt-manager. You can install virt-manager by doing:

apt-get install virt-manager

virt-manager

virt-manager running on a Debian Lenny Dom0

So I just need to remember now that if I want to start a VM, I need to use virsh start <domain>

Although, once started, you can use the standard xm tools.

So finally, I have reached open-source para-virtualisation nirvana. Now if only Debian did Kickstart…

ABC iView on XBMC/Boxee

| Posted in Geek |

12

A plugin for ABC iView on XBMC has been released. See this page for progress of ABC iView on XBMC.

I think it would be really neat to use ABC’s iView on the Xbox Media Centre (XBMC) and/or Boxee. Honestly, who really wants to watch TV on their computers? Haven’t we evolved from that now?

I’ve got a modded XBOX running XBMC, and I have various Linux boxes running XBMC and Boxee and I think they’re the perfect platform for something like iView.. especially because it’s unmetered traffic on iiNet, Internode and other great ISP’s.

I did a little research, and they seem to use Adobe’s Real Time Message Protocol (RTMP) to stream the video from their server to the iView client, which is written in Flash. Recent versions of XBMC and Boxee have code to support RTMP, which is also used by other digital content providers like NBC’s Hulu, and the BBC’s iPlayer.

I have managed to work out most of the iView’s XML stuff, which describes channels, programs, thumbnails, etc but not quite got there with the actual streaming part. I’m playing with rtmpdump, which is based on the rtmp code from XBMC/Boxee, and have almost worked out the URL part to get the server to stream. I just keep getting a message about not being able to find the specified stream.

If anyone out there on the interwhizzle has worked this stuff out, I’d love to hear from them. My googling hasn’t really revealed anything like what I’m after. If you’re interested in using iView on XBMC or Boxee, I’d like to hear from you also.

UPDATE: Please vote for an iView plugin for Boxee at the Customer Support Community for boxee. It might might help get iView into Boxee!

UPDATE 2: I’ve uploaded a basic plugin for XBMC. See: http://www.andybotting.com/wordpress/iview-for-xbmc-plugin-v02 for more info.

Running a Debian Lenny DomU under a CentOS 5 Dom0

| Posted in Geek, Work |

2

The aim of this was to use the standard CentOS/RHEL Xen Dom0 tools to boot a Debian Lenny DomU.

I found plenty of instructions for doing CentOS DomU under a Debian Dom0, but not the other way around. So, this is a little how-to documenting the little things that need to be overcome.

I also wanted the Debian virtual machines to have their filesystems in a file, in the same standard way that the RHEL virt-install creates.

Steps involved:

  • Use virt-install to build a standard CentOS virtual machine
  • Use debootstrap to build a Debian Lenny base install for transplanting
  • Break apart a CentOS filesystem-in-a-file, and move the Debian install into it
  • Modify Debian config for booting the CentOS kernel

Use virt-install to build a standard CentOS virtual machine

I created a new virtual machine, using virt-install.

virt-install -n newvm -r 512 -f /var/lib/xen/images/debian.img -s 8 -l http://ftp.monash.edu.au/pub/linux/CentOS/5/os/i386/ -p --nographics -x

I needed some CentOS virtual machines anyway, so I let the install go through and do its thing. If you didn’t need it, you could probably kill the install before it started installing packages. We just needed the config file for the VM in /etc/xen and the filesystem image.

Use debootstrap to build a Debian Lenny base install for transplanting

I actually had a Debian Xen Dom0 with the xen-tools package installed. I used this to create a new Debian Lenny install, and also do some of the nice hook scripts with you would otherwise have to do by hand.

# xen-create-image --hostname=vanila --size=8Gb --dist=lenny --memory=512M --ide --dhcp

This meant I had a hostname file, libc6-xen and other things already done for me.

This was installed into an LVM partition, so after building it, I mounted the LVM partition, and used tar to compress it.

# mount /dev/mapper/vg-vanilla--disk /mnt
# tar zc -C /mnt/ . > /tmp/vanilla-debian.tar.gz

Break apart a CentOS filesystem-in-a-file, and move the Debian install into it

Set up the loop device
# losetup -f /var/lib/xen/images/debian.img

Map the partitions inside the loop device
# kpartx -av  /dev/loop0
add map loop0p1 : 0 208782 linear /dev/loop0 63
add map loop0p2 : 0 16032870 linear /dev/loop0 208845

At this point, you should have /dev/mapper/loop0p1 which is the root filesystem of your new VM. You’ll need to format the filesystem with:
# mkfs.ext3 /dev/mapper/loop0p1

Mount the newly formatted filesystem
# mount /dev/mapper/loop0p1 /mnt

Extract our Debian Lenny install into the filesystem
# cd /mnt
# tar xf /tmp/vanilla-debian.tar.gz

Modify Debian config for booting the CentOS kernel

We want to use CentOS/RHEL’s pygrub bootloader, just because it’s nice.

First, you’ll need to copy the CentOS kernel into your Debian install. You’ll need the config, kernel and initrd files from /boot of a DomU (or maybe the Dom0..)
# cd /boot
# cp config-2.6.18-92.1.22.el5xen vmlinuz-2.6.18-92.1.22.el5xen initrd-2.6.18-92.1.22.el5xen.img /mnt/boot

Rename the initrd to drop the .img from the end. It doesn’t work with the update-grub script in Debian
# mv initrd-2.6.18-92.1.22.el5xen.img initrd-2.6.18-92.1.22.el5xen

Copy the kernel modules to your new VM too:
# cp -r /lib/modules/2.6.18-92.1.22.el5xen /mnt/lib/modules

If you don’t have a /boot/grub directory in your Debian DomU, then you’ll need create one. You only really need three files: menu.lst and device.map. We’ll need to set it up properly so that both the update-grub script in Debian and the pyGrub bootloader work happily.

Edit the /boot/grub/device.map file. Make sure your hd0 is set to /dev/xvda:
(hd0)   /dev/xvda

The pyGrub script reads grub.conf, and not menu.lst, so symlink it
cd /boot; ln -s menu.lst grub.conf

Here’s the contents of my /boot after I’m finished:
/boot/config-2.6.18-92.1.22.el5xen
/boot/initrd-2.6.18-92.1.22.el5xen
/boot/vmlinuz-2.6.18-92.1.22.el5xen
/boot/grub
/boot/grub/default
/boot/grub/menu.lst
/boot/grub/device.map
/boot/grub/grub.conf

You’ll need to fix your inittab to use the xvc0 as your console. If you don’t you lose access to log into the console. In the file /etc/inittab, edit the tty1 line to be xvc0 instead.
1:2345:respawn:/sbin/getty 38400 xvc0

Your first tty should be changed to xvc0, and the others (tty2-6) should be commented out (if they’re not already)

Unmap the partitions and destroy our loop device
# kpartx -d /dev/loop0
# losetup -d /dev/loop0

Start the new Debian Lenny virtual machine

# xm create -c debian

You should see PyGrub come up, and let you pick the kernel.
pyGRUB version 0.6
==========================================================================
| Debian GNU/Linux, kernel 2.6.18-92.1.22.el5xen                         |
| Debian GNU/Linux, kernel 2.6.18-92.1.22.el5xen (single-user mode)      |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
==========================================================================
Use the ^ and v keys to select which entry is highlighted.
Press enter to boot the selected OS. 'e' to edit the
commands before booting, 'a' to modify the kernel arguments
before booting, or 'c' for a command line.

Will boot selected entry in  4 seconds

Hopefully, it works for you too :)

I’ve made one vanilla debian install, and just make a copy of that image file for each new VM I need to create. I have eth0 in the interfaces file commented out, so I just put the new IP in, set the hostname and I’m ready to go.

I may have missed a step in here, so if you’re trying this out, please comment to let us know how it goes.

Thailand Trip (part 4)

| Posted in Personal |

3

Once we realised how much Stable lodge was really costing us, we upgraded our accommodation for the four nights we had in Bangkok. We booked a serviced apartment at Citiadines in Sukhumvit 8, just down the road from Stable Lodge.


Messy bed at Citadines

We booked it on Wotif and it cost us a little bit more than what Stable Lodge was. It was totally worth it for the comfortable bed alone, especially after sleeping on really hard and really soft beds at the other places.


Nice TV at Citadines

Somehow we ended up wth four nights in Bangkok with was way too much. If you’re going to Thailand, only spend a few days in Bangers at a maximum. It’s just not that exciting. It’s too similar to Melbourne really. Trains, shopping centers, etc.

We checked out the massive MBK shopping center and the King Power duty free place too. If you see King Power anywhere.. avoid it. Don’t waste your time, it’s fancy stuff that is way overpriced.

The last night in Bangkok, we found out about the semi-permanent beer gardens that get set up outside the CentralWorld shopping center. The beer garden for the Thai beer Singha, must have had some association with the Japanese beer Asahi, which just happens to be my favourite beer. So, you can imagine my excitement to find out they were serving it there.


The Asahi tower

Bek and I polished off a tower of Asahi. The tower is a 3 litre tube full of beer with a column of ice down the middle to keep it cold and a tap on the bottom to pour. It was awesome. I thought about how good it would be to do a similar thing in Melbourne, but I realised that it just wouldn’t work because it would get abused. People would be getting smashed and then smashing each other (like going to any pub in the city these days). The Thai people don’t drink that much and are very passive. It’s nice to walk around at any time and feel totally safe.


All gone

We had trouble getting a taxi to the airport when it was time to leave. The guy at the hotel mentioned something about a bomb, but we didn’t know anything else. Finally a taxi arrived who was willing to take us. This guy was crazy. He had this strange twitch in his seat while he was driving. He was doing 130 km/h down the freeway, which had 80 signs. Weaving through traffic and flashing his lights at anyone slowing him down. We also didn’t have any seat belts.

Closer to the airport, we started seeing lots of people in yellow shirts with plastic hand clappers. I had no idea who they were until later. They were protesters heading towards the airport to shut it down.


Protester convoy

We managed to get most of the way to the airport before traffic stopped moving. Bek and I had to put our backpacks on and walk the last km to the terminal. It was pretty exciting actually. We were so lucky to get our fight, because not long after, the protesters stormed the terminal and all flights got shut down. It must have been only an hour or two after we left.

Their aim was to stop their prime minister from getting into the country, from Peru where the APEC summit was held. It seems they don’t like him very much… and it’s a long story.

A nine hour flight and we touched down in Melbourne. First stop, the Classic Curry Company :)

All the photos have been uploaded to my Google Picasa account.

Thailand Trip (part 3)

| Posted in Personal |

1

We were planning on catching the overnight train from Bangkok to Chiang Mai, but at the train station, they said they didn’t have any first class tickets available, so we flew instead. This meant waiting at the airport in Bangkok for a few hours, but it meant we got to Chiang Mai much sooner.

Bek had found a rave review of a boutique hotel from The Age which sounded pretty good. The place was called Banilah and it’s in the north-west part of the city.


Bek standing outside Banilah

This worked out well, because most of the westerners stayed on the east side of the city, so I think we got more of a feel for what Chiang Mai is really about. The young ladies who run the hotel were awesome. They gave us a map when we got there and hilighted lots of things on it we should look at. I also asked them about a good restaurant to eat at for Thai food. If you’re in Chiang Mai, you have to eat at Cafe de Nimman. It was awesome.

We did lots of walking around in Chiang Mai. Bek had an upset stomach, so we had to tone it down a little, but we managed to see lots of the city.


The Tanin fresh food market

The funny thing about the people in Thailand is that they don’t walk anywhere. We occasionally found it difficult to get around because there were so many motorbikes zooming around and the lack of footpaths. Shop owners often put their wares right to the road side, so it doesn’t leave much room for walking. Also, to add to this, stopping for red lights at pedestrian crossings seems to be optional. It does make life interesting.


Busy Chiang Mai road

If you go to Chiang Mai and you want to get around, here’s a tip. Some blue tuk-tuks have an affiliation with the TAT and will drive you for an hour for 30 baht. I think they may operate during the day only, but I’m not sure. You always ask before you get in anyway.


Look out for the blue tuk-tuk’s

Crusing around in a tuk-tuk is a lot of fun. I could have just paid a guy 200 baht to just drive me around all day.


Riding around in a tuk-tuk

After five nights, we got ourselves a tuk-tuk to the airport to fly to Bangkok again for the final part of our trip.

Thailand Trip (part 2)

| Posted in Personal, Uncategorized |

0

Got a taxi from Stable Lodge to Bangkok airport early in the morning to fly to Surat Thani. Surat Thani airport reminds me a lot of Avalon Airport. Pretty small and smells funny. Once we grabbed our bags, there was a guy selling tickets to Ko Samui. Perfect.


Air Asia plane at Surat Thani

We jumped on the bus and it took us to the Sea Trans ferry at Don Sak. We got off the bus and onto the ferry for about and hour and a half. Once we arrived at Na Thon port at Ko Samui, we got our bags off the bus and got a mini bus to the bungalow, except the guy must have mistaken me, and dropped us off at the Beach House, not Beer’s House. Simple mistake. Once we worked out where we were, we jumped on a ute with a roof, which finally got us to Beer’s house.

Beer’s house was awesome. We had a bungalow right on the beach. For the few days we were staying in Ko Samui, the weather held out. Just before and just after, Ko Samui had rain and thunderstorms, so we were pretty lucky.

Beer's House Beach-front bungalow
Beer’s House Beach-front bungalow

Ko Samui is an interesting place. Like the rest of Thailand, the roads are full of motorbikes, doing crazy stuff. We did lots of walking around, but mainly around the Lamai beach area which is on the west side of the island. The way the trip worked out, we only stayed there a few days. I could have easily spent much more time there.

Sunday morning we left early to make our way up to Chiang Mai. We organised our trip to the Surat Thani airport with a travel agency, which might have cost us a little more, but it did make it easy. Although Bek and I had this feeling that something would go wrong and we’d miss our flight, it seemed to work out fine in the end.

A mini-bus picked us up at 6:30am from Beer’s House and took us to Na Thon port.
We were told to get on a bus at Na Thon port, which was crammed full. People were standing in the aisle. Nobody had any idea what was going on, we just were fed small bits of english which gave us an uncomfortable feeling.

We took the bus 15 minutes to the Raja Ferry pier. Bek had read lots of bad things about the Raja ferry, so when she saw the sign, she began to get really nervous. Not to mention she also gets sea sick. She’d heard stories about the ferries running aground and other dodgy acts.


Boarding the Raja ferry

We were told to get off the bus, and get onto the ferry. We were also told to leave our bags on there, which made us a little nervous. The ferry ride was fine, so that was a relief. We got back on the bus at Don Sak and travelled about an hour to the town of Surat Thani.

In the middle of nowhere, we had to get off the bus and get into a different one. We when traveled a bit further and had to get out again. This time it was a little shed, which was some sort of bus terminal. We got in a mini-van with a few other people from there on our way to Surat Thani airport.

Meanwhile, I had brought my Nokia Internet Tablet with me and my external GPS. I had pre-downloaded all the Google Maps tiles so I could track where we were going. It was really handy, because we got lost a couple of times. I was following where the guy was taking us for a while, and he was going in a totally different direction to the airport. I was getting a bit nervous, but he eventually turned the van around. He was taking a short-cut :)

One interesting moment was when we were overtaking a truck. We weren’t going that fast and there was a car coming towards us in the other direction but it seems there was time for another car to overtake us at the same time. Thailand drivers are nuts.

We checked in to our Air Asia flight with plenty of time. We flew from Surat Thani to Bangkok airport but had to wait 5 and a half hours to then board another Air Asia flight to Chiang Mai.

Back from Thailand.. only a few dramas

| Posted in Personal |

1

As you may have heard, protests have been going on in Bangkok recently. It seems to be about the Thai people wanting their prime minister to resign.

We finally got a taxi from our hotel to the airport, after many taxi’s refused to take us. The guy who did end up taking us was a bit crazy, and he was going 130 km/h down the 80 km/h freeway and our seatbelts didn’t work.

Protesters were stopping traffic a few kilometers from the airport. Traffic was crawling from there towards the airport, with people wearing yellow shirts yelling a going crazy.

We managed to almost make it all the way to the airport, but we had to get our and walk the last bit, which wasn’t too bad. News says that the airport was closed shortly after, so we were probably lucky.

The Age has an article: Protesters storm Bangkok airport which might give some insight about what is going on in Bangkok right now.

I’ve got more to write about our holiday, but that might have to come tomorrow.

Thailand trip (part one)

| Posted in Personal |

1

Bek and I managed to score some really cheap JetStar flights to Bangkok six months ago in a 2 for 1 deal. In the end we paid about $400 each for our return tickets, so we’ve had six months to look forward to this trip.

The flight was about normal. It started with JetStar being late to open bag check-in and delays before boarding the flight. During the flight we had the token screaming baby and annoying Americans behind us, not to mention, the in-flight entertainment system was broken. I think this is probably deliberate, to get more people to hire their Video-on-demand systems which cost extra. I came fully prepared with an iPod loaded with new movies which helped a little with the 9 hour flight.

The first thing you notice in Thailand is the humidity as soon as you get out of the airport. It wasn’t overpowering, probably because it was 8pm and a coolish day, by Bangkok’s standards. Bek had done her research, and knew exactly what we needed to do once we got off the plane. We had to find the proper airport taxi queue to avoid being taken for a ride (bad pun alert!). The freeways are pretty smooth and the tollways quick. Lanes and indicators are optional, as well as doing the speed limit. Makes for good fun.

We got the taxi to our hotel, just off Sukhumvit Rd, which was about 30 minutes in the taxi from the airport. The streets that run off Sukhumvit Rd are called Soi’s. We’re staying on Soi 8. It looks more like a laneway than a street, and there is plenty going on, all the time. We’ve actually got two 7-eleven’s on ours, which has been handy changing our large 1000 THB notes to something more manageable.


Sukhumvit Road, Soi 8

We’re staying at Stable Lodge. It has free wifi (which lots of places have here) which is nice. It’s meant that we could book our flights and do some research without having to leave the place. I also put in a call home to let the parentals know we’re still alive. The Eee PC is awesome btw.


Stable Lodge restaurant and pool area

We caught the Skytrain today into the city and exchanged some money and had a walk around the big shopping centers. MBK is the largest. It’s massive. It’s a shame that the prices are too similar to what we’re used to in Australian dollars, but that’s probably more just because I’ve been looking at the gadgets.

The tuk-tuk drivers are seriously pissing me off though. Everywhere you go, there they are waiting to harass you to make you go for a ride with them. They’d probably just take you to their mates jewelery shop. We also had a few incidents at the train station. The ‘official’ information people aren’t official. Even with their fake ID badges.


Busy Bangkok motorway

We bought a couple of long-necks of Chang beer from 7-eleven, which were a bargain at 35 THB and we’re having an early night. It’s up early tomorrow morning to catch our flight to Surat Thani. We go by ferry from there to our next destination.. Beer’s house at Ko Samui. It’s going to be rad.. as long as the weather stays ok.


Bangkok skyline, from our balcony

How do you clone an LVM partition?

| Posted in Linux |

6

It’s actually more difficult than you might think. From the bit of googling that I did, it seems that you can’t just ‘clone’ and LVM logical volume, while it’s running.

One method I found was to use the ‘snapshot’ feature of LVM to create a ‘frozen image’ copy of the logical volume, which is then suitable for copying to a new logical volume, while leaving the original intact.

Here’s our original logical volume that we want to clone.

# lvdisplay
 
--- Logical volume ---
LV Name                /dev/vg/host-disk
VG Name                vg
LV UUID                UK1rjH-LS3l-f7aO-240S-EwGw-0Uws-5ldhlW
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                9.30 GB
Current LE             2382
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           254:0

Let’s now create our snapshot logical volume. For the size, it should only need 10 – 20% of the original size, as we’re only mirroring the real volume.

# lvcreate --size 2G --snapshot --name host-disk-snap /dev/vg/host-disk

Let’s take a look at our new volume

# lvdisplay
 
--- Logical volume ---
LV Name                /dev/vg/host-disk
VG Name                vg
LV UUID                UK1rjH-LS3l-f7aO-240S-EwGw-0Uws-5ldhlW
LV Write Access        read/write
LV snapshot status     source of /dev/vg/host-disk-snap [active]
LV Status              available
# open                 1
LV Size                9.30 GB
Current LE             2382
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           254:0
 
--- Logical volume ---
LV Name                /dev/vg/host-disk-snap
VG Name                server1
LV UUID                9zR5X5-OhM5-xUI0-OolP-vLjG-pexO-nk36oz
LV Write Access        read/write
LV snapshot status     active destination for /dev/vg/host-disk
LV Status              available
# open                 1
LV Size                9.30 GB
Current LE             2382
COW-table size         10.00 GB
COW-table LE           2560
Allocated to snapshot  0.01%
Snapshot chunk size    8.00 KB
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           254:5

From the output, you should be able to see that we’ve now got some snapshot fields shown in our output. We’ll create another logical volume, which will be our final target for our new virtual machine.

# lvcreate --size 10G --name newhost-disk vg

With our source and target partitions ready to go, we need to begin copying the data. You have some choices here, depending on your setup.

If you’re using the same size partitions you could use dd, or even xfs_copy if you’re using XFS.

If you’re like me, I wanted the new target partition to be a smaller size than the original. Also, if you wanted to use a different filesystem, the only real way to do it is to copy the files.

We’ll need to make the new filesystem on our target partiton

# mkfs.xfs /dev/vg/newhost-disk

and mount our filesystems

# mkdir /mnt/host-disk-snap
# mount -o ro /dev/vg/host-disk-snap /mnt/host-disk-snap
 
# mkdir /mnt/newhost-disk
# mount /dev/vg/newhost-disk /mnt/newhost-disk

I wasn’t sure about how changes to the filesystem would affect the original, so I thought I’d stick to the safe side, and mount it as read-only.

Change into the source filesystem

# cd /mnt/host-disk-snap

Using a mix of find and cpio, copy the files

# find . -mount -print | cpio -pdm /mnt/newhost-disk

Wait a few minutes, depending on your filesystem size, and you’re done.

When you’re satisfied, you can just use lvremove to remove your snapshot volume.

# umount /mnt/host-disk-snap
# lvremove /dev/vg/host-disk-snap

After all that, you should finally have a cloned filesystem to use. I’m sure there’s an easier way, but this worked for me.

OpenWRT on the D-Link DSL-502T (Gen 1)

| Posted in Personal |

18

NOTE: Much of this isn’t necessary now, because OpenWRT 8.09 now supports AR7. You can just grab the openwrt-ar7-squashfs.bin image to use from http://downloads.openwrt.org/kamikaze/8.09.1/ar7/


I’ve had this old D-Link DSL-502T sitting around, basically working. When I moved place just recently, I took the opportunity to look into getting OpenWRT installed on this thing, basically because I wanted something I could do DNS/DHCP serving on, while giving me some shell access. The D-Link firmware is kinda dodgy, and I always enjoy installing Linux onto something new.

Chris Pascoe’s page is quite dated now, but was a good place to start. Much development has gone into OpenWRT and the AR7 platform, so much of his information is now incorrect. The best place for info is the OpenWRT wiki page for the DSL-502T. It’s much more comprehensive and many of the patches and hacks that Chris Pascoe needed to do have be rolled into the OpenWRT trunk.

Much of this information has been copied and pasted from the above sites. Credits to both of them.

Start by grabbing the SVN trunk of OpenWRT.

$ svn co https://svn.openwrt.org/openwrt/trunk

Once this is done, you can grab any packages you’re interested in. Note that you can install these later using the opkg command once your firmware is running. I grabbed ntpclient, tcpdump, openvpn and the ddns-scripts.

cd openwrt/trunk/package
svn co https://svn.openwrt.org/openwrt/packages/net/ntpclient
svn co https://svn.openwrt.org/openwrt/packages/net/tcpdump
svn co https://svn.openwrt.org/openwrt/packages/libs/lzo
svn co https://svn.openwrt.org/openwrt/packages/net/openvpn
svn co https://svn.openwrt.org/openwrt/packages/net/ddns-scripts

Select firmware components
Enter into the folder and run make menuconfig. Select at least:

  • Target System -> TI AR7 [2.6]
  • Target Profile -> No Wifi
  • Target Images -> SquashFS
  • Image configuration -> LAN IP Address (not required, but makes it easier if you’re already running a network)
  • Base system -> br2684ctl (only needed by PPPoE)
  • Network -> ppp -> ppp-mod-pppoa and/or ppp-mod-pppoe, depending on your ADSL type
  • Kernel Modules -> Network Devices -> select Annex A (which is ADSL over POTS. B is for ADSL over ISDN)

Make sure that you enable your packages from above in the config. E.g. Network -> Time Synchronization -> ntpclient

Quit and save the config.

Get the build dependencies.

For Ubuntu, you’ll need:
sudo apt-get install flex bison autoconf zlib1g-dev libncurses5-dev automake g++ patch gawk

Build your image by doing
make -j3 (for a dual-core system)

The final firmware produced by the build is located in bin/openwrt-ar7-squashfs.bin.

Uploading the initial OpenWRT firmware.

To upload the initial OpenWRT image, there is a tool called adam2flash. It can be found in the OpenWRT trunk, under the scripts directory. To use it, you need to execute the script in the first second or so of the machine being turned on. It’s recommended that you don’t connect the modem directly to your computer, but use a switch in between. This is in case it takes too long for the ethernet cards to negotiate.

One thing I had trouble with was finding out what the initial IP address of the device was. Before you overwrite your firmware, you can find this out by using telnet. Enable the telnet remote management from the D-Link interface and then check out the ADAM2 environment variables. They should be stored in /proc/ticfg (from memory).

If you’re lucky, you might see an entry starting with my_ipaddress. Mine was 10.1.1.199, but many others have mentioned 192.168.1.1. On my DSL-502T (Gen II), it haven’t found it’s IP yet. It wasn’t set in the file.

Lots more info about the ADAM2 bootloader can be found at the Seattle Wireless site. http://www.seattlewireless.net/ADAM2

Here’s the steps:

  • Download a copy of the standard D-Link firmware so you can revert to it if things go wrong! You need the “web upgrade” .BIN version of the firmware, not the .EXE version. D-Link firmware can be downloaded from (for example) http://www.dlink.com.au/tech/
  • Configure your PC for a static IP address on the same subnet as your modem’s default IP address.
  • Choose an IP address for your modem. The OpenWrt firmware will use 192.168.1.1 after rebooting (unless you set it in the menuconfig), so that’s a sensible choice.
  • Turn off the modem.
  • Run adam2flash-502T.pl, providing the modem IP address you chose and the new firmware to upload. If you are changing between D-Link and OpenWrt firmware, you will also need to specify -setmtd1 (if you forget this, the script will tell you that you need it and exit)
  • Turn on the modem.
  • Wait for the upload to complete. Here’s a sample session:

$ scripts/adam2flash-502T.pl 192.168.1.1 -setmtd1 bin/openwrt-ar7-squashfs.bin
Looking for device: ..... found!
ADAM2 version 0.22.2 at 192.168.1.1 (192.168.1.1)
Firmware type: OpenWRT (little-endian)
logging into ADAM2 bootloader.. ok.
checking hardware.. AR7RD / DSL-502T.
checking MTD settings.. ok.
Firmware size: 0x00280004
Available flash space: 0x003e0000
Preparing to flash.. ok.
Erasing flash and establishing data connection (this may take a while): ok.
Writing firmware: ............. lots of dots ......... done.
Rebooting device.

If you have trouble with this (as I did) you might need to hack the adam2flash-502T script a little. I commented out the whole section about doing the UDP probe part, and just passed the IP address right into the $box variable.

Getting the LEDs to work
Grab a copy of the ledsetup script found in the scripts directory of your SVN checkout. Install it into /etc/init.d and it should run on start-up. This will give you the ethernet light, and also map the USB light to ppp0. Very handy.

DSL Sync
When I finally got my ADSL connected in the new place, I couldn’t get DSL sync. It seemed to be because I had the wrong modulation set.

When you boot the device, you should see something like this in your dmesg.

Registered device TI Avalanche SAR
Sangam detected
requesting firmware image "ar0700xx.bin"
avsar firmware released
tn7dsl_set_modulation : Setting mode to 0xffff
Creating new root folder avalanche in the proc for the driver stats
Texas Instruments ATM driver: version:[7.03.01.00]
DSL in Sync

The line about setting the mode to 0xffff is important. For me, my initial mode was being set to 0x7f (which wasn’t for ADSL2+). The 0xffff mode means to negotiate the best speed (ADSL 1 or 2, 2+). This is set in the ADAM2 environment so if this needs to be changed, you’ll have to reboot your modem and use the onboard FTP server’s commands SETENV, UNSETENV, GETENV (all caps matter), by doing telnet to your modem’s default IP address on port 21.

$ telnet 10.1.1.199 21
220 ADAM2 FTP Server ready.
530 Please login with USER and PASS.
USER adam2
331 Password required for adam2.
PASS adam2
230 User adam2 successfully logged in.
GETENV my_ipaddress
200 GETENV command successful
my_ipaddress 10.1.1.199
GETENV modulation
200 GETENV command successful
modulation 127
SETENV modulation,65535
200 SETENV command successful

You can also set/reset your modem’s default IP address here with the variable my_ipaddress.

Backing up and restoring your configuration changes
OpenWRT saves your filesystem (effectively, configuration) changes in a JFFS filesystem mounted at /jffs. As this filesystem is dynamically sized based upon the size of your kernel and SquashFS, uploading a new firmware image may cause your configuration to be lost.

You can back your changes up to a file on your local machine via ssh:
ssh root@172.18.0.1 tar cf - /etc/ > dsl502t-backup.tar

To restore a saved configuration, we reverse the direction of the transfer. The following command checks the configuration copied properly before deleting the old configuration:
ssh root@172.18.0.1 'cat > /tmp/.r.$$ && tar tf /tmp/.r.$$ && cd / && rm -rf etc/* && tar xf /tmp/.r.$$' < dsl502t-backup.tar

Updating your OpenWRT install
SCP over the new image
desktop# scp bin/openwrt-ar7-squashfs.bin root@172.18.0.1:/tmp/newimg

Log into the OpenWRT device, and use the mtd command to write the new image:
openwrt# mtd -r write /tmp/newimg linux

This should then go through a write/verify process, and once completed it will reboot into the new image.