Welcome! Log In Create A New Profile

Advanced

GoFlex Net + UBIT v0.6 + SATA kernel + Debian Squeeze + hacked Debian initrd

Posted by Vlad 
GoFlex Net + UBIT v0.6 + SATA kernel + Debian Squeeze + hacked Debian initrd
June 12, 2011 12:30PM
I ACCEPT ABSOLUTELY NO RESPONSIBILITY FOR ANY KIND OF DAMAGES THAT MAY OCCUR FROM FOLLOWING STEPS DESCRIBED HERE. YOU'RE DOING THIS AT YOUR OWN RISK

In this posting I'd like to describe my attempts to get the most out of my GoFlex Net, which means UBIT v0.6, SATA kernel and Debian. This is definitely not a Howto where you paste some stuff in your terminal and get a working system. In fact, if you try to do this that way, you'll probably brick your GoFlex. However, if you are more or less experienced Linux user, my experience might help you to get things working. This is also a kind of note to myself, because I have a very bad memory and would probably forget what I actually did in a few months.

Overview

As soon as I got my GoFlex, I, like probably most people in this forum, used Jeff's method to install Debian. Very soon, however, I noticed that the kernel was not able to recognize the SATA ports which kind of made the GoFlex pretty useless for me. I eventually succeeded in replacing the kernel by a newer version with SATA support but soon it turned out to be a rather dissatisfactory solution. The problem is that as long as you use u-boot from Jeff's install script, you can use only one SATA port. There are other limitations too, like very poor recovery options. The obvious solution was to replace u-boot by UBIT, which is a forked and improved version of the former. Although information about how to do it was quite scarce and outdated, I somehow managed to do this too. From this point on, the real troubles began.

As you probably know, to boot a Linux you basically need a bootloader, a kernel, a ramdisk (initrd) and a rootfs. One of the main tasks of the ramdisk is to mount the rootfs and execute the init process on it. For some reason, in my case the ramdisk which comes with UBIT v0.6 always failed to find the rootfs so that the GoFlex booted into initramfs. People who faced this problem too, suggested to simply delete the ramdisk which is by the way called uInitrd. I did this and my GoFlex finally booted just fine. But as soon as I tried to connect a HDD, I suddenly faced spontaneous freezes during the boot process which I simpy couldn't understand. The problem was that by deleting the ramdisk, I made the kernel rely only on the boot parameters it gets from the UBIT. Thus, if UBIT is told to search for a bootable usb flash, it will become sda. But when the kernel is booting, it usually initializes the HDD first, so that the HDD become sda and the USB sdb. Since the kernel was told to mount a rootfs on sda1, it will of course fail, since the sda1 partition of the HDD doesn't contain the rootfs. That was the reason for the freezes. My solution was to use Debian's ramdisk and hardcode the label of the rootfs partition which I chose to be "rootfs". Thus, the ramdisk will look for a partition labeled "rootfs" and will mount it as a rootfs. And since the only partition with this label is the first partition of the USB flash drive, the system always boots just fine.

That might not sound particularly difficult to you, but in fact, I had even more problems to overcome, since I by accident deleted my Debian partition on the USB drive. The only thing I had was a GoFlex with working UBIT, but with the aid of the perfect recovery abilities of the UBIT bootloader, I also found a way to get everything back. First, I divided my flash drive in two ext2 partitions putting /boot/uImage and /uInitrd on the first partition. This way I was able to boot into initramfs. From there I installed PlugBox on the first partition, deleted /uInitrd on that partition and rebooted. After that, GoFlex booted into PlugBox and I was able to install Debian on the second partition using a modified version of shyd's script. Finally, I tared both partitions and repartitioned my USB flash once again, this time dividing it into a large ext3 partition and a swap partition. The ext3 partition was labeled "rootfs" for the reasons I described above. Subsequently, I untared the Debian rootfs on that ext3 partition, added a new SATA kernel and a modified ramdisk and everything worked like it should.

