4. partition and format HDD
Important for USB Disks: Power on First HDD , second router.
IMPORTANT: You will loose all the data on your HDD. Make a backup if necessary.
From now on you will work with putty.
Start putty, enter the IP adress of your box and select SSH.
Confirm the Key.
My HDD (80GB) is partitioned as follows:
data (part1), IPKG (part2) und swap (part3)
all primary, no extended
Swap 512MB (You can also use 128MB if you want to save some space)
IPKG 1GB
Data the rest (~78GB)
View mountpoints
[admin@blechbuechse root]$ df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/root 3008 3008 0 100% /
/dev/discs/disc0/part1 75398848 683812 70884940 1% /tmp/mnt/disc0_1
[admin@blechbuechse root]$
If there is nothing except / go directly to fdisk.
If you allready partitioned your HDD as you want (incl. swap) go to the next chapter. BUT: i recommend using fdisk because several users reported problems in mounting partitions created with third party software.
You should unmount all mounts except /.
Code:
umount /place/of/mountpoint
/place/of/mountpoint needs to be replaced with the entries from df. E.g. "umount /tmp/mnt/disc0_1".
If there is an error message during umount there is activity on the mount. Did you disable FTP / Samba, ...?
After unmounting all it should look like this:
[admin@blechbuechse root]$ df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/root 3008 3008 0 100% /
There may be a tmpfs mounted on /tmp which depends on the used firmware and does NOT need to be unmounted.
Partition with fdisk:
Code:
fdisk /dev/discs/disc0/disc
fdisk:
m for help.
p for view partitions.
d for delete.
n for new.
Delete all existing partitions, if any. All data will be lost!!! create new partitons after deleting the old ones:
partitions:
part1 Swap 512MB type82
part2 IPKG 1024MB /opt
part3 data rest /tmp/harddisk (This is a point where WL-HDD differs to others..!?!)
Create swap: n -> p -> 1 -> 'return' -> +512M -> t -> 82
Create IPKG: n -> p -> 2 -> 'return' -> +1024M
Create data: n -> p -> 3 -> 'return' -> 'return'
Save settings by pressing w and exit.
"fdisk -l" will show your partitions:
[admin@blechbuechse root]$ fdisk -l
Disk /dev/ide/host0/bus0/target0/lun0/disc: 80.0 GB, 80026361856 bytes
16 heads, 63 sectors/track, 155061 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System
/dev/ide/host0/bus0/target0/lun0/part1 1 993 500440+ 82 Linux swap
/dev/ide/host0/bus0/target0/lun0/part2 994 2978 1000440 83 Linux
/dev/ide/host0/bus0/target0/lun0/part3 2979 155061 76649832 83 Linux
Now you activate the swap:
This is a 'free' without swap:
[admin@blechbuechse root]$ free
total used free shared buffers
Mem: 13932 11304 2628 0 1388
Swap: 0 0 0
Total: 13932 11304 2628
[admin@blechbuechse root]$
activate swap:
Code:
mkswap /dev/discs/disc0/part1
swapon /dev/discs/disc0/part1
'free' should look like this after activating:
[admin@blechbuechse root]$ free
total used free shared buffers
Mem: 13932 10236 3696 0 1320
Swap: 500432 0 500432
Total: 514364 10236 504128
[admin@blechbuechse root]$
Now you have enough free memory to format the rest of the HDD:
Code:
mke2fs -j /dev/discs/disc0/part2
mke2fs -j -m 0 /dev/discs/disc0/part3
part3 will take some time, depending on HDD size. The option '-m 0' will set reserved blocks to 0. Do NOT try this on /opt partition!!!
A remark for the newbies: The partitions are ext3 formated. This is what you want!. You do NOT need Fat or NTFS to access your data.
You need to edit the file fstab to automaticaly mount the partitions
a short vi Explanation: vi is an editor.
You enter the insert mode with i, you leave it with ESC.
You can insert the content of the clipboard by right clicking within insert mode.
After leaving the insert mode you quit and save by typing ':wq'. Leaving without saving is ':q!'.
This is all. Search for a vi howto for more.
Edit the file /etc/fstab by typing:
and paste this:
Code:
#device Mountpoint FStype Options Dump Pass#
/dev/discs/disc0/part1 none swap sw 0 0
/dev/discs/disc0/part2 /opt ext3 rw,noatime 1 1
/dev/discs/disc0/part3 /tmp/harddisk ext3 rw,noatime 1 1
Partitions are mounted and swap is activated.
Important: The data partition is mounted to /tmp/hardisk as in fstab. This is handled different in the firmware because of compatibility issues: The Partition is mounted to /tmp/mnt/disc0_3 and a symlink is pointing from /tmp/hardisk to /tmp/mnt/disc0_3
To save fstab for reboot:
Code:
echo "/etc/fstab" >> /usr/local/.files
5. Startup-scripts
The time zone in the firmware is not correct for middle europe. We will correct this:
This issue is fixed from verison wl500g-1.9.2.7-d-r240 (2009-04-11) on.
If you use any newer version you can continue with i /usr/local/sbin/pre-mount.
Code:
vi /usr/local/sbin/pre-boot
content:
Code:
#! /bin/sh
tz="CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00"
nvram set time_zone="$tz"
echo "$tz" > /etc/TZ
Have a look at http://wl500g.info/showpost.php?p=139268&postcount=4 or http://wl500g.info/showthread.php?t=13727 for details.
There is a script to keep the file system clean:
Code:
vi /usr/local/sbin/pre-mount
with this content:
Code:
#! /bin/sh
swapon -a
for i in `awk '/ext3/{print($1)}' /etc/fstab` ; do
if [ -b $i ] ; then
grep -q $i /proc/mounts || e2fsck -p $i 2>&1 | logger -t e2fsck
else
logger -t fstab "$i is not attached"
fi
done
pre-mount will start e2fsck if needed. My WL-HDD with its 80GB HDD takes some hours to do this check! It is possible that your router is switched on and the HDD becomes available hours later. You can leave pre-mount empty to prevent this, but your file system will have to be checked from time to time. Your decision. I have this activated.
post-mount is executed after pre-mount
Code:
vi /usr/local/sbin/post-mount
content:
Code:
#! /bin/sh
/opt/etc/init.d/rc.unslung start
And this file is executed before shutting down:
Code:
vi /usr/local/sbin/pre-shutdown
And again content:
Code:
#! /bin/sh
/opt/etc/init.d/rc.unslung stop
sleep 10s
for i in `cat /proc/mounts | awk '/ext3/{print($1)}'` ; do
mount -oremount,ro $i
done
swapoff -a
sleep 1s
This script is remounting all partitions as read only to prevent loss of data at power off.
The HDD has to be mounted before editing the next file. But the best is to save and reboot:
Code:
flashfs save && flashfs commit && flashfs enable && reboot
check swap and mount of HDD with 'free' and 'df -h'. Everything ok? Next step.
Software and services installed via IPKG write scripts to /opt/etc/init.d.
You need a mechanism to start these scripts. This mechanism (a script) is triggert by post-boot.
Code:
mkdir /opt/etc
mkdir /opt/etc/init.d
vi /opt/etc/init.d/rc.unslung
Remark: If you get a "mkdir: Cannot create directory `/opt/etc': Read-only file system" your HDD (here the IPKG pertition) is NOT mounted.
Content:
#! /bin/sh
# Start/stop all init scripts in /opt/etc/init.d
# starting them in numerical order and
# stopping them in reverse numerical order
#
if [ $# -ne 1 ]; then
printf "Usage: $0 {start|stop}\n" >&2
exit 1
fi
daemons=`echo $(/usr/bin/dirname $0)/S??*`
[ $1 = "stop" ] && daemons=`echo $daemons | /usr/bin/tr " " "\n" | /usr/bin/sort -r`
for i in $daemons; do
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
# Write to syslog
logger -t rc.unslung "$1 service $i"
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set $1
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i $1
;;
esac
done
Make it executable:
Code:
chmod +x /opt/etc/init.d/rc.unslung
And this part is done