Working with WinPE 3.0 images

Mount a WinPE image:

dism /Mount-Wim /WimFile:winpe.wim /index:1 /MountDir:mount

Inject PNP drivers into the WinPE image:

Dism /image:mount /Add-Driver /driver:C:\drivers\blah\mydriver.inf

Un-mount and commit the image:

Dism /Unmount-Wim /MountDir:mount /Commit

See what’s in the image:

imagex /info install.wim

Merge images:

imagex /export source.wim 1 destination.wim "Image Name" /compress maximum

Create a boot cd ISO:

oscdimg -n -bc:\pe\amd64\etfsboot.com c:\pe\amd64\ISO c:\pe\amd64\winpe_amd64.iso

More info in working with images:

http://technet.microsoft.com/en-us/library/dd799244%28WS.10%29.aspx

Info on working with unattend.xml

http://technet.microsoft.com/en-us/library/cc722132%28WS.10%29.aspx

Some notes for older WinPE images; where dism.exe doesn’t work, you need imagex and peimg:

Mount an older WinPE image:

imagex.exe /mountrw winpe.wim 1 mount

Inject PNP drivers into the WinPE image:

peimg.exe /inf=c:\drivers\blah\*.inf mount\Windows

Un-mount and commit the image:

imagex.exe /unmount mount /commit

Each time you ‘commit’ the image it grows in size. Let’s bring it back down to normal:

imagex /compress maximum /export winpe.wim 1 winpe.wim.optimized

Limiting Bandwidth in Linux

The tc command in Linux can be used for fine-grained control over bandwidth throughput. In this case I have limited public outbound traffic to 50Mbps, and internal network traffic to 450Mbps.

The syntax of tc is quite complex. So much so, I found a neat utility called ‘tcng’ (Traffic Control Next Generation) that interprits a much simpler C like syntax and converts it to a string of tc commands.

Here is the tcng script:

dev "eth0" {
  egress {
   class( <$fs> ) // Internal networks
    if ip_dst/22 == 192.168.0.0
    if ip_dst/21 == 192.168.208.0
    if ip_dst/24 == 192.168.240.0
   ;
    class( <$all> ) // All other IP addresses
        if 1
   ;
   htb() {
    class ( rate 500Mbps, ceil 500Mbps ) {
     $fs = class ( rate 450Mbps, ceil 450Mbps ) {sfq;} // Limit internal/trusted network to 450Mbps
     $all = class ( rate 50Mbps, ceil 50Mbps ) {sfq;} // Limit all other networks to 50Mbps
    }
   }
  }
 }

Here is the output it created, which I rolled into a bash script:

# ================================ Device eth0 ================================
tc qdisc add dev eth0 handle 1:0 root dsmark indices 4 default_index 0
tc qdisc add dev eth0 handle 2:0 parent 1:0 htb
tc class add dev eth0 parent 2:0 classid 2:1 htb rate 62500000bps ceil 62500000bps
tc class add dev eth0 parent 2:1 classid 2:2 htb rate 56250000bps ceil 56250000bps
tc qdisc add dev eth0 handle 3:0 parent 2:2 sfq
tc class add dev eth0 parent 2:1 classid 2:3 htb rate 6250000bps ceil 6250000bps
tc qdisc add dev eth0 handle 4:0 parent 2:3 sfq
tc filter add dev eth0 parent 2:0 protocol all prio 1 tcindex mask 0x3 shift 0
tc filter add dev eth0 parent 2:0 protocol all prio 1 handle 2 tcindex classid 2:3
tc filter add dev eth0 parent 2:0 protocol all prio 1 handle 1 tcindex classid 2:2
tc filter add dev eth0 parent 1:0 protocol all prio 1 u32 match u32 0xd055f000 0xfffffc00 at 16 classid 1:1
tc filter add dev eth0 parent 1:0 protocol all prio 1 u32 match u32 0x4a73d000 0xfffff800 at 16 classid 1:1
tc filter add dev eth0 parent 1:0 protocol all prio 1 u32 match u32 0xd109ee00 0xffffff00 at 16 classid 1:1
tc filter add dev eth0 parent 1:0 protocol all prio 1 u32 match u32 0x0 0x0 at 0 classid 1:2

The following command clears out any previous tc settings. You need to run it each time you want to change your traffic limits or configuration:

tc qdisc del root dev eth0

Intel D945GCLF Ethernet timeouts; firmware bug

The Intel D945GCLF (Atom 230) main board has a serious bug in the Realtek gigabit NIC firmware. Any sustained transfer over 100Mbps will eventually cause the NIC to go offline until the network stack is reloaded or machine rebooted. I reproduced the issue in CentOS, Debian, and Windows.

No driver fixes the issue; you have to update the BIOS to the latest version from the Intel website to resolve this.

Lockfiles in Bash

Here’s a simple ‘skeleton’ script that will allow your Bash scripts to use a PID file, or ‘lockfile’. This ensures that only one instance can run at a time which is useful for daily Cron activities such as mirror updates.

#!/bin/bash
pidfile=/var/run/sync.pid
if [ -e $pidfile ]; then
pid=`cat $pidfile`
if kill -0 &>1 > /dev/null $pid; then
echo "Already running"
exit 1
else
rm $pidfile
fi
fi
echo $$ > $pidfile
#do your thing here
rm $pidfile

Categories: Linux. Comments Off on Lockfiles in Bash

Reclaim ‘missing’ space on a Linux partition with tune2fs

If you aren’t storing critical system files on a partition, you can free up a ton of space. This will reduce the ‘reserved’ space on a Linux partition to 0%. I freed up 45Gb of ‘lost’ space on a 900Gb partition using the following command:

tune2fs -m 0 /dev/sda4

Note: DO NOT set the reserved space to 0 on a system partition.

Categories: Linux. Comments Off on Reclaim ‘missing’ space on a Linux partition with tune2fs

Compiling the Unattended Project linuxboot on CentOS5

I use the Unattended Project to deploy various Windows 2003 server versions via PXE. The following describes how to get Unattended Linuxboot (tftp or pxe boot method) to properly compile on a CentOS5 based Linux system. The CentOS machine was deployed with minimum software packages, so your mileage may vary depending on what you already have installed or not.

yum install gcc gcc-c++ wireless-tools-devel bison bison-devel ncurses-devel flex subversion
cd /usr/src
svn co https://unattended.svn.sourceforge.net/svnroot/unattended/trunk unattended
cd unattended/linuxboot
nano -w Makefile

1. Set the Mysql version to the latest 5.X version at mysql.com otherwise it will not download.
2. Set the glibc version to 2.5 (the same version CentOS 5 uses)

make download
make tftpboot -j 4

Notes: The ‘-j 4’ option means that I have 4 CPU cores (Q9550 CPU) and to use all 4 of them. If you have more or less CPU cores, change this setting accordingly. On a Q9550 compilation takes around 10 minutes. On lesser CPU’s like a P4, it could take an hour or more. If compilation stops in an error state, either a package failed to download or your system is missing some dependencies.

You can compile a CD ISO with the ‘make iso -j 4’ command instead.

Etherchannel 802.1q trunk between Cisco and Foundry

Foundry and Cisco both implement port grouping (load sharing) but are very different.  The following code snippets describe the configuration needed between the two very different platforms to create a working Etherchannel trunk.

On the Cisco, ports 23 and 24 form the group for port-channel1:

port-channel load-balance src-dst-ip

interface Port-channel1
 switchport trunk encapsulation dot1q
 switchport trunk allowed vlan 2,3
 switchport mode trunk
!
interface GigabitEthernet1/0/23
switchport trunk encapsulation dot1q
switchport trunk allowed vlan 2,3
switchport mode trunk
channel-group 1 mode on
!
interface GigabitEthernet1/0/24
switchport trunk encapsulation dot1q
switchport trunk allowed vlan 2,3
switchport mode trunk
channel-group 1 mode on
!

Note that in Cisco, load balancing is per-stream and not per-packet like in Foundry. Therefore you must choose the load sharing type. I found that src-dst-ip balanced traffic the best. The default is MAC based which is terrible in a layer3 routed network.

On the foundry, using ports 47 and 48:

vlan 2 by port
 tagged ethe 1 ethe 47 to 48
!
vlan 3 by port
 tagged ethe 1 ethe 47 to 48
!
trunk ethe 47 to 48

And that’s it. But don’t forget to issue the following command the first time you set it up:

trunk deploy

I didn’t see any issues with the different load sharing algorythms on each end with some limited testing. I suspect that as long as the latency is the same across both links in the group there shouldn’t be any issues with out of order packets and such. Send and receive loads on both lines appears well balanced.

Citrix Xenserver – Expanding Local Storage

Twice now, I have had the (dis)pleasure of expanding our local storage on a couple of XenServer boxes.  In a nutshell, here is how it works:

1.  Expand physical disk (add more RAID members, ect).  Use the procedure specific to your RAID card.

2.  Use fdisk to expand the partition your Local Storage resides on:

[root@vps1a ~]# pvscan
PV /dev/sda3 VG VG_XenStorage-4c69467e-0352-5bd4-3dee-e17cc18aee08 lvm2 [923.64 GB / 380.14 GB free]
Total: 1 [923.64 GB] / in use: 1 [923.64 GB] / in no VG: 0 [0 ]

Note the bold type to the left, /dev/sda3 is the partition we want to expand by deleting and re-adding to the maximum size in fdisk.  After you do this, you need to reboot so the OS will recognize the larger partition.  The bold type to the right is the UUID we need later.

3.  After rebooting, now we can expand the physical LVM volume:

pvresize /dev/sda3

4.  Now we tell XenServer that we increased the size, so you can actually use your extra space:

xe sr-scan uuid=4c69467e-0352-5bd4-3dee-e17cc18aee08

Note:  The UUID was discovered in step 2.

5.  All done!

Notes:  Rebooting the XenServer host is a real pain.  It can be avoided by adding your extra space as a separate partition or disk, then using vgextend to join the LVM physical volumes, instead of fdisk to expand an existing partition.  Using the vgextend method at step 2, you don’t have to reboot, but you lose the redundancy of having RAID5 or RAID10 backing your whole volume.

Alternate Row Shading in Excel

One way to make your data legible is to apply cell shading to every other row in a range. Excel’s Conditional Formatting feature (available in Excel or later) makes this a simple task.

  1. Select the range that you want to format
  2. Choose Format, Conditional Formatting
  3. In the Conditional Formatting dialog box, select Formula Is from the drop-down list, and enter this formula:
    =MOD(ROW(),2)=0
  4. Click the Format button, select the Patterns tab, and specify a color for the shaded rows.
  5. Click OK twice to return to your worksheet.

The best part is that the row shading is dynamic. You’ll find that the row shading persists even if you insert or delete rows within the original range.

Categories: Windows. Comments Off on Alternate Row Shading in Excel