UBIT v0.6 over Jeff's u-boot

This is actually the most difficult and dangerous thing, as the ubit_start often stops working in the middle of the execution. I was able to achieve some degree of success by doing the following (from Debian).
mkdir -p /media/flash mount -t jffs2 /dev/mtdblock2 /media/flash/ 
cd /media/flash/ 
wget http://jeff.doozan.com/debian/goflex/v0.6/uInitrd 
wget http://jeff.doozan.com/debian/goflex/v0.6/ubit_start 
chmod +x ubit_start 
./ubit_start 
uboot_install goflexnet 
chain_install goflexnet 
exit 
umount /media/flash/
The most important thing is actually that "uboot_install goflexnet" and "chain_install goflexnet" don't report any errors, otherwise your bootloader won't work properly which effectively means a bricked device. Another thing is that ubit_start often complain about being unable to delete "/tmp/". This error can apparently be fixed by removing "&> /dev/null" in the definition of the unique_tmpdir () function in the script itself.

The really nasty thing about installing ubit over uboot is that your firmware parameters (fw_printenv, fw_setenv) may get mixed, which also happened to me. It took me some time to realize how the variables are supposed to be definen in UBIT and my current configuration works flawlessly. In my case, my firmware parameters (output of fw_printenv) are the following

addr_kern=0x680000
addr_rd=0x1100000
arcNumber=3089
baudrate=115200
bootcmd=run usb_boot; run fast_boot;  run hd_boot; run ubi_boot
bootdelay=3
boot_kern=run set_bootargs; bootm $addr_kern
boot_rd=run set_bootargs; bootm $addr_kern $addr_rd
chain=nand read.e 0x800000 0x480000 0x80000; go 0x800200
console=ttyS0,115200
ethact=egiga0
ethaddr=AA:BB:CC:DD:EE:FF
ext2_boot=run ext2_rd boot_rd; run boot_kern
ext2_kern=ext2load $boot_dev $addr_kern /boot/uImage
ext2_rd=ext2load $boot_dev $addr_rd /uInitrd
fast_boot=run fast_rd ubi_args ubi_fallback
fast_rd=ubifsmount fast; ubifsload $addr_rd /uInitrd
fat_boot=run fat_rd boot_rd
fat_kern=fatload $boot_dev $addr_kern /boot/uImage
fat_rd=fatload $boot_dev $addr_rd /uInitrd
hd_args_0=boot_dev='ide 0:1'; dev_args='root=/dev/sda1'
hd_args_1=boot_dev='ide 1:1'; dev_args='root=/dev/sdb1'
hd_boot=run ide_start; for scan in 0 1; do run hd_args_$scan ext2_kern ext2_boot; run ext2_rd ubi_fallback; run fat_kern fat_boot; run fat_rd ubi_fallback; done
ide_start=ide reset
ipaddr=10.0.10.6
led_error=orange blinking
led_exit=green off
led_init=green blinking
mtdids=nand0=orion_nand
mtdparts=mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)
ncip=10.10.10.5
ncipk=10.10.10.4
nc_start=setenv stdin nc; setenv stdout nc; setenv stderr nc; version
nc_test=ping $ncip
preboot=run nc_test nc_start
rescue=dev_args='ubi.mtd=root rootfstype=preboot';run silent_hd ubi_fallback; run fast_rd ubi_fallback; run ubi_rd ubi_fallback
serverip=10.10.10.3
set_bootargs=setenv bootargs console=$console $mtdparts $dev_args $rd_args netconsole=@$ipaddr/eth0,@$ncipk/
silent_boot=run silent_rd ubi_args ubi_fallback
silent_rd=ubifsmount silent; ubifsload $addr_rd /uInitrd
ubi_args=dev_args='ubi.mtd=root'
ubi_boot=run ubi_rd ubi_args ubi_fallback
ubi_fallback=run ubi_kern boot_rd
ubi_kern=ubifsmount boot; ubifsload $addr_kern /boot/uImage
ubi_rd=ubifsmount ramdisk; ubifsload $addr_rd /uInitrd
ubi_start=ubi part root
usb_args_0=boot_dev='usb 0:1'; dev_args='root=/dev/sda1 rootdelay=10'
usb_args_1=boot_dev='usb 1:1'; dev_args='root=/dev/sdb1 rootdelay=10'
usb_args_2=boot_dev='usb 2:1'; dev_args='root=/dev/sdc1 rootdelay=10'
usb_args_3=boot_dev='usb 3:1'; dev_args='root=/dev/sdd1 rootdelay=10'
usb_boot=run usb_start; for scan in 0 1 2 3; do run usb_args_$scan ext2_kern ext2_boot; run ext2_rd ubi_fallback; run fat_kern fat_boot; run fat_rd ubi_fallback;done
usb_rootfstype=ext2
usb_start=usb start

