NSLU2-Linux
view · edit · print · history

WARNING

This is a HOWTO.

I written it as a reminder: after a few days, my NSLU2 print server were out of order, and in spite of an fsck on each partition of that bloody SDHC memory card and the re-creation of the swap space on it, unable to boot. Hopefully, I has another NSLU2, and a good disk plugged on. So, I could re-copy and adapt a new disk on that one, the plug the last more than one time, because of numerous mistakes due to my impatience.

So, to avoid headaches from me and others, I wrote the few following lines.

I cannot guarantee that you'll not break your system while follow them.

I checked it twice (and more!), but it is your responsability to follow it or ADAPT IT TO FIT YOUR ACTUAL SYSTEM.

It is wise to print a hardcopy, check and adapt all the operations before to begin, then follow and check step by step the operations you'll make.

Purpose

This HOWTO describes the operations required to get a spare system disk for a Debian powered NSLU2

Summary

  • Warning, Why?
  • Get the new disk and plug it
  • Make the partitions, Layout
  • Prepare the partitions image directory
  • Copy the partitions content
  • Make the devices
  • Create the missing directories
  • Verify that everything is OK
  • Umount the new partitions
  • Poweroff
  • Plug the new disk and pray!

0. Conventions

  • $ sign at the beginning of the line stands for a command typed as user on your NSLU2
  • # sign at the beginning of the line stands for a command typed as root on your NSLU2

If you prefer to use sudo for root commands, then insert sudo when a # sign appears.

1. Get the new disk

In order to have a backup for your system disk, you need a disk which global size is larger than the global size of the system partitions content you have to save.

To determine the actual size occupied by your system data, simply connect via ssh to your Slug, then type:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             471M   59M  389M  14% /
tmpfs                  15M     0   15M   0% /lib/init/rw
udev                   10M   56K   10M   1% /dev
tmpfs                  15M     0   15M   0% /dev/shm
/dev/sda5             5.6G  507M  4.8G  10% /usr
/dev/sda6             9.2G  458M  8.3G   6% /var
/dev/sda7             1.9G   48M  1.7G   3% /var/log
/dev/sda8             1.9G   35M  1.8G   2% /tmp
/dev/sda9             9.2G  150M  8.6G   2% /home

These are all data mounts on your system. You can safely ignore:

tmpfs /lib/init/rw, /dev/shm
these fs are memory resident.
udev /dev
this fs hides /dev directory with a dynamic content. Instead, add 100kBytes to the / (aka "root") filesystem.

So, the minimum will be the sum of all other partitions, plus ~10%

  • you can exclude /home if you plan to use a separate disk
  • this layout is mine, so it can likely be different on your system. Especially, you can have a single partition, or you can have more (eg: /var/www)

Now, type:

$ /sbin/fdisk -l /dev/sda

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          62      497983+  82  Linux swap / Solaris
/dev/sda2              63         124      498015   83  Linux
/dev/sda3             125        9729    77152162+   5  Extended
/dev/sda5             125         854     5863693+  83  Linux
/dev/sda6             855        2071     9775521   83  Linux
/dev/sda7            2072        2315     1959898+  83  Linux
/dev/sda8            2316        2559     1959898+  83  Linux
/dev/sda9            2560        3776     9775521   83  Linux

You can see above a partition we didn't count:

/dev/sda1
a swap one.
# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda1                               partition       497972  46608   -1

Divide the size field by 1024 to obtain the actual swap size in Mbytes. eg:

$ echo $(( 497972 / 1024 ))

Then round to the 1OO MBytes? upper (as you probably used a size multiple of 100MBytes).

Add that size to the one you noted before.

If you plan to split/merge the existing partitions to a new layout, do not forget that filesystem itself on each partition takes ~5% of the actual size of the partition

Summary

needed size = SUM( (df -h, except virtual filesystems),(SUM(swap partitions))) * 1,05.

You can now visit your favourite reseller, then plug your brand new USB 2.0 disk.

2. Make the new partitions layout.

There is only one rule: In order to boot, the swap partition and the /, aka "root" partition must be created in respect to the former partition numbers.

Remember we have:

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          62      497983+  82  Linux swap / Solaris
/dev/sda2              63         124      498015   83  Linux

That means, if the root partition above were not /dev/sda2, but the first logical partition, and the extended partition were /dev/sda3, you must create /dev/sdb1 as swap, then /dev/sdb3 as extended, then /dev/sdb5 as "/", Linux.

