Magneto
November 7th, 2004, 01:54 PM
I use Ubuntu on my Dell Latitude C640 laptop and since I might not have the same environment around me as I would with a stationary PC, I must configure my laptop to change certain system settings while mobile.
The instructions laid out here pertain to any laptop setup and the lesson on creating rc scripts can be applied by anyone regardless of the type of system.
If you have an ati radeon 7500 M7 32mb video card you can use my XF86Config-4 files - just change the XF86Config-4.2 file to correctly reflect your monitor's abilities.
Configuring XFree86 is beyond the scope of this document.
And if you have multiple network devices you can use the eth0 script as well. Configuration of networking devices is also beyond the scope of this document.
The first step is analyzing the problem.
What are my needs?
1. I need both my wireless card card working and the onboard ethernet working while I am at my workstation.
2. By default I only want my wireless card working while mobile.
3. I need different XFree86/Xorg settings based on whether I'm at my workstation and connected to an external monitor or mobile using the Laptop's LCD.
Now that I know what I need, how do I go about finding a solution and applying it?
Well, I know from my past experiences with Linux/Unix that when the system starts initialization it looks to /etc/inittab for the runlevel to start. Basically runlevels are different levels the system can operate under which load or do not load certain programs. This is useful for a number of system administration tasks including our present situation.
In Debian, which Ubuntu is based on, you have 3 different actions that you must address. Here's the process:
1.)When you power on your computer, your bootloader can tell the system what runlevel to start off with or it can not specify anything and defer to the inittab default setting. The default bootloader in Ubuntu is GRUB which is the Grand Unified Bootloader.
2.)Next your init configuration file located at /etc/inittab, tells the system to go with the default runlevel, unless your bootloader has specified a particular runlevel
3.)Now /etc/init.d/rc begins to execute the scripts from the runlevel passed to it from their corresponding directory - for example in runlevel 2, rc looks in /etc/rc2.d/ for executable files.
With that in mind, here's my solution -
1.) Modify Grub to add a Mobile option to my boot menu. Since I mostly use my laptop at my desk connected to my CRT and keyboard etc, I will have my Docked/Stationary configuration be the default.
2.)Create 2 scripts - one to modify my XFree86 settings and another to modify my eth0 interface configuration.
3.)Place my scripts somewhere /etc/init.d/rc can see them.
Now I can address my solution.
1.) Modify Grub.
The Grub configuration file is /boot/grub/menu.lst . When you startup your computer and it boots it launches Grub and if you press the Esc key when prompted a menu will appear. The listings in that menu come from the entries in /boot/grub/menu.lst. We now will modify this file.
so open up a terminal. By default in Ubuntu you are using gnome. If you right-click your desktop the first item you will see on the resulting menu is Open Terminal.
type the following at the command line
sudo nano -w /boot/grub/menu.lst
page down to the bottom of this file and you will find the following :
## ## End Default Options ##
title Ubuntu
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro quiet splash
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Ubuntu, kernel 2.6.8.1-3-386 (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro single
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Memory test
root (hd0,0)
kernel /boot/memtest86+.bin
The FIRST entry in this file that looks similar to this is your default boot setting
title Ubuntu
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro quiet splash
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
Make the changes in red
## ## End Default Options ##
title Ubuntu Docked
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro quiet splash
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Ubuntu Undocked
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro quiet splash 3
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Ubuntu, kernel 2.6.8.1-3-386 (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro single
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Memory test
root (hd0,0)
kernel /boot/memtest86+.bin
Note the RED 3 - this sets Grub to tell our system to start at runlevel 3
The other changes in the " title Ubuntu " area are just labels - you don't have to use the word docked or undocked - but using some type of label that you can easily interpret is the best way to set it up.
press Control+o to save your changes - and Control+x to exit nano
Here's what my /boot/grub/menu.lst file looks- ***Note*** I have my own kernel compiled by me listed here in addition to another OS. I normally would NOT leave all the commented out lines in there but Ubuntu has a grub-install command that I guess uses them so I left them alone
2.)Create our Scripts.
A.)xsetup
I have two XF86Config-4 scripts that I use. One is for using the CRT connected to my laptop and the other is for using the LCD. The one for use with the CRT is labeled XF86Config-4.2 because it will be used with runlevel 2 which is our system default setup in /etc/inittab. The file for the LCD display is named XF86Config-4.3 for use in runlevel 3 which is our mobile/undocked runlevel. These files are both located in the /etc/X11 directory.
Here's a link to my XF86Config-4.2 file.
from a terminal do the following
sudo nano -w /etc/init.d/xsetup
xsetup you can copy this and paste it into your terminal by hitting Control+Shift+v
#!/bin/sh
case "$1" in
start|restart|force-reload)
echo -n "Configuring the X server: "
echo cp /etc/X11/XF86Config-4.$RUNLEVEL /etc/X11/XF86Config-4
cp /etc/X11/XF86Config-4.$RUNLEVEL /etc/X11/XF86Config-4
echo "Done"
;;
lcd)
echo -n "Configuring X for LCD: "
cp /etc/X11/XF86Config-4.3 /etc/X11/XF86Config-4
echo "Done"
;;
crt)
echo -n "Configuring X for CRT: "
cp /etc/X11/XF86Config-4.2 /etc/X11/XF86Config-4
echo "Done"
;;
stop)
echo To stop X, kill the gdm process manually
ps -ef | grep gdm
echo "Done"
;;
*)
echo "Usage: /etc/init.d/xsetup {start|lcd|crt|stop|restart|force-reload}"
exit 1
;;
esac
exit 0
This is useless if you don't have different XF86Config-4 files.
save the file like you did previously and exit nano
now type
sudo chmod +x /etc/init.d/xsetup
sudo ln -s /etc/init.d/xsetup /etc/rc2.d/S20xsetup
sudo ln -s /etc/init.d/xsetup /etc/rc3.d/S20xsetup
B.) eth0 script
This script is run only in init 2 or runlevel 2 which is the default and its for another network that my laptop will connect to via the onboard ethernet. By setting it up this way when I am mobile aka runlevel 3 and not likely to be constrained by ethernet cables it wont be configured and I can always run this script at anytime to change things.
sudo nano -w /etc/init.d/eth0
copy and paste this modify it to your system's needs
#!/bin/sh
case "$1" in
start|reload|force)
echo -n "Setting up Onboard Ethernet: "
echo eth0 192.168.2.17
ifconfig eth0 192.168.2.17
echo "Done"
;;
stop)
echo -n "Stopping Onboard Ethernet: "
ifconfig eth0 down
echo "Done"
;;
gatew)
echo -n "Setting Onboard Ethernet as Gateway Interface: "
echo eth0 192.168.2.17
ifconfig eth0 192.168.2.17
echo route del default gw 192.168.5.73 eth1
route del default gw 192.168.5.73 eth1
echo route add default gw 192.168.2.77 eth0
route add default gw 192.168.2.77 eth0
echo "Done"
;;
primary)
echo Setting Onboard Ethernet as Primary Interface
echo -n "Shutting down wireless: "
ifconfig eth1 down
echo Bringing up eth0
ifconfig eth0 192.168.2.17
echo route add default gw 192.168.2.77 eth0
route add default gw 192.168.2.77 eth0
echo "Done"
;;
noprimary)
echo -n "Switching back to Wireless: "
ifconfig eth0 down
ifconfig eth1 up
ifconfig eth1 192.168.5.17
echo route add default gw 192.168.5.73 eth1
route add default gw 192.168.5.73 eth1
echo "Done"
;;
*)
echo "Usage: /etc/init.d/eth0 {start|reload|force|stop|gatew|primary|noprimary}"
exit 1
;;
esac
exit 0
now type
sudo chmod +x /etc/init.d/eth0
sudo ln -s /etc/init.d/eth0 /etc/rc2.d/S20eth0
this is so I can run it from the commandline
sudo ln -s /etc/init.d/eth0 /usr/bin/eth0
That's it!!!!!!!!!!
Now when you start your system by default it will be configured to use your external Monitor and onboard ethernet.
And when you select your 2nd boot option for Ubuntu Undocked your LCD settings will automatically be applied and your onboard ethernet will not be setup.
Those scripts have a few extra helpful items in them ;)
The instructions laid out here pertain to any laptop setup and the lesson on creating rc scripts can be applied by anyone regardless of the type of system.
If you have an ati radeon 7500 M7 32mb video card you can use my XF86Config-4 files - just change the XF86Config-4.2 file to correctly reflect your monitor's abilities.
Configuring XFree86 is beyond the scope of this document.
And if you have multiple network devices you can use the eth0 script as well. Configuration of networking devices is also beyond the scope of this document.
The first step is analyzing the problem.
What are my needs?
1. I need both my wireless card card working and the onboard ethernet working while I am at my workstation.
2. By default I only want my wireless card working while mobile.
3. I need different XFree86/Xorg settings based on whether I'm at my workstation and connected to an external monitor or mobile using the Laptop's LCD.
Now that I know what I need, how do I go about finding a solution and applying it?
Well, I know from my past experiences with Linux/Unix that when the system starts initialization it looks to /etc/inittab for the runlevel to start. Basically runlevels are different levels the system can operate under which load or do not load certain programs. This is useful for a number of system administration tasks including our present situation.
In Debian, which Ubuntu is based on, you have 3 different actions that you must address. Here's the process:
1.)When you power on your computer, your bootloader can tell the system what runlevel to start off with or it can not specify anything and defer to the inittab default setting. The default bootloader in Ubuntu is GRUB which is the Grand Unified Bootloader.
2.)Next your init configuration file located at /etc/inittab, tells the system to go with the default runlevel, unless your bootloader has specified a particular runlevel
3.)Now /etc/init.d/rc begins to execute the scripts from the runlevel passed to it from their corresponding directory - for example in runlevel 2, rc looks in /etc/rc2.d/ for executable files.
With that in mind, here's my solution -
1.) Modify Grub to add a Mobile option to my boot menu. Since I mostly use my laptop at my desk connected to my CRT and keyboard etc, I will have my Docked/Stationary configuration be the default.
2.)Create 2 scripts - one to modify my XFree86 settings and another to modify my eth0 interface configuration.
3.)Place my scripts somewhere /etc/init.d/rc can see them.
Now I can address my solution.
1.) Modify Grub.
The Grub configuration file is /boot/grub/menu.lst . When you startup your computer and it boots it launches Grub and if you press the Esc key when prompted a menu will appear. The listings in that menu come from the entries in /boot/grub/menu.lst. We now will modify this file.
so open up a terminal. By default in Ubuntu you are using gnome. If you right-click your desktop the first item you will see on the resulting menu is Open Terminal.
type the following at the command line
sudo nano -w /boot/grub/menu.lst
page down to the bottom of this file and you will find the following :
## ## End Default Options ##
title Ubuntu
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro quiet splash
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Ubuntu, kernel 2.6.8.1-3-386 (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro single
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Memory test
root (hd0,0)
kernel /boot/memtest86+.bin
The FIRST entry in this file that looks similar to this is your default boot setting
title Ubuntu
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro quiet splash
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
Make the changes in red
## ## End Default Options ##
title Ubuntu Docked
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro quiet splash
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Ubuntu Undocked
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro quiet splash 3
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Ubuntu, kernel 2.6.8.1-3-386 (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro single
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
title Memory test
root (hd0,0)
kernel /boot/memtest86+.bin
Note the RED 3 - this sets Grub to tell our system to start at runlevel 3
The other changes in the " title Ubuntu " area are just labels - you don't have to use the word docked or undocked - but using some type of label that you can easily interpret is the best way to set it up.
press Control+o to save your changes - and Control+x to exit nano
Here's what my /boot/grub/menu.lst file looks- ***Note*** I have my own kernel compiled by me listed here in addition to another OS. I normally would NOT leave all the commented out lines in there but Ubuntu has a grub-install command that I guess uses them so I left them alone
2.)Create our Scripts.
A.)xsetup
I have two XF86Config-4 scripts that I use. One is for using the CRT connected to my laptop and the other is for using the LCD. The one for use with the CRT is labeled XF86Config-4.2 because it will be used with runlevel 2 which is our system default setup in /etc/inittab. The file for the LCD display is named XF86Config-4.3 for use in runlevel 3 which is our mobile/undocked runlevel. These files are both located in the /etc/X11 directory.
Here's a link to my XF86Config-4.2 file.
from a terminal do the following
sudo nano -w /etc/init.d/xsetup
xsetup you can copy this and paste it into your terminal by hitting Control+Shift+v
#!/bin/sh
case "$1" in
start|restart|force-reload)
echo -n "Configuring the X server: "
echo cp /etc/X11/XF86Config-4.$RUNLEVEL /etc/X11/XF86Config-4
cp /etc/X11/XF86Config-4.$RUNLEVEL /etc/X11/XF86Config-4
echo "Done"
;;
lcd)
echo -n "Configuring X for LCD: "
cp /etc/X11/XF86Config-4.3 /etc/X11/XF86Config-4
echo "Done"
;;
crt)
echo -n "Configuring X for CRT: "
cp /etc/X11/XF86Config-4.2 /etc/X11/XF86Config-4
echo "Done"
;;
stop)
echo To stop X, kill the gdm process manually
ps -ef | grep gdm
echo "Done"
;;
*)
echo "Usage: /etc/init.d/xsetup {start|lcd|crt|stop|restart|force-reload}"
exit 1
;;
esac
exit 0
This is useless if you don't have different XF86Config-4 files.
save the file like you did previously and exit nano
now type
sudo chmod +x /etc/init.d/xsetup
sudo ln -s /etc/init.d/xsetup /etc/rc2.d/S20xsetup
sudo ln -s /etc/init.d/xsetup /etc/rc3.d/S20xsetup
B.) eth0 script
This script is run only in init 2 or runlevel 2 which is the default and its for another network that my laptop will connect to via the onboard ethernet. By setting it up this way when I am mobile aka runlevel 3 and not likely to be constrained by ethernet cables it wont be configured and I can always run this script at anytime to change things.
sudo nano -w /etc/init.d/eth0
copy and paste this modify it to your system's needs
#!/bin/sh
case "$1" in
start|reload|force)
echo -n "Setting up Onboard Ethernet: "
echo eth0 192.168.2.17
ifconfig eth0 192.168.2.17
echo "Done"
;;
stop)
echo -n "Stopping Onboard Ethernet: "
ifconfig eth0 down
echo "Done"
;;
gatew)
echo -n "Setting Onboard Ethernet as Gateway Interface: "
echo eth0 192.168.2.17
ifconfig eth0 192.168.2.17
echo route del default gw 192.168.5.73 eth1
route del default gw 192.168.5.73 eth1
echo route add default gw 192.168.2.77 eth0
route add default gw 192.168.2.77 eth0
echo "Done"
;;
primary)
echo Setting Onboard Ethernet as Primary Interface
echo -n "Shutting down wireless: "
ifconfig eth1 down
echo Bringing up eth0
ifconfig eth0 192.168.2.17
echo route add default gw 192.168.2.77 eth0
route add default gw 192.168.2.77 eth0
echo "Done"
;;
noprimary)
echo -n "Switching back to Wireless: "
ifconfig eth0 down
ifconfig eth1 up
ifconfig eth1 192.168.5.17
echo route add default gw 192.168.5.73 eth1
route add default gw 192.168.5.73 eth1
echo "Done"
;;
*)
echo "Usage: /etc/init.d/eth0 {start|reload|force|stop|gatew|primary|noprimary}"
exit 1
;;
esac
exit 0
now type
sudo chmod +x /etc/init.d/eth0
sudo ln -s /etc/init.d/eth0 /etc/rc2.d/S20eth0
this is so I can run it from the commandline
sudo ln -s /etc/init.d/eth0 /usr/bin/eth0
That's it!!!!!!!!!!
Now when you start your system by default it will be configured to use your external Monitor and onboard ethernet.
And when you select your 2nd boot option for Ubuntu Undocked your LCD settings will automatically be applied and your onboard ethernet will not be setup.
Those scripts have a few extra helpful items in them ;)