Please note that you'll have to replace AA:BB:CC:DD:EE:FF by the MAC adress of your Goflex Net which can be found on the bottom side of the device.

Recovery

Supposing you have a working UBIT v0.6 but nothings else, you can still easily recover your system via netconsole. For that your GoFlex Net must be connected to the router. On your Linux PC, run

ifconfig eth0:0 10.10.10.5 
ifconfig eth0:1 10.10.10.4
ifconfig eth0:2 10.10.10.2
After that open a few terminal windows and run
nc -lu 10.10.10.5 6666
to monitor and control the UBIT and
nc -lu 10.10.10.4 6666
to see the kernel log. What you'll also need is a usb flash with one ext2 partition. On that partition you should create a boot folder and put uImage to it. Also you should put uInitrd
to the root of the partition so that it looks like this
/boot/uImage
/uInitrd
Now connect the flash drive to your GoFlex and turn it on. Via netconsole you should be able to see how UBIT finds your usb flash and loads the kernel and the ramdisk. When in the kernel log you see something like
sshd (1141): /proc/1141/oom_adj is deprecated, please use /proc/1141/oom_score_adj instead.
then you should be able to ssh into the GoFlex. Use the web interface of your router to find out, which IP GoFlex is currently using. You should login as "root" and use the password "root". Once you have ssh access to the initramfs, you can easily recover by for example installing PlugBox on the ext2 partition of your usb flash. In fact, even if you want to install Debian, you should start with plugbox first, as debootstrap doesn't work properly when executed under initramfs. All you need to do to install PlugBox is to issue
on /dev/sda1 sh
wget http://archlinuxarm.org/os/ArchLinuxARM-armv5te-latest.tar.gz -O rootfs.tar.gz

tar -xzvf rootfs.tar.gz
If you now reboot, the probability is high, that you will boot into initramfs once again, because as I've alredy mentioned, the current UBIT ramdisk seems to have problems mounting the correct rootfs. To fix that, connect the usb flash to your PC and remove uInitrd from the root of the partition. Thus UBIT won't find any ram disk to load and the kernel will automatically mount /dev/sda1 as rootfs. Of course, this works only as long as you have no HDD connected to your system.

Debian from PlugBox

