Working Fix for Ubuntu Load_Cycle_Count Problem

November 3rd, 2008 No comments

## Adapted from https://en.opensuse.org/Disk_Power_Management
##
## Create a configuration file named “disk” to manage disk power management:
gksudo gedit /etc/pm/config.d/disk

## Copy and paste the following into “disk”
# Configure disk power management settings to ensure both
# long disk life and good power management.
#
# Space delimited list of disk devices this affects.
#
DEVICES_DISK_PM_NAMES=”/dev/sda”
#
#
# Power management modes
#
# Powersave mode off
#  Disable APM and spin-down
#
DEVICES_DISK_PM_POWERSAVE_OFF=”hdparm -q -B 255 -q -S 0″
#
# Powersave mode on
# Enable APM to aggressive 128 and set spin-down for 21 minutes
#
DEVICES_DISK_PM_POWERSAVE_ON=”hdparm -q -B 128 -q -S 252″

## Next create the power management script “disk.sh”
gksudo gedit /etc/pm/power.d/disk.sh

## Copy and paste the following into “disk.sh”
#!/bin/bash
. /usr/lib/pm-utils/functions
. /etc/pm/config.d/disk

if test -z “${DEVICES_DISK_PM_NAMES}”; then
exit 1
fi

case “$1” in
true)
echo “**enabled pm for harddisk”
for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
${DEVICES_DISK_PM_POWERSAVE_ON} ${DISK_NAME}
done ;;
false)
echo “**disabled pm for harddisk”
for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
${DEVICES_DISK_PM_POWERSAVE_OFF} ${DISK_NAME}
done ;;
esac

## Save disk.sh, close, and make it executable
sudo chmod +x /etc/pm/power.d/disk.sh

Categories: Uncategorized Tags:

Boot Ubuntu in 19 Seconds

October 30th, 2008 No comments

Want your Ubuntu to boot more quickly? Read this.

There are also links to solutions to the odd “resume” problems I was experiencing: “no resume image” on my swap partition.

Categories: Uncategorized Tags:

Copy Files Using Windows Remote Desktop

October 30th, 2008 No comments

Here’s a great tip for copying files from your desktop to EC2 (or any remote Windows server). Posted on Amazon’s EC2 forum by P. Hebert:

“Before you connect to the instance, wander through the tabs and find check the box under “Local drives and resources” for your C: drive. Once connected to the instance, open Windows Explorer and in the address bar, type “tsclientc” (without quotes). your local PC’s C: drive will (slowly) open up in Explorer and you can drag&drop.”

“This doesn’t require any additional ports to be opened up; it goes over the RDP connection you already using for remote desktop. ”

Categories: Uncategorized Tags:

UUID in /etc/fstab

October 29th, 2008 No comments

While I understood the value of using UUIDs to specify devices in /etc/fstab, it wasn’t clear how it all worked. After a bit of googling …

When a device is connected, the system automatically retrieves its UUID, regardless of which interface is used. The list of currently available devices can be displayed with:

ls /dev/disk/by-uuid -lh

Currently available block device ids can be displayed using blkid and attributes of individual devices is displayed by vol_id /dev/name.

Also, blkid information is cached in /etc/blkid.tab.

Very important: if you clone drives with dd, the UUID will be cloned too! If this isn’t what you had in mind, reset it using:

tune2fs -U UUID /dev/name

where UUID is one of the following:
a unique id like “c1b9d5a2-f162-11cf-9ece-0020afc76f16”
or clear, random or time.

Categories: Uncategorized Tags:

Concurrency from Microsoft

October 29th, 2008 No comments

Long after Erlang set the standard for concurrent languages, Microsoft is addressing the issue with extensions to C++. Here are a couple of excellent articles from MSDN:

Design Considerations for Parallel Programming

and

Solving 11 Likely Problems In Your Multithreaded Code

Categories: Uncategorized Tags:

Ruby Sorting

October 28th, 2008 No comments

A rather neat little piece of code I ran across for “human” sorting. Given an array of picture names:

%w[picture3 picture20 picture1004 picture1].sort_by {|item| item.scan(/[0-9]+|[^0-9]+/).map {|s| s[/[^0-9]/] ? s : s.to_i} }

Split each string up into runs of digits or runs of non-digits, convert the digit strings to integers, and sort array-wise (component by component).

Categories: Uncategorized Tags:

Windows XP and Apache WebDAV

October 22nd, 2008 No comments

Not clear why this is the case, but the WebDAV client in Explorer on XP has been somewhat broken for years.

Specifying a URL like this won’t work:

https://example.com/webdav

Instead you need to explicitly specify the port:

https://example.com:80/webdav

No idea why it works this way – perhaps someone at Microsoft can tell us.

Categories: Uncategorized Tags:

Fuse on CentOS

October 16th, 2008 No comments

To install fuse on CentOS:

yum install fuse dkms dkms-fuse
modprobe fuse
depmod
Categories: Uncategorized Tags:

Disable Remote Root Login

October 16th, 2008 No comments

From G Garon at go2linux:

For security reasons it is not a good idea to permit ssh root direct login, it is better to login as another user, and then switch to root using the ‘su -‘ comand, to do this, you need to disable root from login directly using ssh protocol, this will decrease the possibility of a hacker breaking your linux box, as now he will have to guess your user name and your password

Ok, let’s go and see to make this.

Edit the file /etc/ssh/sshd_config

vi /etc/ssh/sshd_config

(you can use your favorite text editor)
I strongly recommend you to open two logins if doing this from a remote connection, and never close one of them, in case you need to roll back the configuration

locate this line with, writing this onces editing with vi or vim

:/Protocol
if it says

Protocol 2, 1

change it to:

Protocol 2

This will enable only ssh2 which is more secure that ssh, do not do this if you need to log with a client that only support ssh, and not ssh2 protocol.

Next locate this line “PermitRootLogin yes” by entering this on your vi or vim editor

:/PermitRootLogin yes

and change it to this:

PermitRootLogin no

and save the file, with this:

shift+zz

now restart the ssh service.
If Fedora or CentOS
/etc/init.d/sshd restart

If Debian or Ubuntu
/etc/init.d/ssh restart

Test that you can login and gain root access with ‘su -‘ (without quotes), before, you left your root remote connection

Related Links
https://linux.go2linux.org/node/6
https://linux.go2linux.org/taxonomy/term/3

Categories: Uncategorized Tags:

CentOS 5 Xen images – part 2: installing the Xen guest

October 16th, 2008 No comments

Copied from JP Houde’s blog:

OK, so you downloaded an image from jailtime.org or you made your own image as described in my previous post, and now you want to install a Xen guest using it. Here’s how to do it :

Setup the dom0 (host OS)

Of course, Xen should be installed on the host OS. I use CentOS 5, so I just selected Xen during the installation. It will install a xen kernel that you should use to boot the host OS (dom0). I won’t go into details here, because that’s really easy to do with CentOS or Redhat Enterprise Linux. With other distributions, you could have to install distribution-specific packages, or use the official Xen package from xen.org.

Setup the target partition or logical volume

You should create a filesystem for the “root” partition and the swap. You could use simple files, but you will have better performance using real partitions or LVM volumes. LVM volumes also has other advantages, like the ability to create snapshots for backing up data, and easy resizing.

The following commands will create a 5GB root logical volume (LV) and 1GB swap in the /dev/vg0 volume group (VG). For more information about LVM, search for LVM howto in a search engine.

# root
lvcreate -L 5000M -n mailroot /dev/vg0
mkfs.ext3 /dev/vg0/mailroot
# swap
lvcreate -L 1000M -n mailswap /dev/vg0
mkswap /dev/vg0/mailswap

You can then mount the root partition and copy the base system (either an image from jailtime or an image you made yourself) on it.

mkdir /mnt/mailroot
mount /dev/vg0/mailroot /mnt/mailroot
# if you image contents is located in /centos...
cp -R /centos/* /mnt/mailroot/

Don’t forget to unmount the root partition when you’re done! Xen will not boot the domain if the partition is already mounted.

Download a kernel for the domU

The kernel that we will need to boot the domU has be to located in the dom0.

You can use the standard xen kernel that comes with CentOS to do that (e.g. vmlinuz-2.6.18-53.1.13.el5xen) , but you’ll also need an initrd, or the kernel won’t boot. To make the initrd, use the following command :

/sbin/mkinitrd --with=xennet --preload=xenblk /boot/initrd-centos5-xen.img 2.6.18-53.1.13.el5xen

This makes an initrd image with the required modules to boot a domU. The last parameter is the version of your kernel (the one you will use to boot the domU). You can get this number by typing “uname -r” on the command line. This will result in a /boot/initrd-centos5-xen.img image file.

Note (2008-02-14) : in a previous version of this blog post, I recommended to use a kernel from the official Xen distribution at xen.org. It worked, but it doesn’t seem to work anymore.

Create the configuration file

The configuration of the Xen guest is controlled by a simple text file. Create it as /etc/xen/yourdomUname, and move (or symlink) it in /etc/xen/auto if you want to start it automatically on boot.

Most basic parameters in this file are easy to understand. You should make sure “kernel” points to the kernel you copied from the xen tarball. “memory” is the amount of RAM allocated to the guest. “name” will be the name of the guest that you will use when connecting to it or shutting it down using the “xm” command.

“vif” contains information about network interfaces. One important thing in that line is the MAC address. If you don’t specify it here, a random MAC will be assigned at each boot, and that may not give good results. Edit the last 3 numbers (put anything, it just has to be unique across your network).

Finally, ‘disk’ is the parameter that tells Xen what partitions to use and what device name it will assign them. The last line, ‘root’, will tell the kernel what is the root device.

kernel = "/boot/vmlinuz-2.6.18-53.1.13.el5xen"
ramdisk = "/boot/initrd-centos5-xen.img"
memory = 512
name = "mail"
vif = [ 'mac=00:16:3e:21:f1:31,bridge=xenbr0' ]
dhcp = "dhcp"
disk = ['phy:/dev/vg0/mailroot,sda1,w', 'phy:/dev/vg0/mailswap,sda2,w' ]
# The next line would be useful if you want to use an simple file instead of a partition/LV
#disk = ['file:/root/test.img,sda1,w', 'file:/root/centos.swap,sda2,w' ]
# We don't use pygrub, we boot the kernel directly from dom0
#bootloader="/usr/bin/pygrub"
root = "/dev/sda1 ro"

Boot the domain!

OK, you’re ready to boot the guest domain! Just issue the following command to “create” (which means boot, really) the domU.

xm create /etc/xen/YOUR_CONFIG_FILE -c

The -c parameter tells xm to connect to the domain’s console. You can disconnect from it by pressing CTRL+], and connect to it again with “xm connect NAME”.

If everything works right, you should see the login prompt appearing, and you will be ready to use the new guest domain!

Fix SSH

If you made the guest image yourself as I explained in my previous post (part 1), you need to create the random device to fix SSH (and probably other services that requires generating keys). Issue the following commands on the guest’s console :

/sbin/MAKEDEV generic
/etc/init.d/sshd start
Categories: Uncategorized Tags: