Monday 9 September 2013

some scripts about debian(linux) boot-shell and swap

Recently, I manage a tiny vps with  debian, since it needs extension is swap for more programs. I do some research on how to mount a swap and add some customer shell on boot. This article just for record some shell script for next time to use.

1, the website  http://www.debian.org/doc/manuals/debian-reference/ very useful, but sometimes it goes wrong like:
the page:
http://www.debian.org/doc/manuals/debian-reference/ch03.en.html#_an_overview_of_the_boot_strap_process

it write:
The Debian system goes into runlevel N (none) to initialize the system by following the "/etc/inittab" description.
  1.  but actually it is in  /etc/event.d/somefile
2, the swap setting process.
    1, checking the current usage of each partition:

root@wemet:~# df -B M
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/vda 20031M 3323M 15684M 18% /
none 1M 0M 1M 0% /sys/fs/cgroup
udev 242M 1M 242M 1% /dev
tmpfs 50M 1M 49M 1% /run
none 5M 0M 5M 0% /run/lock
none 246M 0M 246M 0% /run/shm
none 100M 0M 100M 0% /run/user

2, build the large file
root@wemet:~# dd if=/dev/zero of=/swapadd bs=1024 count=524288
524288+0 records in
524288+0 records out

3,moving file to /mnt/swap/  that is just meet the mount standard.
4, build virtual memory
root@wemet:~# mkswap /mnt/swap/swapadd
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=a5c8b651-6f64-4414-bb5f-580b742acfce

5, make a shell file which will enable the swap
the bash file is:
#!/bin/sh
swapon /mnt/swap/swapadd
and make it have right and standard place:
root@wemet:~# mv swaponfile /etc/init.d
6, put it to standard multi-user runlevels (2 to 5)
root@wemet:/etc# cd /etc/rc2.d
root@wemet:/etc/rc2.d# ln -s /etc/swaponfile myswap
7, Changing the system swappiness value. The swap file will then only be used when my RAM usage is around 80 or 90 percent. open /etc/sysctl.conf as root, add fellowing:
vm.swappiness = 10 
 or you can also handle on shell script:
root@wemet:/etc# sysctl vm.swappiness=10
8,reboot and the new swap woulb be built.