If you still have your usb flash with the debian partition from Jeff's install method, that's fine. If you don't, you will have to install PlugBox first. I suggest using a usb flash divided into three partitions (ext2,ext2,swap). On the first partition (sda1) you should install PlugBox as described above. The second partition (sda2) will be for Debian. Since we don't want to install u-boot (which is a part of Jeff's install script), we should modify the install script. I used shyd's modified version of Jeff's script which I then modified myself to remove the bootloafer part. Thus, this script will install Debian on /dev/sda2 but it won't alter you bootloader. You can get the script here. Save the script as goflex.debian-squeeze.sh to the root of your usb flash. Boot into Plugbox and issue

cp /goflex.debian-squeeze.sh /tmp/
cd /tmp 
chmod +x goflex.debian-squeeze.sh
./goflex.debian-squeeze.sh

Normally this should work without any errors. If your GoFlex has no internet access under PlugBox, consider editing /etc/resolv.conf and adding the IP of your router. In my case it looks like this
nameserver 192.168.1.1
Another strange problem I run into was that my time and date were completely wrong. I fixed that by issuing
date -s "11 Jun 2011 20:00:00"
which set the current date.
After the install is done, you shouldn't reboot but shutdown. Connect the usb flash to your pc and backup the debian partition to a tar file.
cd /media/debian-partitition
tar --one-file-system -cpf ~/GoFlex-Debian.tar *
you should also backup the PlugBox partition
cd /media/plugbox-partitition
tar --one-file-system -cpf ~/GoFlex-PlugBox.tar *
or at least save a copy of /boot/uInit and uInitrd from that partition. Now use Gparted or whatever you want to delete all the partitions on the usb flash and divide it into two partitions: a large ext3 and a small swap (256-512mb). Put your debian tar on the ext3 partition by issuing sth like
cd /media/debian-ext3
tar -xf ~/GoFlex-Debian.tar *
Don't forget to put /boot/uInit and uInitrd you've saved from the PlugBox partition to the new Debian partition, otherwise it won't boot. Unmount the flash drive, connect to the GoFlex and turn it on. If everything works out, Debian should boot nicely.

Debian with SATA kernel and hacked initrd

If you installed Debian as described above you already have the fancy new SATA kernel (uImage). Don't forget to adjust your arcNumber, otherwise the kernel will think that you're using a Dockstar and not GoFlex Net:
fw_setenv arcNumber "3089"
Now we still have the problem (as described at the beginning of the posting), that as soon as GoFlex boots with a HDD connected, the probability is high that it won't boot properly. To fix this we really should use a ramdisk, since the kernel alone is not intellegent enough to mount the right rootfs. Debian's initrd is capable of mounting a rootfs by UUID or label but unfortunately I wasn't able to make UBIT hand over the label instead of the device name. No matter what I tried, as boot parameters kenel always had root=/dev/sda1 and not root=LABEL=rootfs as I intended to. So I decided to hack the initrd, by making it always mount the partition with the label "rootfs" as rootfs. Here's how you can do it from Debian
apt-get install nano
cd /boot
mkdir initrd.img-new     
cp initrd.img-2.6.32-5-kirkwood initrd.img-new/
cd initrd.img-new/
gzip -dc initrd.img-2.6.32-5-kirkwood | cpio -id                       
rm initrd.img-2.6.32-5-kirkwood 
nano init
in nano find the part which looks like

if [ -n "${noresume}" ]; then
       export noresume
       unset resume
else
       resume=${RESUME:-}
fi
and add the following line
ROOT="/dev/disk/by-label/rootfs"
Save your changes (Ctrl-W) and exit (Ctrl-X) nano. Use
find ./ | cpio -H newc -o > new-initrd
gzip new-initrd 
mv new-initrd.gz initrd.img
mkimage -A arm -O linux -T ramdisk -C gzip -a 0 -e 0 -n "clever-initrd" -d initrd.img /uInitrd
to create a new uInitrd and put it into the root of rootfs. This way your GoFlex should always boot correctly, no matter whether HDDs are present or not. Just don't forget to label the rootfs partition on your usb flash as "rootfs"

Phew, now I can actually start using my GoFlex Net instead of hacking it :)



Edited 1 time(s). Last edit at 09/09/2011 01:34PM by Vlad.
Re: GoFlex Net + UBIT v0.6 + SATA kernel + Debian Squeeze + hacked Debian initrd
June 15, 2011 06:31AM
Thank's for sharing this.
It will defenatly spare me for many frustrating hours.

