Tuesday, May 29, 2007
Resetting an xterm
- reset
- if that doesn't help, ESC c should supposedly do a full reset (seems not to work for me)
- or enable the xterm menu:
XTerm*vtMenu*softreset*Label: Do Soft Reset
XTerm*vtMenu*hardreset*Label: Do Full Reset
Locales in Ubuntu and Debian
- apt-get install language-pack-et language-pack-en # Estonian and English
- update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 # set default to English
Friday, May 18, 2007
Enhancements to xubuntu-desktop metapackage
- either don't depend on xorg-video-all and xorg-input-all or purge unused modules after install.
- either don't depend on Eastern fonts or purge unused ones after install.
- add localepurge, debfoster, deborphan
Install Ubuntu (Feisty) from Windows
- mkdir c:\boot; cd boot
- download http://kent.dl.sourceforge.net/sourceforge/grub4dos/grub_for_dos-0.4.2.zip and unzip to boot
- download http://archive.ubuntu.com/ubuntu/dists/feisty/main/installer-i386/current/images/netboot/ubuntu-installer/i386/initrd.gz and http://archive.ubuntu.com/ubuntu/dists/feisty/main/installer-i386/current/images/netboot/ubuntu-installer/i386/linux
- create a menu.lst file. I've chosen to install the minimal server edition, consult http://archive.ubuntu.com/ubuntu/dists/feisty/main/installer-i386/current/images/netboot/ubuntu-installer/i386/pxelinux.cfg/default
if you want to install the full Gnome Ubuntu edition.
menu.lst
title Install Ubuntu Server Edition
kernel (hd0,0)/boot/linux base-installer/kernel/linux/extra-packages-2.6= tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language-support=false vga=normal --
initrd (hd0,0)/boot/initrd.gz - reboot into plain DOS (press F8 during boot and choose Safe mode command prompt),
cd boot
grub (or grub --config-file="c:\boot\menu.lst") - Ubuntu installation will start.
Possible errors:
It may happen, that the filesystem type is not properly changed if you chose to setup partition table manually. Grub fails to install in that case and grub-install will fail with a confusing message "file ...boot/grub/stage1 not read correctly". Just umount /target, fdisk /dev/hda and fix the partition type + rerun Install grub boot loader from menu.
Thursday, May 17, 2007
Install GMPY on Ubuntu
- sudo apt-get install python-dev libgmp3-dev build-essential
- cd tmp; wget http://gmpy.googlecode.com/files/gmpy-1.02-1.zip
- unzip gmpy-1.02-1.zip
- cd gmpy-1.02
- sudo python setup.py install
Saturday, May 05, 2007
Tweaking Linux for broadband connection
You can pick an arbitrarily large window size (for the most part) and not have to worry too much about making it too big. I use a window size of 512 KB (or 524288 bytes) myself, and I have no problems at all. My brother, who runs Linux over a different broadband provider than I have, had some trouble with using 512 KB--so, instead he used 256 KB (or 262144 bytes) which worked better for him. Typically, you will notice that your connection is actually slower than the default settings if your window size is too big. That being said, you should try out different size window sizes and see what works best for you--but, in most cases either 512 KB, 256 KB, or 128 KB seem to do the trick quite nicely.
/etc/sysctl.conf (substituting your window size in place of 524288, if necessary):
# Tweaks for faster broadband...
net.core.rmem_default = 524288
net.core.rmem_max = 524288
net.core.wmem_default = 524288
net.core.wmem_max = 524288
net.ipv4.tcp_wmem = 4096 87380 524288
net.ipv4.tcp_rmem = 4096 87380 524288
net.ipv4.tcp_mem = 524288 524288 524288
net.ipv4.tcp_rfc1337 = 1
net.ipv4.ip_no_pmtu_disc = 0
net.ipv4.tcp_sack = 1
net.ipv4.tcp_fack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_ecn = 0
net.ipv4.route.flush = 1
And turn off IPv6:
sudo su
echo 'alias net-pf-10 off' >> /etc/modprobe.d/blacklist_ipv6
Check after reboot:
lsmod | grep ipv6
dmesg | grep 'family 10'
Friday, May 04, 2007
Tweaking Linux for speed
- Use hashed b-trees to speed up lookups in large directories when creating filesystems:
sudo mke2fs -j -O dir_index /dev/hda1 - Optimize directories.
e2fsck -fD /dev/hda1
man e2fsck:
-D Optimize directories in filesystem. This option causes e2fsck
to try to optimize all directories, either by reindexing them if
the filesystem supports directory indexing, or by sorting and
compressing directories for smaller directories, or for filesys‐
tems using traditional linear directories. - Use data=writeback and noatime when mounting ext3 partitions (/etc/fstab):
/dev/hda1 / ext3 defaults,data=writeback,noatime 0 1
sudo tune2fs -o journal_data_writeback /dev/hda1
From man mount:
writeback
Data ordering is not preserved - data may be written into
the main file system after its metadata has been commit‐
ted to the journal. This is rumoured to be the highest-
throughput option. It guarantees internal file system
integrity, however it can allow old data to appear in
files after a crash and journal recovery.
noatime
Do not update inode access times on this file system
(e.g, for faster access on the news spool to speed up
news servers). - Choose an I/O scheduler wisely. Although CFQ should be the default, it does no harm to force it by passing elevator=cfq to kernel command line (by editing /boot/grub/menu.lst and running update-grub).
Check your current scheduler:
cat /sys/block/hda/queue/scheduler # or
dmesg | grep scheduler
From http://www.redhat.com/magazine/008jun05/features/schedulers/ :The Completely Fair Queuing (CFQ) scheduler is the default algorthim in Red Hat Enterprise Linux 4. As the name implies, CFQ maintains a scalable per-process I/O queue and attempts to distribute the available I/O bandwidth equally among all I/O requests. CFQ is well suited for mid-to-large multi-processor systems and for systems which require balanced I/O performance over multiple LUNs and I/O controllers.
The Deadline elevator uses a deadline algorithm to minimize I/O latency for a given I/O request. The scheduler provides near real-time behavior and uses a round robin policy to attempt to be fair among multiple I/O requests and to avoid process starvation. Using five I/O queues, this scheduler will aggressively re-order requests to improve I/O performance.
The NOOP scheduler is a simple FIFO queue and uses the minimal amount of CPU/instructions per I/O to accomplish the basic merging and sorting functionality to complete the I/O. It assumes performance of the I/O has been or will be optimized at the block device (memory-disk) or with an intelligent HBA or externally attached controller.
The Anticipatory elevator introduces a controlled delay before dispatching the I/O to attempt to aggregate and/or re-order requests improving locality and reducing disk seek operations. This algorithm is intended to optimize systems with small or slow disk subsystems. One artifact of using the AS scheduler can be higher I/O latency.
Check that DMA is enabled.
dmesg | grep -i dma- Consider using readahead, prelink and preload. Prelink is generally a must. Readahead may cut boot times.
- Readahead allows the user to specify a set of files to be read into the page cache to accelerate first time loading of programs, typically during the boot sequence.
- The prelink package contains a utility which modifies ELF shared libraries and executables, so that far fewer relocations need to be resolved at runtime and thus programs come up faster.
- preload monitors applications that users run, and by analyzing this data, predicts what applications users might run, and fetches those binaries and their dependencies into memory for faster startup times.
sudo sed -i 's/PRELINK=.*/PRELINK=yes/' /etc/default/prelink
pass 'profile' option to kernel with grub on next boot, so that readahead can be reprofiled - Enable concurrent boot.
sudo sed -i 's/CONCURRENCY=.*/CONCURRENCY=shell/' /etc/init.d/rc - Place the swap partition wisely. Sectors are generally numbered starting from the outside of the disk, so either try to place swap close to sector 0 (on the outside of the drive, where read/write speed may or may not be higher) or in the middle. Let me quote:
Modern disks have more sectors in outer than in inner tracks but nevertheless placing swap partitions at the outer rim of the disk is questionable. The usage pattern of swap partitions involves short transfers between head movements. Therefore increasing throughput is less important then reducing seek time. It is better to place swap partitions at around the middle of the disk (but notice that the disk lies to fdisk about its true geometry and does not tell about outer tracks being bigger than inner ones so what looks to be the middle of the disk in fdisk is not the physical middle). - Control swapping according to your memory resources.
Quoting:- If you have a lot of memory and succeed in not using swap at all then set vm.swappiness to 0
- If your computer has little memory and needs to swap much set vm.swappiness to 100
- A good default in between is vm.swappiness=60
sudo sysctl vm.swappiness=0
sudo swapoff -a
sudo swapon -a
sudo su
echo 'vm.swappiness=0' >> /etc/sysctl.conf - Turn off IPv6:
sudo su
echo 'alias net-pf-10 off' >> /etc/modprobe.d/blacklist_ipv6
check after reboot:
lsmod | grep ipv6
Also turn off ipv6 in Firefox/Iceweasel:
about:config - Turn off filesystem checking for foreign filesystems and for filesystems that don't need to be checked (this will considerably speed up boot):
edit /etc/fstab and set last number to 0 for filesystems that don't need checking, e.g.
UUID=x /media/sda7 ntfs defaults,nls=utf8,umask=007,gid=46 0 0
Thursday, May 03, 2007
Trimming down etch to ~100 MB
- sudo debootstrap etch etch/ ftp://ftp.ee.debian.org/debian
- sudo chroot etch
- apt-get install localepurge
- apt-get --purge remove dselect aptitude dhcp3-client dhcp3-common info man-db manpages dmidecode laptop-detect
- apt-get install grub initrd-tools linux-image-686 ssh python-minimal
- mkdir /boot/grub; update-grub
- apt-get clean
- APT cache:
6.4M /var/cache/apt/pkgcache.bin
6.4M /var/cache/apt/srcpkgcache.bin
19M /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_etch_main_binary-i386_Packages
3.6M /var/lib/dpkg/info
internationalization:
6.9M /usr/share/i18n
4.9M /usr/lib/gconv
documentation:
8.2M /usr/share/doc
4.7M /usr/share/man
zoneinfo:
5.6M /usr/share/zoneinfo
kernel modules:
44M lib/modules/2.6.18-4-686/kernel - time for cleanup:
- vi /etc/apt/sources.list, comment everything out. This will temporarily disable apt
- apt-get update
- rm /usr/share/i18n/{charmaps,locales}/*
- rm -rf /usr/lib/gconv # or at least
for i in IBM INIS EBCDIC MAC ISO- ISO_ KOI JOHAB CP BIG5 EUC ECMA ARM ASM GEOR GOST GREEK LATIN NATS GB SJIS; do rm /usr/lib/gconv/${i}*; done - rm -rf /usr/share/{doc,man}/*
- boot into the system and check what modules are actually in use with lsmod, remove the modules you don't need (e.g. who needs sound in a router? or even better, build your own kernel):
rm -rf /lib/modules/2.6.18-4-686/kernel/sound
rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/isdn
rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/net/wireless
rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/media
rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/scsi/pcmcia
version=2.6.18-4-686
depmod -a -F /boot/System.map-$version $version
update-initramfs -u # to check that nothing is broken
# other redundant modules:
/lib/modules/2.6.18-4-686/kernel/net/{ax25,ipx,x25,ipv6,appletalk,atm,bluetooth,decnet,econet,irda}
/lib/modules/2.6.18-4-686/kernel/fs/{reiserfs,smbfs,qnx4,xfs,befs,bfs,affs,afs,coda,cifs,freevxfs,hfs,hfsplus,hpfs,ocfs2,nfs,nfs_common,nfsd,ncpfs,ufs,udf}
# remove modules that you don't need from (spacehogs):
# /lib/modules/2.6.18-4-686/kernel/drivers/net
# /lib/modules/2.6.18-4-686/kernel/drivers/scsi
rm /lib/modules/2.6.18-4-686/kernel/drivers/scsi/sata*.ko
rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/scsi/aic7xxx* - we are down to 97M now:
97M / - configure timezone, hosts, hostname, network interfaces, fstab, name resolver:
- tzconfig
- echo '127.0.0.1 localhost' > /etc/hosts # see http://www.howtoforge.com/perfect_setup_debian_etch_p3 for IPv6
- echo 'my.hostname' > /etc/hostname
- vi /etc/network/interfaces
iface lo inet loopback
... - vi /etc/fstab
#
proc /proc proc defaults 0 0
/dev/hda2 none swap sw 0 0/dev/hda1 / ext3 defaults,errors=remount-ro 0 1 - vi /etc/resolv.conf
nameserver x.x.x.x - set root password or add an ordinary user and install sudo
passwd - disable IPv6 if you don't need it
- boot target with Knoppix, tomsrtbt or whatever other rescue tools you have
- create a parition for the new system, mkfs, mount and cd to target root
- transfer the filesystem:
nc -lp 5555 | tar xf - # in target system
cd etch; sudo tar cf - . | nc target 5555 - In target: chroot .; grub-install /dev/hda OR if you are unable to run grub from the target, create a grub floppy:
- dd if=/boot/grub/stage1 of=/dev/fd0 bs=512
dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1 - in grub shell:
root (hd0,0)
kernel /vmlinuz root=/dev/hda1 ro
initrd /initrd.img
boot - when booted into target, run grub install
if proc is not mounted, grub will complain Could Not Find Device For /boot,
mount proc /proc
cp /proc/mounts /etc/mtab
grub-install /dev/hda - ready, reboot target
- update-locale LC_ALL=C LANG=C
- setup /etc/iftab
- update-alternatives --set editor /usr/bin/vim.tiny
- apt-get install sudo; visudo
# or user ALL=(ALL) NOPASSWD: ALL
%admin ALL=(ALL) ALL