M0E-lnx's Blog
Not much of a blogger, but here it is
Wednesday, May 4, 2011
My adventures in computer programming
Tuesday, February 2, 2010
Updated internet connection sharing howto
http://m0e-lnx.blogspot.com/2009/08/howto-share-your-internet-connection-in.html
Tuesday, December 1, 2009
Enhanced power savings for laptops under Vectorlinux
The technical details of how better battery life is achieved can be quite complicated for people like myself to fully understand.
There is a very nice article on the linux journal explaining the technical details if you'd like to http://www.linuxjournal.com/article/7539
Here is how to get this working on VectorLinux. Its quite simple really.
- Download the latest laptop-mode-tools tarball from here
- cd to the dir where the tarball is downloaded
- Extract the tarball ( tar xf laptop-mode-tools-*.tar.* )
- cd into the resulting dir (cd laptop-mode-tools-*
- become root via the su command and enter your root password.
- You should see an install.sh script in that directory, execute it (./install.sh)
- Edit your /etc/rc.d/rc.local and add this line at the very end "/etc/rc.d/init.d/laptop-mode restart"
Reboot and enjoy.
###############################################################################
#
# Configuration for Laptop Mode Tools
# -----------------------------------
#
# There is a "system" to the configuration setting names:
# CONTROL_something=0/1 Determines whether Laptop Mode Tools controls
# something
# LM_something=value Value of "something" when laptop mode is active
# NOLM_something=value Value of "something" when laptop mode is NOT
# active
# AC_something=value Value of "something" when the computer is running
# on AC power
# BATT_something=value Value of "something when the computer is running
# on battery power
#
# There can be combinations of LM_/NOLM_ and AC_/BATT_ prefixes, but the
# available prefixes are different for each setting. The available ones are
# documented in the manual page, laptop-mode.conf(8). If there is no LM_/
# NOLM_ in a setting name, then the value is used independently of laptop
# mode state, and similarly, if there is no AC_/BATT_, then the value is used
# independently of power state.
#
# Some options only work on ACPI systems. They are marked ACPI-ONLY.
#
# Note that this configuration file is a fragment of shell script: you
# can use all the features of the shell scripting language to achieve your
# desired configuration.
#
#
# Modules
# -------
#
# Laptop Mode Tools modules have separate configuration files, that can be
# found in /etc/laptop-mode/conf.d. Please look through these configuration
# files as well, there are many useful power saving tools in there!
#
###############################################################################
###############################################################################
# Configuration debugging
# -----------------------
###############################################################################
#
# Set this to 1 if you want to see a lot of information when you start/stop
# laptop_mode.
#
VERBOSE_OUTPUT=0
###############################################################################
# When to enable laptop mode
# --------------------------
#
# "Laptop mode" is the mode in which laptop mode tools makes the computer
# consume less power. This includes the kernel "laptop_mode" feature, which
# allows your hard drives to spin down, as well as various other settings which
# can be tweaked by laptop mode tools. You can enable or disable all of these
# settings using the CONTROL_... options further down in this config file.
###############################################################################
#
# Enable laptop mode when on battery power.
#
ENABLE_LAPTOP_MODE_ON_BATTERY=1
#
# Enable laptop mode when on AC power.
#
ENABLE_LAPTOP_MODE_ON_AC=0
#
# Enable laptop mode when the laptop's lid is closed, even when we're on AC
# power? (ACPI-ONLY)
#
ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=0
###############################################################################
# When to enable data loss sensitive features
# -------------------------------------------
#
# When data loss sensitive features are disabled, laptop mode tools acts as if
# laptop mode were disabled, for those features only.
#
# Data loss sensitive features include:
# - laptop_mode (i.e., delayed writes)
# - hard drive write cache
#
# All of the options that follow can be set to 0 in order to prevent laptop
# mode tools from using them to stop data loss sensitive features. Use this
# when you have a battery that reports the wrong information, that confuses
# laptop mode tools.
#
# Disabling data loss sensitive features is ACPI-ONLY, and it only works if
# your battery gives off frequent ACPI events to indicate a change in battery
# level.
#
# NOTE: If your battery does NOT give off battery events often enough, you can
# enable the battery-level-polling module to make this work. Look at the
# file /etc/laptop-mode/conf.d/battery-level-polling.conf for more information.
#
###############################################################################
#
# Disable all data loss sensitive features when the battery level (in % of the
# battery capacity) reaches this value.
#
MINIMUM_BATTERY_CHARGE_PERCENT=3
#
# Disable data loss sensitive features when the battery reports its state
# as "critical".
#
DISABLE_LAPTOP_MODE_ON_CRITICAL_BATTERY_LEVEL=1
###############################################################################
# Controlled hard drives and partitions
# -------------------------------------
#
# For spinning down your hard drives, laptop mode will remount file systems and
# adjust hard drive spindown timeouts. These parameters specify which
# devices and partitions are affected by laptop mode.
###############################################################################
#
# The drives that laptop mode controls.
# Separate them by a space, e.g. HD="/dev/hda /dev/hdb". The default is a
# wildcard, which will get you all your IDE and SCSI/SATA drives.
#
HD="/dev/[hs]d[abcdefgh]"
#
# The partitions (or mount points) that laptop mode controls.
# Separate the values by spaces. Use "auto" to indicate all partitions on drives
# listed in HD. You can add things to "auto", e.g. "auto /dev/hdc3". You can
# also specify mount points, e.g. "/mnt/data".
#
PARTITIONS="auto /dev/mapper/*"
#
# If this is enabled, laptop mode tools will assume that SCSI drives are
# really SATA drives that only _look_ like SCSI drives, and will use hdparm
# to control them. Set this to 0 if you have /dev/sd devices and you want
# laptop mode tools to use the "sdparm" command to control them.
#
ASSUME_SCSI_IS_SATA=1
###############################################################################
# Hard drive behaviour settings
# -----------------------------
#
# These settings specify how laptop mode tools will adjust the various
# parameters of your hard drives and file systems.
###############################################################################
#
# Maximum time, in seconds, of work that you are prepared to lose when your
# system crashes or power runs out. This is the maximum time that Laptop Mode
# will keep unsaved data waiting in memory before spinning up your hard drive.
#
LM_BATT_MAX_LOST_WORK_SECONDS=600
LM_AC_MAX_LOST_WORK_SECONDS=360
#
# Should laptop mode tools control readahead?
#
CONTROL_READAHEAD=1
#
# Read-ahead, in kilobytes. You can spin down the disk while playing MP3/OGG
# by setting the disk readahead to a reasonable size, e.g. 3072 (3 MB).
# Effectively, the disk will read a complete MP3 at once, and will then spin
# down while the MP3/OGG is playing. Don't set this too high, because the
# readahead is applied to _all_ files that are read from disk.
#
LM_READAHEAD=3072
NOLM_READAHEAD=128
#
# Should laptop mode tools add the "noatime" option to the mount options when
# laptop mode is enabled?
#
CONTROL_NOATIME=0
# Should laptop use relatime instead of noatime? The "relatime" mount option has
# more standards-compliant semantics, and allows more applications to work,
# while retaining a low level of atime updates (i.e., disk writes).
USE_RELATIME=1
#
# Should laptop mode tools control the hard drive idle timeout settings?
#
CONTROL_HD_IDLE_TIMEOUT=1
#
# Idle timeout values. (hdparm -S)
# Default is 2 hours on AC (NOLM_HD_IDLE_TIMEOUT_SECONDS=7200) and 20 seconds
# for battery and for AC with laptop mode on.
#
LM_AC_HD_IDLE_TIMEOUT_SECONDS=60
LM_BATT_HD_IDLE_TIMEOUT_SECONDS=60
NOLM_HD_IDLE_TIMEOUT_SECONDS=7200
#
# Should laptop mode tools control the hard drive power management settings?
#
CONTROL_HD_POWERMGMT=1
#
# Power management for HD (hdparm -B values)
#
BATT_HD_POWERMGMT=1
LM_AC_HD_POWERMGMT=254
NOLM_AC_HD_POWERMGMT=254
#
# Should laptop mode tools control the hard drive write cache settings?
#
CONTROL_HD_WRITECACHE=0
#
# Write cache settings for HD (hdparm -W values)
#
NOLM_AC_HD_WRITECACHE=1
NOLM_BATT_HD_WRITECACHE=0
LM_HD_WRITECACHE=0
###############################################################################
# Settings you probably don't want to touch
# -----------------------------------------
#
# It is usually not necessary to change these parameters. They are included
# for completeness' sake.
###############################################################################
#
# Change mount options on partitions in PARTITIONS? You don't really want to
# disable this. If you do, then your hard drives will probably not spin down
# anymore.
#
CONTROL_MOUNT_OPTIONS=1
#
# Dirty synchronous ratio. At this percentage of dirty pages the process
# which calls write() does its own writeback.
#
LM_DIRTY_RATIO=60
NOLM_DIRTY_RATIO=40
#
# Allowed dirty background ratio, in percent. Once DIRTY_RATIO has been
# exceeded, the kernel will wake pdflush which will then reduce the amount
# of dirty memory to dirty_background_ratio. Set this nice and low, so once
# some writeout has commenced, we do a lot of it.
#
LM_DIRTY_BACKGROUND_RATIO=1
NOLM_DIRTY_BACKGROUND_RATIO=10
#
# kernel default settings -- don't touch these unless you know what you're
# doing.
#
DEF_UPDATE=5
DEF_XFS_AGE_BUFFER=15
DEF_XFS_SYNC_INTERVAL=30
DEF_XFS_BUFD_INTERVAL=1
DEF_MAX_AGE=30
#
# This must be adjusted manually to the value of HZ in the running kernel
# on 2.4, until the XFS people change their 2.4 external interfaces to work in
# centisecs. This can be automated, but it's a work in progress that still
# needs some fixes. On 2.6 kernels, XFS uses USER_HZ instead of HZ for
# external interfaces, and that is currently always set to 100. So you don't
# need to change this on 2.6.
#
XFS_HZ=100
#
# Seconds laptop mode has to to wait after the disk goes idle before doing
# a sync.
#
LM_SECONDS_BEFORE_SYNC=2
Friday, August 7, 2009
HOWTO: Share your internet connection in Linux
HOW IT WORKS
If your interfaces are called something different, so you may need to replace these labels as needed.
PREPARE THE SERVER
The server computer will need a dhcp and a dnsmasq server. If you use vectorlinux (like I do), you can get the dnsmasq package from the repositories. This package includes a dhcp server, so it it should work perfectly for what we need. If you run some other distro, look for this package in your package management application, or build them from source now.
CONFIGURATION
You will need root access on your server box to do this... so make yourself root now, or get handy with that sudo command ;)
Here are tbe basic settings that we need in /etc/dnsmasq.conf
interface=eth0Everything else in the file you can leave alone.
dhcp-range=192.168.5.50,192.168.5.150,12h
Start the magic automatically on boot.
Now that everything has been configured, it is time to setup the firewall rules at boot time so that everything works as soon as the system starts.
Create a new text file and put it somewhere in your path... I have mine in /root/ and mine is calles ic.firewall
It can be called anything and really can be anywhere, so long as you remember it later on.
The file needs to have the following information
#!/bin/bash
#interface to the outside world
OUTSIDEIFACE="wlan0"
#interface to the inside private network
INSIDEIFACE="eth0"
INSIDEIPRANGE="192.168.5.0/24"
ifconfig $INSIDEIFACE down
ifconfig $INSIDEIFACE 192.168.5.1 up
killall dhcpcd
ifconfig $OUTSIDEIFACE down
iwconfig $OUTSIDEIFACE essid your_essid key your_encryption_key
#enable ip forwarding in the kernel
echo 1 > /proc/sys/net/ipv4/ip_forward
#firewall iptables rules
iptables -t nat -A POSTROUTING -o $OUTSIDEIFACE -j MASQUERADE
iptables -A FORWARD -i $OUTSIDEIFACE -o $INSIDEIFACE -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $INSIDEIFACE -o $OUTSIDEIFACE -j ACCEPT
iptables -A INPUT -j ACCEPT -p all -s $INSIDEIPRANGE -i $INSIDEIFACE
iptables -A OUTPUT -j ACCEPT -p all -d $INSIDEIPRANGE -o $INSIDEIFACE
#adding default route to the outside world
route add -net 0.0.0.0 $OUTSIDEIFACE
killall dhcpcd
dhcpcd $OUTSIDEIFACE
Save the file to your preferred location ( remember i'm using /root/firewall.ic ).
Add it to your rc.local so that it is read at boot time.
echo 'sh /root/firewall.ic \n'>> /etc/rc.d/rc.local
echo '/etc/rc.d/rc.dnsmasq restart \n'>> /etc/rc.d/rc.local
If you do not use vectorlinux, make sure you change the last line on that code to point to the correct path for your dnsmasq start script.
Also, now it's a good time to make sure that start script is set to executable mode
chmod +x /etc/rc.d/rc.dnsmasq
Now you need to restart your server computer, reboot it, and come back when you're done.
CONFIGURING A ROUTER AS A CLIENT
If you have a router that you want to use to to share this connection with multiple computers, here is what you need.
- Using a computer other than the Server, connect to the router and enter it's configuration interface.
- Disable DHCP server on the router.
- In the LAN section of your router, Set the IP address to 192.168.5.2 and the Netmask to 255.255.255.0
- Using a patch cable (ethernet cable), connect the Server's eth0 interface to one of the router's LAN ports.
- Make sure the router's WAN port is not connected to anything.
- Save settings on your router, and restart it (unplug it and wait 30 seconds if needed)
Connect to your router's wireless interface (or wired) using a client as you normally
If you use vectorlinux, You can safely use VLWifi to connect to the wireless access point now. Otherwise, find the documentation on your distro to connect to a wireless access point without using a networking daemon. (see 'man iwconfig')
IF YOU ARE NOT USING A ROUTER
Simply connect the Server's eth0 to the client's eth0 interface using a patch cable (ethernet cable)
Bring up your clients eth0
ifconfig eth0 up
dhcpcd eth0
CREDITS
Enjoy ;)
Thursday, June 11, 2009
Vectorlinux GUI installer moves to a new home
The new home offers trac for bug tracking.
the speedy branch is just about ready for testing.
Thursday, May 28, 2009
Howto setup freenx server on your VectorLinux box
This howto explains how to setup a basic nx environment using the freenx-server.
Freenx-server is the free (Open Source) implementation of the commercial NX project.
WARNING: Testing the outcome of this howto requires you to use a proprietary client program, which VectorLinux does not distribute. You can however get such a program from here for a linux box and for a windows box here. This program is available free of charge, however it is not Open Source, so if you have a problem with that, perhaps you should stop here, or find you a free (open source) client.
PREPARE SERVER
Before you begin, you will need a couple things in your server box.
- Make sure your ssh server is running and working
- Install xdialog
- Install freenx-server
- Install netcat (also known as "nc")
- Prepare a client (last step)
SOFTWARE INSTALLATION
Make sure you have the "testing" repository enabled.
# slapt-get -i freenx-server Xdialog netcat
SSH SETTINGS
You may need to make a couple of changes to your ssh settings. Make sure these options of the file are setup just like here
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys2
You may leave everything else as is. These are the only important settings for the nx server.
After you install your freenx-server package, you will need to create the default configuration file, This can be easily done by just copying the default provided with the package
# cp /usr/NX/etc/node.conf.new /usr/NX/etc/node.conf
Now, we need to setup the nx environment
cd into the NX dir
# cd /usr/NX/bin
# ./nxsetup --purge --clean --install --setup-nomachine-key
That will create everything you need for your nx server. Most likely you'll receive some error messages about RDP and CUPS not being setup, but this is OK (unless you really need to use RDP and remote printing directly from the client... that's something I'm not getting into)
After that, you will need to add user accounts to your server, so execute the following commands while still in the same dir. Repeat this step for every user in your system who will have access to the nx environment. The user you specify to the nx server MUST exist in the system first.
# ./nxserver --adduser your_user_name_here
START THE SERVER
It is now time to start the server to do some testing, while in the same dir, execute this command
# ./nxserver --start
TEST YOUR ENVIRONMENT
From your client box, fire up your nx client.
Using the nxclient is pretty much a straight forward process. It features a graphical wizard that guides you through the process. Basically you'll create a new session. You will need the basic information like host address and port. User name and password of the user account at the remote host. The tricky part to this is the one that follows.
Once you finish the wizard, you want to click the "configure" button.
If you have GNOME or KDE installed, you can just select 'unix' and 'KDE' or 'GNOME' which ever one you have on the server, otherwise select 'Custom' and read the following step.
Under "Desktop" select 'unix' and 'custom' from the drop down boxes and click the "Settings" button. Under "Application", select "Run the following command" and enter the command that starts your default window manager on the remote location. This can be something like 'startxfce4' or 'icewm-session' or 'startlxde' depending of which window manager you use.
Under "Options" select 'New Virtual Desktop' and click OK
Under "Display" on the remaining dialog, select "Fullscreen" or your prefered desktop size
Click "Save"
Click "Ok"
After that, you'll just need to enter the password for your remote user account, click "Login" and off you go.