Peter
What's the file transfer speed from lan 2 lan on there with sata drives??
Re: GoFlex Net + UBIT v0.6 + SATA kernel + Debian Squeeze + hacked Debian initrd
July 04, 2011 09:34AM
I know this is after the fact, but could you not simply have changed the U-boot "bootargs" environment variable to set "root=LABEL=rootfs" instead of "root=$usb_root"? That parameter should be passed to the initrd to locate using the udev symlink "/dev/disk/by-label/rootfs".

(Looking at your U-bit output, you would to set root in set_bootargs line, where currently $dev_args sets the root during the usb scan.)

** edit **

I just tested it out... It seems to work as I expected...
My root filesystem stick has a label of "ROOTFS".

root@debian:~# blkid
/dev/sda1: LABEL="ROOTFS" UUID="df08d1b8-2938-495f-8c64-6baf4c5f0ef5" TYPE="ext2"

...

Marvell>> usb start
usb start
(Re)start USB...
USB: Register 10011 NbrPorts 1
USB EHCI 1.00
scanning bus for devices... 3 USB Device(s) found
scanning bus for storage devices... 1 Storage Device(s) found

Marvell>> run usb_scan
run usb_scan
Loading file "/boot/uImage" from usb device 0:1 (usbda1)
1 bytes read
Found bootable drive on usb 0:1

Marvell>> run usb_set_bootargs
run usb_set_bootargs

Marvell>> printenv bootargs
printenv bootargs
bootargs=console=ttyS0,115200 root=/dev/sda1 rootdelay=10 rootfstype=ext2 mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)

Marvell>> setenv bootargs console=ttyS0,115200 root=LABEL=ROOTFS rootfstype=ext2 mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)
setenv bootargs console=ttyS0,115200 root=LABEL=ROOTFS rootfstype=ext2 mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)

Marvell>> run usb_boot
run usb_boot
Loading file "/boot/uImage" from usb device 0:1 (usbda1)
1433612 bytes read
Loading file "/boot/uInitrd" from usb device 0:1 (usbda1)
5465330 bytes read
## Booting kernel from Legacy Image at 00800000 ...
Image Name: linux-2.6.32-5-kirkwood
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1433548 Bytes = 1.4 MiB
Load Address: 00008000
Entry Point: 00008000
Verifying Checksum ... OK
## Loading init Ramdisk from Legacy Image at 01100000 ...
Image Name: initramfs-2.6.32-5-kirkwood
Image Type: ARM Linux RAMDisk Image (gzip compressed)
Data Size: 5465266 Bytes = 5.2 MiB
Load Address: 00000000
Entry Point: 00000000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK

Starting kernel ...

...

And then I can then ssh in as normal... And if I set the label to something wrong, it appears like it's worked, but I cannot ssh back in at all... I tested with "root=LABEL=FOO".



Edited 3 time(s). Last edit at 07/04/2011 10:27AM by kraqh3d.
Re: GoFlex Net + UBIT v0.6 + SATA kernel + Debian Squeeze + hacked Debian initrd
July 08, 2011 09:46AM
Brilliant! It works! This is what I've been trying to do but haven't figured out how to go about it. Thanks Vlad. Now my Goflex Net always boots from the right partition as long as it has the right label.

kraqh3d, I did that but my uboot wouldn't accept the root as a label. Maybe you have a more up-to-date uboot version?



Edited 1 time(s). Last edit at 07/08/2011 09:49AM by playdude.
Re: GoFlex Net + UBIT v0.6 + SATA kernel + Debian Squeeze + hacked Debian initrd
July 08, 2011 01:01PM
I'm using Jeff's standard U-boot on an original Dockstar. I was just testing it for giggles as I had expected it to work but was curious to find out.


U-Boot 2010.09 (Oct 23 2010 - 11:49:22)
Marvell-Dockstar/Pogoplug by Jeff Doozan


root@debian:~# cat /proc/cmdline
console=ttyS0,115200 root=LABEL=ROOTFS rootdelay=10 rootfstype=ext3 mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)



Edited 4 time(s). Last edit at 07/10/2011 06:50PM by kraqh3d.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: