NSLU2-Linux
view · edit · print · history

When formatting a hard disk with the Linksys web interface, it creates 3 partitions to sda/sdb (a for USB port 1 or b for USB port 2).

 /dev/sda1 fileshare partition, maximum diskspace that is left after sda2 & sda3
 /dev/sda2 configuration partition/system file partition, approx. 100 megabytes.
 /dev/sda3 swap partition, 55 megabytes.

I wanted to use sda2 for storing my programs, configs etc. but I thought that 100 megabytes wouldn't be sufficient as I wanted to try a lot of stuff. I also wanted to raise the size of the swap partition to 64 megabytes at the same time. So I started my little project first with trying to unmount mounted partitions, then using swapoff /dev/sda3 and then trying to fdisk it. SerComm/Linksys however has modified fdisk and it refuses to work properly, it complains that there are already 3 partitions on the disk and then exits. I tried to kill most of running processes as I thought that the disk device was still busy, but it didn't help.

Next thing was to back up all files on /dev/sda1 and /dev/sda2 and connect this disk to my Linux workstation and fdisk+format it there. I also copied my backed up files back to the partitions. Then I connected it to my nslu but it didn't help me out, the web interface told me that disk wasn't formatted. I checked from the shell that it was formatted and can also be mounted, but the Linksys firmware must check that it formatted it itself.

I then formatted again disk via the web interface, I was hoping that it wouldn't resize it if it already contained 2 Linux ext3 partitions + 1 Linux swap. But it did resize them.

I connected my hard disk back to my Linux workstation, used fdisk to erase the previous partition table and re-created my custom partition table, I didn't format the disk. Just set /dev/sda1 and /dev/sda2 to Linux filesystem format and /dev/sda3 to Linux Swap format.

Next I connected my harddisk once again to the NSLU and entered the shell. I found fdisk command in /sbin and I renamed it:

 mv /sbin/fdisk /sbin/fdisk.old

and created a new fdisk, actually just a shell script, but it did the job and solved something for me that was still a little unclear. Here's my new fdisk:

 #!/bin/sh
 echo $1 $2 $3 $4 $5 >> /tmp/fdiskparams

It's a simple script which outputs command line parameters 1-5 to file /tmp/fdiskparams. e.g. fdisk hello world would append text "hello world" to our /tmp/fdiskparams.

Be sure to change the permissions on the new fdisk:

 chmod 755 fdisk

Then I went back to the web interface and tried to format again. I waited to see if it would complain about failed fdisk or that it would have an internal partition table modifier, but using

 cat /tmp/fdiskparams

showed me this:

 -d /dev/sda
 /dev/sda

First line means that it used fdisk to clear the partition table and then it started to edit partitions on the second line. Output isn't shown because my script doesn't support catching stdin and redirecting it to a file. I thought that I could then use fdisk to partition my disk so I wouldn't need to connect the disk to a workstation, but I was wrong. I tested this and fdisk won't let you use the interface even with an empty partition table.

But now my NSLU was formatting the disk and it had tried to use fdisk. After formatting I was still worried about status of disk, if it after all still checks sizes of sda2 and sda3 then it wouldn't work, but it reported that disk state was Formatted. I rebooted to make sure and yes, the status still was formatted.

If you proceeed with my instructions, remember to change fdisk.old back to fdisk in case it is needed for something later.


I have used the above instructions several times successfuly with usb flash drives, but when it came to a 250GB hard drive it failed. Immediately following the part where you tell the web interface to format the drive, it showed up as formatted in the web screen. However a df command shows that only the data partition is mounted. Unsling would then fail.

I was able to get custom partitions by backing up the files on a linksys formatted drive. Then using a SUSE linux box I partitioned and formatted the drive. I put all the linksys files back and everyone's happy now.

Note: The hidden files must also be copied. Specifically .dongle and .htpasswd in the conf partition.

-MTisza?


I had a similar problem to the above with a WD 250Gb MyBook? Drive. After repartitioning, renaming /sbin/fdisk to /sbin/fdisk.old, and clicking format on the web interface, I similarly received an error when unslinging the drive. Checking the /sbin/unsling script gives a quick understanding why:

  ...
  echo "Checking that $targ has been properly formatted..."
  if ! [ -d $targ/public ] || ! [ -f $targconf/.dongle ] || ! [ -f $targconf/passwd ] ; then
  ...

Since I was using port2, $targ here is my /dev/sda1 mounted on /share/flash/data and $targconf is /dev/sda2 mounted on /share/flash/conf. I confirmed that these files had indeed not been created or copied.

To make things work, plug in a spare USB pen in the other port, rename /sbin/fdisk.old back to /sbin/fdisk, and using the web interface format the usb pen. Copy the files over to the original 250Gb drive. Double check everything is there, including hidden files (ie. use "ls -la"). My slug became increasingly confused at this point, and refused to copy 'en masse' at times (moving files helped, copying individually helped too)...

HTH

- Cyanescent


This trick will also help you to have more than three partitions in your root hard disk. An extra NTFS partition may come in handy in certain situations.

lgv

view · edit · print · history · Last edited by lgv.
Based on work by cyanescent, AlbertSmith, MTisza, tman, and jake.
Originally by jake.
Page last modified on October 16, 2007, at 10:39 PM