PDA

Bekijk de volledige versie : Increase Free Memory and no more reboots due to too long syslog file (Need USB disk)



erik_bies
02-05-2004, 23:00
Ok,

This is working for me, and may be also working for you.
The idea is to disable the ramdisk where the syslog is stored. While disabling gives you some more memory, the biggest advantage (to me) is that the syslog can grow, grow grow without the device runs out of memory.

Now, I would not reccommend this for a flashdrive, as I think a flash can only be written a few thousand times. Well, actually I don't know. At your own risk!

Step 1.
Make sure you have OLEG's firmware running, and you are booting from harddisk.
You can check it by loggin on, and type mount

If you don't see an "cramfs" entry you are running smooth from disk :cool:

Step 2 Make your drive writable after the booting.
For this step you need vi editor. In the latest version of the firmware this is build in, for older versions you need to use the 'full version' which can be found here http://files.wl500g.info/asus/wl500g/firmware/app/busybox.zip
This version might anyway be handy to have somewhere on your disk, just in case you need the extra features.

Make your drive writable after the booting.
Add a line to the "/init/boot" file (maybe make a backup of the boot file cp boot boot.org)
mount -o remount,rw,noatime "$boot_dev" /
after the two mount commands. This brings your disk in read-write mode just after booting.

Step 3 Create empty tmp dir
The original firmware always starts with empty tmp. I'm not sure if it is really needed. Anyway, it nicely cleans up any mess left behind

add the rm line just before the "mkdir /mnt/ramfs/tmp" line
rm -rf /mnt/ramfs/tmp
mkdir /mnt/ramfs/tmp

Step 4 Remove RAM disk
Continue editing the boot file, add the # in front of the mount command of the ramdisk
#mount -t ramfs ramfs /mnt/ramfs

reboot your router, and check with mount command.
you should see something like:

/dev/scsi/host0/bus0/target0/lun0/part1 on / type ext2 (rw,noatime)
none on /dev type devfs (rw)
none on /proc type proc (rw)

Ok, way to go, you have it.
You can see the available mem by typing:
~ # cat /proc/meminfo
total: used: free: shared: buffers: cached:
Mem: 14794752 12906496 1888256 0 425984 6336512
Swap: 0 0 0
MemTotal: 14448 kB
MemFree: 1844 kB
MemShared: 0 kB
Buffers: 416 kB
Cached: 6188 kB
SwapCached: 0 kB
Active: 3760 kB
Inactive: 4316 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 14448 kB
LowFree: 1844 kB
SwapTotal: 0 kB
SwapFree: 0 kB


If you still don't think you have enough memory you might wanna add some swap memory

do it as following:
Create an empty file (the number behind the count is the number of MB you wanna have as swap)
~ # dd if=/dev/zero of=/swp bs=1M count=32
32+0 records in
32+0 records out

(you need again the full version of the busybox)
~ # /path to your busybox/busybox mkswap /swp
Setting up swapspace version 1, size = 33550336 bytes
~ # /busybox swapon /swp

again, you can check if it is working by typing:
~ # cat /proc/meminfo
total: used: free: shared: buffers: cached:
Mem: 14794752 13496320 1298432 0 663552 6955008
Swap: 33546240 131072 33415168
MemTotal: 14448 kB
MemFree: 1268 kB
MemShared: 0 kB
Buffers: 648 kB
Cached: 6664 kB
SwapCached: 128 kB
Active: 2420 kB
Inactive: 6364 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 14448 kB
LowFree: 1268 kB
SwapTotal: 32760 kB
SwapFree: 32632 kB

Note: Mini "vi" editor manual.
Maybe you are struggeling with vi just as I most of the time do.
The way to edit this boot file:
/path to your full busybox/busybox vi /init/boot
scroll to the place where you want to edit, click the "insert" key. You see in the bottom left part of the screen "-- Insert --" (click once more to replace)
No modify/add the text you want to edit, after the edit is done click the "Esc" key. to delete a line type ":d"
Now write the file with the ":w" command
Close vi with the ":q" command

BTW. While experimenting to get this done, I several times booted the device without having a working tmp dir. The interesting behaviour is that some of the services did not start, or did not work. I could not log on to the box anymore with SSH, however the telnetd was each time running and accepting connections. This allowed me to fix the thing and continue.

Mark Koops
21-09-2004, 22:01
Hi Erik,

I have read your posting with losts of interest and tried to work it out myself . So, loading the root file system and changing the /init/boot file as describe. It all seems to work fine for a small amount of time, but after 1 or 2 restarts of the router (including detaching/attaching the usb drive) something seems to change in the filesystem that causes the router to end up in some sort of boot loop.

That is: after booting up is finished, my network adapter does get an IP address and I am able to open a telnet session to the router but in seconds that connection is dropped and the router starts booting again. This keeps going on and on.

Solved it a couple of times by reinstalling the root file system from scratch, but it keeps failing every time after 1 or 2 reboots.
Could not find any clear keys in the system log about something failing just before the reboot occurs.

Do you have any idea what can be the problem? And do you have any suggestions to solve it?

TIA,

Mark

Styno
22-09-2004, 09:38
Hey, this is great. I was just working on the same procedure. Now I don't need to anymore :D

Thanks!

One comment: Migrating from flashboot to USB boot will make the process of upgrading/changing firmware more difficult. So be prepared to go in-dept with this.

Oh, and if someone only wants the additional swap memory but does not want to boot from USB then just copy the full version of busybox to the USB disk and carry on with the described mount commands in Erik' post (Below is the description on howto do this).

Adding Swap memory to a custom firmware without using the rootfs option (tested it on 1.7.5.9-CR5):
- Create a swap partition using Partition Magic (or similar program) or with the 'busybox mkswap' command.
- Add the following command to the post-boot script:
/mnt/usbfs/busybox swapon /dev/discs/disc0/part6
My partition table:
/dev/discs/disc0/part1 - 159 GB FAT32
/dev/discs/disc0/part2 - 64 Mb Extended
/dev/discs/disc0/part5 - 32 Mb Ext2
/dev/discs/disc0/part6 - 32 Mb Linux Swap
- Save the changes with:
flashfs save
flashfs commit
- Reboot and check the swap space with:
cat /proc/meminfo

A note though: Swap memory will have to travel over USB1.1 (11Mb/s) so it will probably be slow...

Styno
22-09-2004, 09:41
Hi Erik,

I have read your posting with losts of interest and tried to work it out myself . So, loading the root file system and changing the /init/boot file as describe. It all seems to work fine for a small amount of time, but after 1 or 2 restarts of the router (including detaching/attaching the usb drive) something seems to change in the filesystem that causes the router to end up in some sort of boot loop.

That is: after booting up is finished, my network adapter does get an IP address and I am able to open a telnet session to the router but in seconds that connection is dropped and the router starts booting again. This keeps going on and on.

Solved it a couple of times by reinstalling the root file system from scratch, but it keeps failing every time after 1 or 2 reboots.
Could not find any clear keys in the system log about something failing just before the reboot occurs.

Do you have any idea what can be the problem? And do you have any suggestions to solve it?

TIA,

Mark
The reboots probably are triggered by the watchdog daemon. This indicates that one or more 'critical' services have failed to start. Search the forum on which services are being watchdogged.

Styno
02-10-2004, 12:48
Like described 2 posts up, I've setup swap memory on my USB HDD and I've noticed swap memory being used up to 26MBytes till now! The router can really use this extra virtual memory it seems. This extensive use of memory is mostly caused by the giFT daemon, which requires heaps of RAM sometimes.

total: used: free: shared: buffers: cached:
Mem: 14725120 13430784 1294336 0 704512 3579904
Swap: 32862208 26611712 6250496
MemTotal: 14380 kB
MemFree: 1264 kB
MemShared: 0 kB
Buffers: 688 kB
Cached: 2016 kB
SwapCached: 1480 kB
Active: 4368 kB
Inactive: 3708 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 14380 kB
LowFree: 1264 kB
SwapTotal: 32092 kB
SwapFree: 6104 kB



Mem: 13240K used, 1140K free, 0K shrd, 300K buff, 7328K cached
Load average: 2.33, 2.32, 1.70 (State: S=sleeping R=running, W=waiting)

PID USER STATUS RSS PPID %CPU %MEM COMMAND
1049 root D 5700 1 56.1 39.6 ld.so.1
1187 root S 228 1012 11.2 1.5 giFTwakeup
1296 root R 220 1295 3.2 1.5 top
778 root SW 0 1 2.0 0.0 usb-storage-0
4 root SW 0 1 0.3 0.0 kswapd
488 root S 36 1 0.1 0.2 telnetd
1032 root S 140 983 0.0 0.9 watchdog
512 root S 140 1 0.0 0.9 httpd
1006 root S 128 1 0.0 0.8 nmbd
970 root S 76 1 0.0 0.5 stupid-ftpd
826 root S 36 1 0.0 0.2 udhcpc
317 root S 20 1 0.0 0.1 klogd
305 root S 20 1 0.0 0.1 syslogd
1013 root S 12 1 0.0 0.0 busybox_httpd
1012 root S 12 998 0.0 0.0 giftd.sh
1295 root S 8 488 0.0 0.0 sh
1005 root S 4 1 0.0 0.0 dropbear
3 root RWN 0 1 0.0 0.0 ksoftirqd_CPU0
8 root SW 0 1 0.0 0.0 mtdblockd

(ld.so.1 is the giFT daemon)

Strange thing though: The giFT daemon and the other processes do not account to 26 MB swap + 12 MB RAM. But I must say I don't exactly know how Linux handles swap memory, it might be buffer space as well.

Anyone an idea why Linux uses so much swap space?

Edit:
OMG, now all the swap space is used...

total: used: free: shared: buffers: cached:
Mem: 14725120 13234176 1490944 0 667648 1847296
Swap: 32862208 32862208 0
MemTotal: 14380 kB
MemFree: 1456 kB
MemShared: 0 kB
Buffers: 652 kB
Cached: 1740 kB
SwapCached: 64 kB
Active: 2948 kB
Inactive: 4880 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 14380 kB
LowFree: 1456 kB
SwapTotal: 32092 kB
SwapFree: 0 kB