Answers 103

From LXF Wiki

Answers 103

<title>Memory for details</title>

<question>Is there a program that could report the used RAM slots in a machine? What's in them from the point of view of RAM per chip, bus speed, and so on? Crucial has an ActiveX utility for IE that does the job, but I'm not running Windows, and I don't want to install a browser add-on that has that much access to my hardware. </question>

<answer>I know of two programs that will display this information: lshw (http://ezix.org/project/wiki/HardwareLiSter) is a terminal program that shows plenty of information about your computer system, including specifics of the memory. This is the sort of information it gives.

*-memory
  description: System Memory
 physical id: 40
 slot: System board or motherboard
 size: 4GB
 *-bank:0
   description: DIMM SDRAM
Synchronous 800 MHz (1.2 ns)
   product: PartNum0
   vendor: Manufacturer0
   physical id: 0
   serial: SerNum0
   slot: DIMM0
   size: 1GB
   width: 64 bits
   clock: 800MHz (1.2ns)
 *-bank:1

For a graphical alternative, try HardInfo (http://hardinfo.berlios.de) which is also on the LXF DVD each month. This shows a different selection of information about your computer. Between the two, they should tell you all they need Incidentally, the output from these programs can be extremely useful to us when we're trying to answer your questions. </answer>

<title>Address watching</title>

<question>I have access to my PC at work using the corporate VPN. For years the IP address of my work PC hasn't changed, but lately it seems that it changes once or twice a week. Is there any simple way that my PC (Kubuntu 7.10) could send me an email reporting the new address when it changes? </question>

<answer>Before you do anything else, check with your employer that this is acceptable to them. Having access to your work network from home is convenient; losing your job over it most certainly is not! I don't know of a specific utility for doing this (cue about 50 emails from LXF readers enlightening me) but it is easy to do with this short script, which you can run via Cron.

#/bin/sh
IPADDRESS=$(/sbin/ifconfig eth0 | sed -n `s/.*inet
addr:\([^ ]*\).*/\1/p')
if [[ "${IPADDRESS}" != $(cat ~/.current_ip) ]]
then
  echo "Your new IP address is ${IPADDRESS}" |
mail -s "IP address change" you@your.mail
  echo ${IPADDRESS} >|~/.current_ip
fi

The real business is done in the second line, which uses a regular expression to extract the current IP address from the output of ifconfig. This is compared with the address stored on a previous run; we use ~/.current_ip to store the address here, but any location that is writable by you and unlikely to be touched by anyone else will do. If the address is different, it sends you an email using the mail command and writes the new address into .current_ip. The mail command is the standard program for sending emails from the command line or scripts, but it does require that you have a local SMTP installed. If mail and its dependencies are not already installed on your computer, it will be easier to use SendEmail, installable from Synaptic. This can use any SMTP server. Replace the mail command above with

sendEmail -s smtp.work.com -f you@work.com -t
 you@home.co.uk -u "IP address change" -q

The first argument is the address of the mail server at work (you can remove the -q (quiet) option for testing). </answer>

<title>Offline apt-get</title>

<question>I don't currently have a net connection to my Ubuntu box, but I do have access to a fast connection at college. Is there a tool I can use on the box that's connected to the net (a Windows PC) to grab dependencies? What I'm looking for is a way to enter the name of the software that I want to install and get back a list of dependencies that I can run in a Windows app to fetch the files and any others that the next one depends on. </question>

<answer> There are at least two ways to do this. The quick and easy option is to use the `Generate package download script' option in Synaptic. Mark the packages you want to install, then select this option from the File menu, which will generate a shell script that you can run to download the packages. Then you transfer the packages to your Ubuntu box and either put them in /var/cache/apt/archives or use the `Add downloaded packages' menu option in Synaptic to install them. The main disadvantage of this method is that the script requires wget, so you need this installed on the computer you use for the downloading. An alternative is to use apt-get from the command line with the --print-uris option. Apt-get will automatically try to install all dependencies, and the --print-uris option outputs the URIs of all the files it needs. You can use grep and cut to extract the URIs from the output with

apt-get --print-uris --yes install pkgspec | grep ^\' |
cut -d\' -f2 >downloads.list

For example, running this with `postgrey' instead of the word `pkgspec' creates a file containing

http://security.ubuntu.com/ubuntu/pool/universe/
libn/libnet-dns-perl/libnet-dns-perl_0.59-
1build1.1_i386.deb
http://gb.archive.ubuntu.com/ubuntu/pool/
universe/libb/libberkeleydb-perl/libberkeleydb-
perl_0.31-1_i386.deb
http://gb.archive.ubuntu.com/ubuntu/pool/main/
libd/libdigest-sha1-perl/libdigest-sha1-perl_2.11-
1build1_i386.deb
http://gb.archive.ubuntu.com/ubuntu/pool/main/
libd/libdigest-hmac-perl-dfsg/libdigest-hmac-perl_
1.01-5_all.deb
http://gb.archive.ubuntu.com/ubuntu/pool/
universe/libi/libio-multiplex-perl/libio-multiplex-
perl_1.08-3_all.deb
http://gb.archive.ubuntu.com/ubuntu/pool/
universe/libn/libnet-cidr-perl/libnet-cidr-perl_0.11-
1_all.deb
http://gb.archive.ubuntu.com/ubuntu/pool/
universe/libn/libnet-ip-perl/libnet-ip-perl_1.25-2_
all.deb
http://gb.archive.ubuntu.com/ubuntu/pool/
universe/libn/libnet-server-perl/libnet-server-perl_
0.94-1_all.deb
http://gb.archive.ubuntu.com/ubuntu/pool/
universe/p/postgrey/postgrey_1.27-4_all.deb

As you can see, this includes the dependencies as well as the program itself. Copy download.list to a USB flash drive to take it to the computer with the faster internet connection. Many FTP programs and download managers will read a list of download URLs from a file, such as

wget --input-file myurilist

You can give more than one package name as `pkgspec' However, you do need to run the apt-get update from time to time to keep up to date. If you are using another connection because your home computer is on a slow dial-up, there's no problem, as apt-get update doesn't download much. If you have no internet access at all, you can run apt-get --print-uris update and download the files elsewhere, then copy, unpack and rename the Sources files in /var/lib/apt/lists. </answer>

<title>User conflicts</title>

<question>I have installed Ubuntu from LXF100 and find the setup very impressive. However, when I start the PC from scratch ­ having shut down completely ­ all my settings in Ubuntu have disappeared and I have to re install and reset everything. I lose Thunderbird account settings, all updates and even saved documents. This problem does not occur with the SUSE 0.3 installation that I have installed on the same box. Can you advise please on what to do to avoid this recurring? At present I am not shutting down for fear of losing all. </question>

<answer>Are you using the same username and home directory for both Ubuntu and SUSE? If so, this problem is caused by the two distros allocating different numeric user IDs for that user. As a result, the SUSE user can write to the directory but the Ubuntu user cannot. While it is possible to change the user ID on one computer to the same as the other in order to enable the same user in both distros to write to the directory, this brings its own set of problems. The distros probably have different versions of some programs, which can cause conflicts when saving settings. A newer version of a program can usually read the settings saved by an older version, but the reverse is not always true. The safest way to work with two (or more) distros, is to have a separate user directory for each one. You can use the same user name, but you need to change the path to the home directory. For example, you could have the username `pearse' on both distros, but make the user directories /home/pearse-suse and /home/pearse-ubuntu. To change the home directory in SUSE, start Yast and go to User Management. Select your user and click on the Edit button, go to the Details tab and change the home directory to, say, pearse-suse. Make sure the Move to New Location box is ticked and press Accept to make the changes. If you do this while logged in as your user, you may find yourself unable to log out, so press Ctrl-Alt-Backspace to kill and restart X, then log in again. It is also possible to do this by logging out of the desktop and editing the passwd file in a root console, by running vipw, changing the home directory for your user and saving the file. Then do

mv /home/pearse /home/pearse-suse

to move the directory. On the Ubuntu half of your system, you can use a root console in the same way or use the System > Administration-Users and Groups menu item to run the user manager. You should open a terminal before you do this, then go into the user manager, select your user and press Properties, go to the advanced tab and change the home directory. You should also change the user's main group to `users' to match the settings in SUSE. Ubuntu doesn't have the option to rename the home directory, so go to the terminal you opened earlier (you cannot open one after you've changed the home directory), and run

sudo mv /home/pearse /home/pearse-ubuntu

then log out and back in again. The GUI user management tools on both distros should indicate the numeric UID for the user. Both distros default to 1000 for the first user, but if they don't match, you should change the one for Ubuntu. You will need to do this from a root console, while not logged-in to the desktop, with

sudo -i
vipw
#make the change
chown -R pearse: ~pearse

The first line gives you root access; vipw works as above (never edit /etc passwd directly); and the last line applies the changed values to your home directory and all its contents. Finally, make sure everything in the home directories is owned by the same user by running the following as root:

chown -R pearse: /home/pearse

Of course, this now means that you have two separate home directories, with separate mail folders and other documents split between the two. While the common username and UID mean you can access both home directories from either distro, it would be easier to make common files available to both, which can be done with symlinks. From a terminal in SUSE, run commands like this

ln -s ../pearse-suse/Mail ../pearse-ubuntu/Mail
ln -s ../pearse-suse/documentsl ../pearse-ubuntu/documents
ln -s ../pearse-suse/photos ../pearse-ubuntu/photos

to ensure that the same directories (and therefore the same data), are available to both distros. Do not do this for any directories that contain settings information, as an upgrade of a software package on one distro could break things for one or both distros. That's the main reason for keeping the two home directories separate. </answer>

<title>No disk in Knoppix</title>

<question>I have just bought a Compaq Desktop SR5280CF and tried to use a Live CD. I tried Mepis, PCLinuxOS and OpenSUSE; all three are able to boot in the computer, but the hard disk is not detected. Neither Konqueror nor KDiskFree show hda1 or sda1. This computer comes with Vista and seems to be running OK. Is there anything wrong with this computer or Linux, or is it something I've missed? </question>

<answer>We had the same problem with a new laptop once, and it was down to the SATA settings in the BIOS. Our computer lets you choose whether or not to use AHCI for the SATA interface (Advanced Host Controller Interface is a standard for SATA communication). We have to disable AHCI on the rare occasions that we need to boot Windows (what was that about Linux's inferior hardware support?) and if we forget to re-enable this, Knoppix can't find the hard disk. Ubuntu and Gentoo see the disk, but others do not. Check your BIOS settings and try changing anything related to SATA protocols. Or you can try a different Live CD ­ Ubuntu worked fine with our system. </answer>

<title>Passwords and partitions</title>

<question>I wanted to try a simple, small distro yesterday and fired up Knoppix 3.2 from LXF63's DVD. Everything went just fine except that I don't know the root password. I tried all sorts of combinations, such as `visitor', `Knoppix' `lxformat' and so on, but none of them are correct. I looked in some back issues (LXF62 and LXF63), but nowhere did you guys tell us how to access the root account. I want to use GParted but can only do so as root. In the meantime, can you tell me a neat way to rename a partition on a USB hard drive under Fedora 7? I've managed to change the permissions (which were all wrong for what I wanted to do) but cannot for the life of me figure out how to rename it. </question>

<answer>You have us a little confused here (who said "what's new?"), because Knoppix 3.2 wasn't on LXF63's DVD ­ that had version 3.7. Do you mean an earlier Linux Format coverdisc? To make it even more confusing, Knoppix 3.7 does not include GParted, only QtParted (because Knoppix is a KDE-based distro). However, the answer is the same whichever program you need to run as root: open a terminal by selecting System > Konsole from the K menu, then type su at the prompt. This will give you root access. There is no password, so you can run any programs you want from here. Trying to run programs that demand root access directly from the menu has variable results. Most pop up a requester asking for the root password, which doesn't work when there is no password. Others, like QtParted, run as root anyway. Using su in a terminal though lets you run anything as root. What do you mean by `renaming a partition'? If you want to change the numbering used in the /dev/hdN device nodes (because creating and deleting partitions has left them out of order, for example), this can be done with Fdisk. Run

 fdisk /dev/hda

then press P to see the partition table, X to enter expert mode and F to fix the partition order. Finally, press W to write your changes to the disk. If you want to change the filesystem label (often referred to the volume name), the method depends on the filesystem in use. This is easiest with an ext2/3 filesystem, where you use

 e2label /dev/sda1 newname

The equivalent command for ReiserFS is

 reiserfstune --label newname /dev/sda1

and for XFS you would use

 xfs_admin -L newname /dev/sda1

The maximum length for a filesystem label is sixteen characters for ext2/3 and ReiserFS, with XFS being limited to twelve characters. As you mention permissions, I doubt you are using an MS-DOS filesystem on this disk, but for completeness, you need the Mtools package to change a FAT filesystem label. This uses a global configuration file in /etc/mtools mtools.conf and a per-user file in ~/.mtoolsrc. You need to map hard drive partitions to MS-DOS style drive letters in here, with a section like

 drive D:
  file="/dev/sda1"

Then you can change the volume label with

 mlabel D:newname

You can also run mlabel without the new volume name, in which case it will display the old volume name and prompt for a new one. </answer>

<title>Lost moon</title>

<question>I've installed Kmoon and KWeather in both Dapper Drake and now in Gutsy, but neither runs. They don't show up in the menus, and when I try to start from Konsole, I get "command not found" I used to love both these applets. Locate finds the files; but perhaps they are not installed in the correct directories? I'm a beginner and don't know how to evaluate (or correct) the situation if that's what is wrong. </question>

<answer> Neither of these are standalone programs, they are both applets for KDE's Kicker taskbar. This means you cannot `run' them, either from a menu item or a shell. You can see exactly what files a packages installs using dpkg. For example

dpkg -L kmoon

shows all the files in the kmoon package. A quick way to find any programs installed by a package is to search for paths containing `bin/' since programs are generally installed into one of /bin, /sbin, /usr/bin or /usr/sbin, like this:

dpkg -L kmoon | grep bin/

In this case it gives no output, because no executable programs are installed. To use these programs, right-click on an empty area of the Kicker panel and select `Add Applet to Panel...' This opens a window detailing all the Kicker applets installed on your system, from which you can select those that you want to add. If there is no blank space on your panel, click on the drag bar to the left of an existing applet and go to the panel menu from there. </answer>

<title>Freeing your fonts</title>

<question>I often work on documents and spreadsheets from work that use the Microsoft fonts, Times and Arial, which I do not have. I have downloaded the Liberation fonts from Red Hat to use as replacements, after reading about them in LXF95. After I installed them in my /usr/share/fonts/truetype folder the fonts are now available in OpenOffice.org. How can I find out which font OpenOffice.org is using instead of the Microsoft font and change that to the Liberation equivalent? Also, how can I get Firefox to use the Liberation fonts when Microsoft fonts are specified for a web page? I have read in the Linux Format Special on OpenOffice.org that OpenOffice.org creates smaller files than those made by Microsoft Office, but I am finding this far from the case. OpenOffice.org saves a blank .doc file at 65KB and a blank .xls spreadsheet at 95KB. What is going on here? I am using version 2.2 of OpenOffice.org as supplied with Ubuntu 7.04 from the LXF94 DVD. </question>

<answer> The tarball from Red Hat contains only the fonts ­ you'll need a little more to use them in place of the Microsoft fonts. How you do this depends on whether the fonts are installed globally, as you did in /usr/share/fonts, or only for a user, in ~/.fonts. In the former case, add this code to /etc/fonts/local.conf, otherwise add it to ~/.fonts/local.conf. In either case, create the file if it does not exist.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
 <match target="pattern">
  <test qual="any" name="family"><string>Times
New Roman</string></test>
  <edit name="family" mode="assign"><string>Li
beration Serif</string></edit>
 </match>
 <match target="pattern">
  <test qual="any" name="family"><string>Arial</
string></test>
  <edit name="family" mode="assign"><string>Li
beration Sans</string></edit>
 </match>
 <match target="pattern">
  <test qual="any" name="family"><string>Courie
r</string></test>
  <edit name="family" mode="assign"><string>Li
beration Mono</string></edit>
</match>
</fontconfig>

This means any program that tries to load one of the Microsoft fonts will use the Liberation alternative, so all web pages will look much like their authors intended, even when you don't have any Microsoft fonts installed. It also means that you don't need to change any documents you've created in OpenOffice.org, as they can reference the Microsoft fonts and work equally well when you send them to Windows users. You can get more information on this, and the above code, at http://uwstopia.nl/blog/2007/05/free-your-fonts. In our experience, OpenOffice.org saves much smaller files than Word and Excel, but an empty file is not a typical example. Word saves a lot of redundant information in a file, so loading a document into OpenOffice.org and saving it as a .doc file will usually reduce the size, but the greatest reduction is when you use Open Document files, as these are compressed with zip. </answer>

<title>Firewall basics</title>

<question>I received this answer from my friend to a question I asked. "Have you set up an appropriate Iptables rule? You need something like

iptables -A INPUT -i eth0 -p tcp --syn -m state -- state NEW -j NFQUEUE

If the box is a remote system, you should exclude the SSH port or whatever you use to connect to it." I don't get how to "exclude an SSH port" and I, can't ask him again, so I would appreciate any help you can give. </question>

<answer>Without knowing the question you asked your friend, this is difficult to answer with any degree of precision, so here is a more general response on the use of Iptables. The Linux Netfilter software that provides firewalling is built into the kernel, and Iptables is the user program that sets up the firewall rules for it ­ the one you have given here filters incoming packets on eth0 that are requesting a new TCP connection (--syn). Iptables is very powerful, but also very low-level. This means you can give the firewall specific instructions and it will do exactly what you tell it to, irrespective of whether that was really what you wanted it to do. As a result, using Iptables without some detailed knowledge of it is quite dangerous. You could lock yourself out of a computer, or you could set up rules that you believe protect the system when they actually let all manner of potentially dangerous traffic through. To set up Iptables safely, you need one of two things. Either a good book or tutorial on the subject and the time to read and understand it, or a graphical front-end. There are a number of good front-ends available, which all perform basically the same function ­ provide an easy interface to tell the software what you want to filter, then generate the Iptables rules. The available packages include Firewall Builder (www.fwbuilder.org), Guarddog (www.simonzone.com/software/guarddog) and Shoreline Firewall (www.shorewall.net). The first is a GTK program that fits in well with a Gnome or Xfce desktop, while Guarddog is a KDE program. They offer similar features, but with a different approach. Shoreline Firewall is a script-based program that is harder to set up the first time, but provides more flexibility. Any of these are capable of protecting your system, so try them and see which you like best. The comment about the SSH port is because the rule you were given blocks all TCP traffic originating from outside. This is fine if you are not running any sort of server, but if this is a machine you access remotely via SSH, you would also lock yourself out. The advice is to add a rule that allows SSH traffic ­ that is, traffic to port 22, the SSH port ­ to pass, so that you can still connect remotely. This is easily done by setting an option on any of the programs mentioned previously. Of course, if this computer is not a remote server, this advice is irrelevant. If you are dealing with a remote machine, running a GUI program may not be possible. However, these programs all generate standard Iptables rule sets, so you can run them on a local box, test the rules to ensure they do what you need, then transfer the rules to the remote computer. </answer>

<title>DIY packages</title>

<question>I usually uninstall apps by using apt-get remove in Ubuntu. Recently, I have started compiling programs from source, but then have problems uninstalling them. I tried to use make uninstall, but to do this you always need the Makefile present. So do I always have to save my Makefiles to uninstall apps that I've installed by compiling them? That isn't really practical. </question>

<answer>You can recreate the Makefile by unpacking the source tarball again and running ./configure in its directory. Note that if you passed any options to ./configure the first time you unpacked the tarball, you must give the same options again. Then you can run make uninstall from inside the source directory. However, there is a better solution; one that integrates self-compiled programs with your package manager, so everything can be uninstalled (or updated) in the same way. Install CheckInstall, which you will find in the Essentials directory of each Linux Format DVD, and use this instead of make install. The installation process then becomes

./configure
make
sudo checkinstall --type=debian --install=yes

As you can see, the call to CheckInstall replace make install. This runs make install, then builds a Debian package and installs it with dpkg. The result is that the software you've just compiled is not only installed but visible in Synaptic, from where you can uninstall it. There are many more options for CheckInstall it's not limited to packages that use make install (all of which are described in the documentation), but this is enough to get you going. </answer>

<title>Resurrect my laptop!</title>

<question>I want to load Linux on to my USB 2.0 external hard drive and use it to boot my laptop. Trouble is, my laptop is an old IBM Thinkpad, so I think I will have to use a floppy disk to force it to boot from the external drive (as mentioned in LXF99's First Steps tutorial). I'll need to create this setup on my desktop, because the CD drive doesn't work. How do I set up the floppy disk to force booting from USB? Is booting a full sized distro rather than a lightweight distro from a USB port any different to set up? </question>

<answer>Not all external USB hard disk enclosures are bootable: work through the following instructions to find out if yours is. Booting from a floppy and passing the boot process to a hard disk is not that different to doing the same with a pen drive. The easiest way is to install as usual, by booting from the distro CD/DVD and installing to the USB drive. When you get to the bootloader section, have it install to the MBR (Master Boot Record) of the external drive, not the internal one. Recent kernels use the SCSI library for all hard disks, so your internal disk will be /dev/sda and the external /dev/sdb. We tried this with PCLinuxOS from LXF101's DVD; it has a specific option for installing to USB drives. Once you have installed in this way, the distro will boot on any PC that supports booting from USB hard drives. Otherwise, you need to create a floppy disk containing the Grub bootloader. You can get a pre-made one from http://tinyurl.com/2f62dt. Download pdlfloppy.img.gz and write it to a floppy disk with

 gzip -dc pdlfloppy.img.gz | dd of=/dev/fd0

This floppy is set up to boot a Pendrivelinux installation, so edit the configuration file at /mnt/floppy/boot/grub/menu.list to match the corresponding file on the USB hard drive. For PCLinuxOS, the first menu entry looks like:

title linux
kernel (hd0,0)/boot/vmlinuz BOOT_
IMAGE=linux root=/dev/sdb1 acpi=on resume=/
ev/sdb5 splash=silent vga=788
initrd (hd0,0)/boot/initrd.img

The references to /dev/sdb are probably correct unless your BIOS makes the USB device the first in the chain (sda) when you boot from it, but the Grub partition labels all refer to the first partition on the first disk, so change these to (hd1,0). Now boot from the floppy and select your new menu entry. If you get a `file not found' error, press C to reach the Grub console and type

find /boot/vmlinuz

This will give you the number of the partition containing your kernel, and this is what you need in the kernel line of the menu. Highlight the menu entry and press E to edit, then do the same on the kernel line. Change the path and press B to boot the changed entry. If this works, make the changes permanent in the menu.lst file. Another approach is to add this to menu.lst:

root (hd1,0)
chainloader +1

This simply runs the bootloader on your external drive ­ useful if the drive has multiple distros. </answer>