Below, we now create the partitions in respect of the existing table of sda1:

remain

 $ /sbin/fdisk -l /dev/sda

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          62      497983+  82  Linux swap / Solaris
/dev/sda2              63         124      498015   83  Linux
/dev/sda3             125        9729    77152162+   5  Extended
/dev/sda5             125         854     5863693+  83  Linux
/dev/sda6             855        2071     9775521   83  Linux
/dev/sda7            2072        2315     1959898+  83  Linux
/dev/sda8            2316        2559     1959898+  83  Linux
/dev/sda9            2560        3776     9775521   83  Linux

operations

# fdisk /dev/sdb


The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

=> nothing, this is OK

Command (m for help): n
Command action
   e   extended (1-4)
   p   primary partition (1-4)
p''return''
partition number(1-4): 1
First cylinder (1-9729, default 1):''return''
Last cylinder or +size or +sizeM or +sizeK (1-9729, default 9729): +500M

Command (m for help):p

Disk /dev/sdb: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          62      497983+  82  Linux

Command (m for help): t
Partition 1 selected
Hex code (type L to list codes): 82 '''=> Linux swap'''
Changed system type of partition 1 to 82 (Linux swap / Solaris)

Command (m for help):n''return''
partition number(2-4):2''return''
First cylinder (63-9729, default 63):''return''
Last cylinder or +size or +sizeM or +sizeK (63-9729, default 9729): +2000M''return''

Command (m for help):p''return''

Disk /dev/sdb: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          62      497983+  82  Linux swap / Solaris
/dev/sda2              63         124      498015   83  Linux

Command (m for help):n''return''
Command action
   e   extended (1-4)
   p   primary partition (1-4)
e''return''
partition number(1-4): 3
First cylinder (125-9729, default 125):''return''
Last cylinder or +size or +sizeM or +sizeK (1-9729, default 9729):''return''

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (125-9729, default 125):''return''
Last cylinder or +size or +sizeM or +sizeK (1-9729, default 9729):+6000M''return''

Command (m for help): p

Disk /dev/sdb: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          62      497983+  82  Linux swap / Solaris
/dev/sdb2              63         124      498015   83  Linux
/dev/sdb3             125        9729    77152162+   5  Extended
/dev/sdb5             125         854     5863693+  83  Linux

Command (m for help):n

you continue the n (new) operations with l (logical) to the end of your partition list), then verify a last time the layout, and write (w), or quit in emergency (q):

Command (m for help): p

Disk /dev/sdb: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          62      497983+  82  Linux swap / Solaris
/dev/sdb2              63         124      498015   83  Linux
/dev/sdb3             125        9729    77152162+   5  Extended
/dev/sdb5             125         854     5863693+  83  Linux
/dev/sdb6             855        2071     9775521   83  Linux
/dev/sdb7            2072        2315     1959898+  83  Linux
/dev/sdb8            2316        2559     1959898+  83  Linux
/dev/sdb9            2560        3776     9775521   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

Summary

You have prepared -- copied or modified -- your new partition plan

You were attentive to create the main root and swap partitions number in respect of the former partition layout, included extended partition if relevant

Note: there is no problem to not create the primary partitions in order on the disk (/dev/sdb4 can be created at cylinder 1, etc).

Prepare the image directory, copy the former partitions content to the targets

We assumes here the new drive is /dev/sdb, and the partition layer you created follows the example above.

Here we create the directories we will mount the new partitions on:

foobar@nslu2:~$ mkdir newlayout && cd newlayout
foobar@nslu2:~/newlayout$ for dir in slash sl_user sl_var sl_var_log sl_home
> do
> mkdir $dir
> done

Now, we format the new partitions

tom@littleblue:~/newlayout$ su
Password: 
littleblue:/home/tom/newlayout# for dev in /dev/sdb{2,5,6,7,8,9}
do
mkfs.ext3 $dev
done
[.................................................]
littleblue:/home/tom/newlayout# mkswap /dev/sdb1
[.................................................]

Now, we check and mount the new partitions on each relevant directory

littleblue:/home/tom/newlayout# fsck.ext3 /dev/sdb2 && mount /dev/sdb2 slash
littleblue:/home/tom/newlayout# fsck.ext3 /dev/sdb5 && mount /dev/sdb5 sl_usr
littleblue:/home/tom/newlayout# fsck.ext3 /dev/sdb6 && mount /dev/sdb6 sl_var
littleblue:/home/tom/newlayout# fsck.ext3 /dev/sdb7 && mount /dev/sdb7 sl_var_log
littleblue:/home/tom/newlayout# fsck.ext3 /dev/sdb9 && mount /dev/sdb2 sl_home

Now, we copy the content of the /, aka "root" directory to the target

littleblue:/home/tom/newlayout# cd slash
littleblue:/home/tom/newlayout/slash# tar cf - -C / --one-file-system  . | tar xf -

Note: if you use sudo, use it on the both sides of the pipe

Note: we use a tar option (-one-file-system) where needed, to select and insulate the root filesystem data exclusively

Note: you can make the tar command verbose by typing "cvf" instead of "cf" after the pipe, but you will certainly miss the warnings

Note: if your plan is to change de layout, by moving eg /usr on another partition, use: tar cf - -C / --one-file-system --exclude /usr . | tar xf -. You will need to repeat the "--exclude /foo" option for each moved filesystem. Do not forget after that to create the missing directories and to modify slash/etc/fstab as typed in a section below

Now, we copy the content of each partition root directory to the relevant target directory (a mounted /dev/sdbx partition)

littleblue:/home/tom/newlayout/slash# cd ../sl_usr
littleblue:/home/tom/newlayout/sl_usr# tar cf - -C /usr  . | tar xf -
littleblue:/home/tom/newlayout/sl_usr# cd ../sl_var
littleblue:/home/tom/newlayout/sl_var# tar cf - -C /var --one-file-system . | tar xf -
littleblue:/home/tom/newlayout/sl_var# cd ../sl_var_log
littleblue:/home/tom/newlayout/sl_var_log# tar cf - -C /var_log  . | tar xf -
littleblue:/home/tom/newlayout/sl_var_log# cd ../sl_home
littleblue:/home/tom/newlayout/sl_home# tar cf - -C /home  . | tar xf -

Note: we can safely ignore /tmp beside

Note: we use a tar option (--one-file-system) where needed, to select and insulate each filesystem data

Note: if your plan is to change de layout, by moving eg /var/www on another partition, use: tar cf - -C /var --one-file-system --exclude /var/www . | tar xf -. You will need to repeat the "--exclude /foo" option for each moved filesystem. Do not forget after that to create the missing directories and to modify slash/etc/fstab as typed in a section below

Summary

We

  • created the filesystems on the new partitions
  • created the target directories
  • mounted the new formatted partitions
  • copied the former partitions data to the new mounted partitions

Create the devices

You remember that while copying the former / (aka root) partition content to the new target (slash), we used the tar option --one-file-system.

This option allowed us to not soil the root filesystem with unwanted stuff, and insulate the other filesystems contents from the extracted archive.

This has (hopefully) a side effect: the /dev directory content were not created.

Or, we need to populate the /dev directory with a set of devices (pseudo-files to access the hardware, which point to the kernel in a way you'll find elsewhere).

So, here are the operations:

  • Copy the MAKEDEV script from /dev to the "slash" directory.
littleblue:/anywhere# # cd /home/tom/newlayout/slash
littleblue:/home/tom/newlayout/slash# cd dev
littleblue:/home/tom/newlayout/slash/dev# pwd
/home/tom/newlayout/slash/dev

Note: be carefull to be in the slash/dev directory as typed above, as it is really an hassle to revert the mess you done otherwise. You have been warned

  • populate the slash/dev target directory with standards "devices"
littleblue:/home/tom/newlayout/slash/dev# cp -p /dev/MAKEDEV .
littleblue:/home/tom/newlayout/slash/dev# pwd
/home/tom/newlayout/slash/dev
littleblue:/home/tom/newlayout/slash/dev# ./MAKEDEV generic

You can quietly prepare and drink a cup of tea (about 3 beers long :) )

Summary

We populated the target dev directory using MAKEDEV.

Create the missing directories

Remember: in case you changed the filesystem layout in the target disk, you used the tar option --exclude /foo/bar as times as needed.

This has the side effect that the mountpoints directories misses in their parent target filesystem.

For example, we have splitted /var in /var and /var/www.

So, it is time to:

  • add the missing sl_var/www directory;
  • add the missing entry /var/www to the slash/etc/fstab file.

Assuming /var has been already a partition, and the new disk target for the future /var/www is /dev/sdb10, which will become /dev/sda10,

Here are the commands:

  • edit the slash/etc/fstab file
littleblue:/anywhere# # cd /home/tom/newlayout/slash
littleblue:/home/tom/newlayout/slash# cd etc
littleblue:/home/tom/newlayout/slash/etc# pwd
/home/tom/newlayout/slash/etc
littleblue:/home/tom/newlayout/slash/etc# vi fstab

 ******* vi screenshot **********************************************************

# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/sda1       none            swap    sw              0       0
/dev/sda2       /               ext3    defaults,errors=remount-ro 0       1
/dev/sda5       /usr            ext3    defaults        0       2
/dev/sda6       /var            ext3    defaults        0       2
/dev/sda7       /var/log        ext3    defaults        0       0
/dev/sda8       /tmp            ext3    defaults        0       2
/dev/sda9       /home           ext3    defaults,acl    0       2
~                                                                               
~                                                                               
~
"/etc/fstab" 11L, 658C                                        1,1           All
 ********************************************************************************
[escape]G
[escape]o
 ********************************************************************************
.................
/dev/sda8       /tmp            ext3    defaults        0       2
/dev/sda9       /home           ext3    defaults,acl    0       2
[cursor]
 ********************************************************************************
.................
/dev/sda8       /tmp            ext3    defaults        0       2
/dev/sda9       /home           ext3    defaults,acl    0       2
/dev/sda10      /var/www/       ext3    defaults        0       2[cursor]
 *********************************************************************************
[escape]:wq
littleblue:/home/tom/newlayout/slash/etc#
  • create the relevant sl_var/www directory
littleblue:/home/tom/newlayout/slash/etc# cd home/tom/newlayout/sl_var
littleblue:/home/tom/newlayout/sl_var# pwd
home/tom/newlayout/sl_var
littleblue:/home/tom/newlayout/sl_var# mkdir www
littleblue:/home/tom/newlayout/sl_var# 

Summary

We created here the missing directory mountpoints, and added the relevant entries in the target slash/etc/fstab file

Verifying that everything is OK

The checklist:

  • Will the main swap and root filesystems targets be on the same devices (/dev/sdax) than the former ones? If one ore two of these filesystems were on a logical partition of the extended partition, is(are) the extended partition number the same, and is(are) the logical partition number the same?
  • Are the generic devices fully populated on the new slash/dev/ target directory?
  • Do the new partition layer is reflected on the new etc/fstab, assuming that (eg) the new disk /dev/sdb will be /dev/sda?
  • In case you changed the partitionning scheme (eg: you splitted /var in /var and /var/www on the targets filesystems), are the mountpoints directories entries created on the parents filesystems?

And:

  • Are you sure to not forget an existing filesystem? check /etc/fstab, then type mount and compare.

Reread the HOWTO from the beginning to this point. Point the operations you made.

Umounting the new disk filesystems

littleblue:/anywhere# cd

in case you are connected via su, quit the root session, then check the standard user is not in one of the new target directories (simply type cd). Reconnect as root (su or use sudo).

litlittleblue:/anywhere/but/targets# umount /dev/sdb*

You can safely ignore the warnings about not mounted filesystems.

Summary

Wu umounted the new filesystems

Now you can switch off your NSLU2

litlittleblue:/anywhere# poweroff

Plug your new disk

  • Unplug the former disk
  • Plug your new disk in lieu of

Push the start button, check the leds

readystatus orange
init
caterpillar
kernel loading
readystatus orange
after 10 minutes, you can consider that you likely missed something. probably in the fstab or -- shame on you -- the connection between root partition and the former one. it happened to me to ;). So, see below to power off.
ready status switching green/orange
correct booting, you can have a beer
disk1 green, readystatus heartbeat
boot is successfull

Try to connect to your NSLU2 via SSH.

If it doesn't succeed, push the power button, then unplug power chord while you'll get the cartepillar leds blinking. Swap the disks, and try to guess what is wrong. If you got the redystatus led heartbeat, you most probably missed the fstab entry for /usr.

Check for the processes (ps -ef), check the mounts (/sbin/mount).

You can now poweroff your NSLU2, then swap the disks and keep your spare one in a safe place. Or You can keep the new disk with it's updated layout. So have a beer (or, safer, a tea).

view · edit · print · history · Last edited by Thomas Harding.
Originally by Thomas Harding.
Page last modified on July 20, 2008, at 10:01 PM