Archive

Author Archive

Hacking Cisco

May 24th, 2011 No comments

Someone on one of the lists posted about the blog Hacking Cisco so I went over to check it out. Wow. Jarek Rek is the author and he must be putting a ton of time into his studies.

Inspiring.

I have added his blog to the blogroll on the side.

Categories: CCIE Labs Tags:

DRBD and Heartbeat

May 10th, 2011 No comments

I spent a considerable amount of time over the last couple of days working with DRBD and Heartbeat.

Below are the links I used to get things running:
http://wiki.centos.org/HowTos/Ha-Drbd
http://www.howtoforge.com/vm_replication_failover_vmware_debian_etch_p3
http://www.clusterlabs.org/doc/en-US/Pacemaker/1.1/html/Clusters_from_Scratch/s-intro-pacemaker.html
http://www.drbd.org/users-guide/s-heartbeat-r1.html
http://www.drbd.org/users-guide/s-heartbeat-config.html
http://www.drbd.org/users-guide/s-heartbeat-crm.html

Part of my problem was not understanding the difference between R1 and DRM style clusters and their accompanying daemons; heartbeat, pacemaker and the different protocol versions. Pacemaker is a more advanced cluster resource manager that can work with both Corosync and Heartbeat. Heartbeat uses an older protocol whereas pacemaker uses OpenAIS to be compatible with RedHat cluster services.

Regardless here are my notes for configuration, and just for completeness my notes are a mix of doing this first on VMWare and then on a Xen cluster so any inconsistencies are a result of doing this multiple times in different environments. Regardless the errors are mine and I would recommend reading the documentation linked above.

The basics behind the setup is that DRBD replicates data between two servers. DRBD is the network block device that mirrors the data. The heartbeat daemon keeps track of the shared IP, the daemons that are in HA and runs the init scripts appropriately.

DRBD Initialization

Format the disk:

fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 10443.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p
Disk /dev/xvdb: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10443, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-10443, default 10443):
Using default value 10443

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83

Command (m for help): p
Disk /dev/xvdb: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1       10443    83883366   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Make sure that the names names are consistent throughout all of these configuration files. This may mean ensuring they are correct in DNS and /etc/hosts.

Locally configure name for this server:

uname -n
drbd01.chainringcircus.org

uname -n
drbd02.chainringcircus.org

DNS name for this server:

dig +short drbd01.chainringcircus.org
192.168.1.191
dig +short drbd02.chainringcircus.org
192.168.1.192

The /etc/drbd.conf file was designed to allow a verbatim copy on both nodes of the cluster.

cat /etc/drbd.conf
#
# please have a a look at the example configuration file in
# /usr/share/doc/drbd83/drbd.conf
#

global {
        usage-count no;
}

common {
        protocol C;
        handlers {
                pri-on-incon-degr "echo '!DRBD! pri on incon-degr' | wall ; sleep 60 ; halt -f";
                #pri-on-incon-degr "echo o > /proc/sysrq-trigger ; halt -f";
                #pri-on-incon-degr This handler is called if the node is primary, degraded and the local
                #copy of the data is inconsistent.  It broadcasts an error, sleeps for 60 seconds and then halts.
        }

        startup {
                wfc-timeout 10;                 # Wait for connection timeout.  The init script blocks the boot process
                                                          # until the DRBD resources are connected.  We wait for 10 seconds.
                degr-wfc-timeout 30;        # Wait for connection timeout if this node was a degraded cluster.
        }

        disk {
                on-io-error detach;
        } # or panic, ...

        net {  
                cram-hmac-alg "sha1";
                shared-secret "CHANGEME";        # Don't forget to choose a secret for auth
                max-buffers   20000;                  # Play with this setting to achieve highest possible performance
                unplug-watermark   12000;         # Play with this setting to achieve highest possible performance
                max-epoch-size 20000;               # Should be the same as max-buffers
        }
        syncer {
                rate 100M;
        }
}

resource sites {
        device /dev/drbd0;
        disk /dev/sdb;
        meta-disk internal;     # Internal means that the last part of the backing device is used to store the metadata.
        on drbd01.chainringcircus.org {       #on hostname as seen in uname -n and the DNS lookup.
                address 192.168.1.191:7788;
        }
        on drbd02.chainringcircus.org {
                address 192.168.1.192:7788;
        }
}

Copy the configuration file:

scp /etc/drbd.conf root@drbd02.chainringcircus.org:/etc/

Tried to start DRBD but got an error:

service drbd start
Starting DRBD resources: [
sites
no suitable meta data found :(
Command '/sbin/drbdmeta 0 v08 /dev/sdb internal check-resize' terminated with exit code 255
drbdadm check-resize sites: exited with code 255
d(sites) 0: Failure: (119) No valid meta-data signature found.

        ==> Use 'drbdadm create-md res' to initialize meta-data area. <==


[sites] cmd /sbin/drbdsetup 0 disk /dev/sdb /dev/sdb internal --set-defaults --create-device --on-io-error=detach  failed - continuing!
 
s(sites) n(sites) ]..........
/etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res    cs            ro                 ds                 p  mounted  fstype
0:sites  WFConnection  Secondary/Unknown  Diskless/DUnknown  C


/etc/init.d/drbd stop
Stopping all DRBD resources: .

I did not initialize the meta data storage and this needs to be done before a DRBD resource can be brought online. The DRBD resource needs to be down or detached from its backing storage.

drbdadm create-md sites
md_offset 1073737728
al_offset 1073704960
bm_offset 1073672192

Found some data

 ==> This might destroy existing data! <==

Do you want to proceed?
[need to type 'yes' to confirm] yes

Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.

service drbd start
Starting DRBD resources: [
sites
Found valid meta data in the expected location, 1073737728 bytes into /dev/sdb.
d(sites) s(sites) n(sites) ]..........

Check the status:

cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
 0: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:1048508

Make it primary:

drbdadm -- --overwrite-data-of-peer primary sites
cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
    ns:67584 nr:0 dw:0 dr:67584 al:0 bm:4 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:980924
        [>...................] sync'ed:  6.7% (980924/1048508)K delay_probe: 10
        finish: 0:01:27 speed: 11,264 (11,264) K/sec
[root@localhost etc]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
    ns:1019904 nr:0 dw:0 dr:1019904 al:0 bm:62 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:28604
        [==================>.] sync'ed: 97.7% (28604/1048508)K delay_probe: 195
        finish: 0:00:02 speed: 11,132 (10,404) K/sec
[root@localhost etc]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
    ns:1048508 nr:0 dw:0 dr:1048508 al:0 bm:64 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
You have new mail in /var/spool/mail/root

Make a file system:

mkfs.ext3 /dev/drbd0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
131072 inodes, 262127 blocks
13106 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Testing the filesystem:

mount /dev/drbd0 /sites

mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda5 on /home type ext3 (rw)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
.host:/ on /mnt/hgfs type vmhgfs (rw,ttl=1)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/drbd0 on /sites type ext3 (rw)

touch /sites/test.txt

ls /sites
lost+found  test.txt

umount /sites

drbdadm secondary sites

On the second server:

drbdadm primary sites

mount /dev/drbd0 /sites/

mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda5 on /home type ext3 (rw)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
.host:/ on /mnt/hgfs type vmhgfs (rw,ttl=1)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/drbd0 on /sites type ext3 (rw)

ls /sites
lost+found  test.txt

Heartbeat R1-style

Heartbeat in R1 configuration uses 3 files that must be configured if you are using the heartbeat protocol.
/etc/ha.d/ha.cf
/etc/ha.d/haresources
/etc/ha.d/authkeys

cat /etc/ha.d/authkeys
auth 1          # A numerical identifier between 1 and 15 inclusive
                    # must be unique within the file.
1 sha1 CHANGEME   # Methods can be md5 sha1 or crc.
                                # The password is just a string.
chmod 600 /etc/ha.d/authkeys

Before we take care of the ha.cf file we need to set up the ha_logd configuration file.

cp /usr/share/doc/heartbeat-2.1.3/logd.cf /etc/

And make changes to the logd.cf file accordingly. Be sure to copy /etc/logd.cf to both servers. Also note that I had to completely stop and then restart the heartbeat daemon for my logging changes to take affect.

cat /etc/logd.cf
#       File to write debug messages to
#       Default: /var/log/ha-debug
debugfile /var/log/ha-debug.log

#
#
#       File to write other messages to
#       Default: /var/log/ha-log
logfile /var/log/ha.log

#
#
#       Facility to use for syslog()/logger
#       Default: daemon
#logfacility    daemon

#       Entity to be shown at beginning of a message
#       for logging daemon
#       Default: "logd"
entity logd

#       Do we register to apphbd
#       Default: no
#useapphbd no

#       There are two processes running for logging daemon
#               1. parent process which reads messages from all client channels
#               and writes them to the child process
#  
#               2. the child process which reads messages from the parent process through IPC
#               and writes them to syslog/disk

#       set the send queue length from the parent process to the child process
#
#sendqlen 256

#       set the recv queue length in child process
#
#recvqlen 256
cat /etc/ha.d/ha.cf
# The recommendation is to use logd.
use_logd yes
# Default option is 0, values are 0-255 with 1-3 being the most useful.
debug 0
# Timing according to the FAQ at www.linux-ha.org/wiki/FAQ
# warntime should be at least 2 * keepalive
# warntime should be 1/2 to 1/4 deadtime
# The interval between heartbeat packets.
keepalive 1
# How quickly Heartbeat should issue a "late heartbeat" warning.  Warntime is
# important for tuning deadtime.
warntime 5
# How long to decide a cluster node is dead.  Too low will flasely declare
# a death and too high will hinder takeover during a failure.
# Can be specified as a floating point number followed by a untis-specifier.
# If units are omitted it defaults to seconds.
# deadtime 1
# deadtime 100ms 100 milliseconds
# deadtime 1000us 1000 microseconds
deadtime 10
# 694 is the default but can be changed if multiple clusters are in use.
udpport 694
# Which interfaces send UDP broadcast traffic, more than one can be specified.
bcast   eth0
# auto_failback can be "on" "off" or "legacy"
auto_failback off
# Set the nodes in the cluster.
node    in1.eamc.org        
node    in2.eamc.org
# Make sure this IP address is pingable from the bcast network above.
ping 192.168.1.1    
respawn hacluster /usr/lib/heartbeat/ipfail
cat /etc/ha.d/haresources
drbd01 192.168.1.190 drbddisk::sites Filesystem::/dev/drbd0::/sites::ext3 httpd
# Explanation:
# Primary Server name --> virtual IP address to be used --> DRBD resource as configurd in /etc/drbd.conf
# --> where to mount the DRBD resource and the filesystem type --> resource to start/stop in case of failover

Cluster Management
To take over cluster management from a primary server:

/usr/lib/heartbeat/hb_takeover

Relinquishing cluster management to a secondary server:

/usr/lib/hearbeat/hb_standby
/etc/init.d/heartbeat stop

The order of operations as set by the init scripts:

ls -al /etc/rc3.d/ | egrep "hear|drb"
lrwxrwxrwx  1 root root   14 Apr  1 11:40 S70drbd -> ../init.d/drbd
lrwxrwxrwx  1 root root   19 Jun  1 08:58 S75heartbeat -> ../init.d/heartbeat

Notes for Xen users:

# cat /etc/modprobe.d/drbd.conf
options debd disable_sendpage=1

To allow live migration on Xen:

        net {
                allow-two-primaries;
        }

Split-brain
Playing around this morning I got the cluster into split-brain.

Jun  1 10:46:53 in1 kernel: block drbd0: Split-Brain detected but unresolved, dropping connection!
Jun  1 10:46:53 in1 kernel: block drbd0: helper command: /sbin/drbdadm split-brain minor-0

Here is how to fix it.
Run this first on the secondary node.

drbadm -- --discard-my-data connect sites

Run this on the primary node.

drbadm connect sites
Categories: Linux Tags:

CCIE R&S Written Blueprint

April 12th, 2011 No comments

Below is the CCIE written blueprint. My plan is to slowly fill in my notes with the corresponding sections. The problem arises when Cisco is vague as to what is actually required. For instance I have been studying MPLS and LDP recently. While MPLS is listed on the blueprint, you need to understand LDP as well, however, it is not on the blueprint.

I have decided go ahead and add sections I feel are necessary but my added sections will be in italics to set them apart from the official outline. They will also break from the Cisco numbering convention. For instance below, section 4.11 Implement LDP does not follow the Cisco numbering theme of 4.10, 4.20, 4.30 but instead uses 4.11. Italics combined with the odd numbering signal my personal changes to the outline.

Source:
Cisco Learning Network

1.00 Implement Layer 2 Technologies
         1.10 Implement Spanning Tree Protocol (STP)                   
                  (a) 802.1d                   
                  (b) 802.1w                   
                  (c) 801.1s                   
                  (d) Loop guard                   
                  (e) Root guard                   
                  (f) Bridge protocol data unit (BPDU) guard
                  (g) Storm control                   
                  (h) Unicast flooding                   
                  (i) Port roles, failure propagation, and loop guard operation
         1.20 Implement VLAN and VLAN Trunking Protocol (VTP)
         1.30 Implement trunk and trunk protocols, EtherChannel, and load-balance
         1.40 Implement Ethernet technologies
                  (a) Speed and duplex
                  (b) Ethernet, Fast Ethernet, and Gigabit Ethernet
                  (c) PPP over Ethernet (PPPoE)
         1.50 Implement Switched Port Analyzer (SPAN), Remote Switched Port Analyzer (RSPAN),
          and flow control
         1.60 Implement Frame Relay
                  (a) Local Management Interface (LMI)
                  (b) Traffic shaping
                  (c) Full mesh
                  (d) Hub and spoke
                  (e) Discard eligible (DE)
         1.70 Implement High-Level Data Link Control (HDLC) and PPP

2.00 Implement IPv4
         2.10 Implement IP version 4 (IPv4) addressing, subnetting,
                    and variable-length subnet masking (VLSM)
         2.20 Implement IPv4 tunneling and Generic Routing Encapsulation (GRE)
         2.30 Implement IPv4 RIP version 2 (RIPv2)
         2.40 Implement IPv4 Open Shortest Path First (OSPF)
                  (a) Standard OSPF areas
                  (b) Stub area
                  (c) Totally stubby area
                  (d) Not-so-stubby-area (NSSA)
                  (e) Totally NSSA
                  (f) Link-state advertisement (LSA) types
                  (g) Adjacency on a point-to-point and on a multi-access network
                  (h) OSPF graceful restart
         2.50 Implement IPv4 Enhanced Interior Gateway Routing Protocol (EIGRP)
                  (a) Best path
                  (b) Loop-free paths
                  (c) EIGRP operations when alternate loop-free paths are available,
                  and when they are not available
                  (d) EIGRP queries
                  (e) Manual summarization and autosummarization
                  (f) EIGRP stubs
         2.60 Implement IPv4 Border Gateway Protocol (BGP)
                  (a) Next hop
                  (b) Peering
                  (c) Internal BorderGateway Protocol (IBGP) and
                  External Border Gateway Protocol (EBGP)
         2.70 Implement policy routing
         2.80 Implement Performance Routing (PfR) and Cisco Optimized Edge Routing (OER)
         2.90 Implement filtering, route redistribution, summarization,
         synchronization, attributes, and other advanced features

3.00 Implement IPv6
         3.10 Implement IP version 6 (IPv6) addressing and different addressing types
         3.20 Implement IPv6 neighbor discovery
         3.30 Implement basic IPv6 functionality protocols
         3.40 Implement tunneling techniques
         3.50 Implement OSPF version 3 (OSPFv3)
         3.60 Implement EIGRP version 6 (EIGRPv6)
         3.70 Implement filtering and route redistribution

4.00 Implement MPLS Layer 3 VPNs
         4.10 Implement Multiprotocol Label Switching (MPLS)
         4.11 Implement LDP
         4.20 Implement Layer 3 virtual private networks (VPNs) on provider edge (PE),
         provider (P), and customer edge (CE) routers
         4.30 Implement virtual routing and forwarding (VRF) and Multi-VRF Customer Edge (VRF-Lite)

5.00 Implement IP Multicast
         5.10 Implement Protocol Independent Multicast (PIM) sparse mode
         5.20 Implement Multicast Source Discovery Protocol (MSDP)
         5.30 Implement interdomain multicast routing
         5.40 Implement PIM Auto-Rendezvous Point (Auto-RP),
         unicast rendezvous point (RP), and bootstrap router (BSR)
         5.50 Implementmulticast tools, features, and source-specific multicast
         5.60 Implement IPv6 multicast, PIM, and related multicast protocols,
         such as Multicast Listener Discovery (MLD)

6.00 Implement Network Security
         6.01 Implement access lists
         6.02 Implement Zone Based Firewall
         6.03 Implement Unicast Reverse Path Forwarding (uRPF)
         6.04 Implement IP Source Guard
         6.05 Implement authentication, authorization, and accounting (AAA)
         (configuring the AAA server is not required, only the client-side (IOS) is configured)
         6.06 Implement Control Plane Policing (CoPP)
         6.07 Implement Cisco IOS Firewall
         6.08 Implement Cisco IOS Intrusion Prevention System (IPS)
         6.09 Implement Secure Shell (SSH)
         6.10 Implement 802.1x
         6.11 Implement NAT
         6.12 Implement routing protocol authentication
         6.13 Implement device access control
         6.14 Implement security features

7.00 Implement Network Services
         7.10 Implement Hot Standby Router Protocol (HSRP)
         7.20 Implement Gateway Load Balancing Protocol (GLBP)
         7.30 Implement Virtual Router Redundancy Protocol (VRRP)
         7.40 Implement Network Time Protocol (NTP)
         7.50 Implement DHCP
         7.60 Implement Web Cache Communication Protocol (WCCP)

8.00 Implement Quality of Service (QoS)
         8.10 Implement Modular QoS CLI (MQC)
                  (a) Network-Based Application Recognition (NBAR)
                  (b) Class-based weighted fair queuing (CBWFQ), modified deficit round robin (MDRR),
                  and low latency queuing (LLQ)
                  (c) Classification
                  (d) Policing
                  (e) Shaping
                  (f) Marking
                  (g) Weighted random early detection (WRED) and random early detection (RED)
                  (h) Compression
         8.20 Implement Layer 2 QoS: weighted round robin (WRR), shaped round robin (SRR),
                  and policies
         8.30 Implement link fragmentation and interleaving (LFI) for Frame Relay
         8.40 Implement generic traffic shaping
         8.50 Implement Resource Reservation Protocol (RSVP)
         8.60 Implement Cisco AutoQoS

9.00 Troubleshoot a Network
         9.10 Troubleshoot complex Layer 2 network issues
         9.20 Troubleshoot complex Layer 3 network issues
         9.30 Troubleshoot a network in response to application problems
         9.40 Troubleshoot network services
         9.50 Troubleshoot network security

10.00 Optimize the Network
         10.01 Implement syslog and local logging
         10.02 Implement IP Service Level Agreement SLA
         10.03 Implement NetFlow
         10.04 Implement SPAN, RSPAN, and router IP traffic export (RITE)
         10.05 Implement Simple Network Management Protocol (SNMP)
         10.06 Implement Cisco IOS Embedded Event Manager (EEM)
         10.07 Implement Remote Monitoring (RMON)
         10.08 Implement FTP
         10.09 Implement TFTP
         10.10 Implement TFTP server on router
         10.11 Implement Secure Copy Protocol (SCP)
         10.12 Implement HTTP and HTTPS
         10.13 Implement Telnet

11.00 Evaluate proposed changes to a Network
         11.01 Evaluate interoperability of proposed technologies against deployed technologies
                  (a) Changes to routing protocol parameters
                  (b) Migrate parts of a network to IPv6
                  (c) Routing Protocol migration
                  (d) Adding multicast support
                  (e) Migrate spanning tree protocol
                  (f) Evaluate impact of new traffic on existing QoS design
         11.02 Determine operational impact of proposed changes to an existing network
                  (a) Downtime of network or portions of network
                  (b) Performance degradation
                  (c) Introducing security breaches
         11.03 Suggest Alternative solutions when incompatible changes
         are proposed to an existing network
                  (a) Hardware/Software upgrades
                  (b) Topology shifts
                  (c) Reconfigurations

 

Categories: CCIE, Routing Tags:

Data Loss Prevention

March 7th, 2011 No comments

Every once in a while I get to write a neat piece of code that I can share. This is one of those times. I realize it is not large and by PerlMonk standards not very elegant. The problem therein lies with maintainability over the next few years. Regardless I like what I wrote and would like to share.

At the Circus we had a pretty good idea that we had some data leakage. Nothing like people taking off with everything needed to get home loans and rip off customers, just people not thinking about what they send through email. We didn’t know the extent of the problem or even if we had one. We just weren’t sure. Our C-level executives didn’t believe that employees would be so careless with customer data. We decided to find out.

I must say that the results were actually quite positive. We had a couple of people email work related data home so they could work at home over the weekend and a few emails regarding employment, but they were originated by the prospective employee.

Regardless, in order for us to find out I wrote a few scripts that hook into our email system. One that I am particularly proud of recurses through a directory of email messages and attachments scanning each file for relevant data.

Please note that by the time these scripts touch the data it has been scrubbed by the antivirus and other checks we have in place. I am only looking for keywords or regular expressions that would indicate customer related data loss.

Let me explain the directory structure. Under the email system is the directory /var/spool/filter that contains every email message that has been sent in the last 30 minutes. There is a cleanup process that erases all the files in that directory and that is actually where I wrote the hook, in the cleanup process. Here is a sample listing of the directory.

#ls -1 /var/spool/filter/
msg-1299451572-29517-0
msg-1299451626-29523-0
msg-1299451695-29528-0
msg-1299452467-29565-0
msg-1299452491-29570-0
msg-1299453007-29593-0
msg-1299453086-29599-0

As you can see, each email header ends with a .hed extension and the message is in .txt format. The ETP.doc file is an attachment.

#ls -1 /var/spool/filter/msg-1299451626-29523-0/
ETP.doc
msg-29523-1.txt
msg-29523-2.dat.hed

The subroutine I am most pleased with is the one that recurses through the directory structure. The slurp command returns a hash and if it is a subdirectory then it is a hash as well. I look for it with the following line of code.

if (ref $structure->{$key} eq 'HASH')

That is how I find subdirectories to push onto the stack of recursive calls. As it traverses each directory it just looks at each file extension and makes a determination as to what to do with it.

I realize most system administrators are asking why I didn’t use the file command to make sure the script was acting appropriately for each file type but that does not work with the new Microsoft document types.

# file Test-Excel.xlsx
Test-Excel.xlsx: Zip archive data, at least v2.0 to extract

I thought it was a fun project and I enjoyed writing what I felt was an interesting piece of code.

#!/usr/bin/perl
# 2011-01-12 Jud Bishop
# This script goes looking for customer data being sent out through email and
# flags it for further review.
use strict;
use warnings;
use File::Find;
use File::Basename;
use File::Copy::Recursive qw(fcopy dircopy rcopy);
use File::Slurp::Tree;

#my $dir = "/home/jud/TestMessages";
#my $log = "/home/jud/TestMessages/violation";
#my $auditdir = "/home/jud/TestMessages/Trash/";
my $dir = "/var/spool/filter";
my $log = "/var/log/hipaa/violation";
my $auditdir = "/opt/smtpaudit/";
my $debug = 0;


###################
# MAIN
###################
my %tree;
my $tree = slurp_tree($dir);

open (LOG, '>>', $log) or die $!;

traverse_structure($dir, $tree);

close LOG or die $!;


##########
# This does the heavy lifting of the whole program.  It recursively
# iterates through the directory structure and works on a file accordingly.
# Each directory is a hash key.
##########
sub traverse_structure {
        if($debug){print "##traverse_structure\n";}
        my ($base, $structure) = @_;
        my $path;
    my @violation;
    my $secure;
        foreach my $key ( keys %$structure) {
                $path = $base . "/" . $key;
        $secure = 0;
        ## If it's a HASH then it's a directory.
                if (ref $structure->{$key} eq 'HASH'){
            if($debug){print "key: $key\n"};
                        traverse_structure( $path, $structure->{$key} );
                } else {
            if($debug){print "file  : $key\n"};
            if($debug){print "base  : $base\n"};
            if($debug){print "path  : $path\n"};
            if($debug){print "secure: $secure\n"};
            if($debug){print "violation: $#violation\n"};
   
            ## If the file is not being used...
            if ($path =~ m/doc$/){
                parse_doc($path, \@violation);
            } elsif ($path =~ m/xlsx$|xls$/) {
                parse_excel($path, \@violation);
            } elsif ($path =~ m/txt$/) {
                parse_message($path, \@violation);
            } elsif ($path =~ m/pdf$/) {
                parse_pdf($path, \@violation);
            } elsif ($path =~ m/hed$/) {
                parse_head($path, \@violation, \$secure);
            }
                }
    }
       # If it is a secure email than it is encrypted on
       # the fly and not a violation.
    if ( ($secure == 0) && ($#violation > 3) ){
        push (@violation, "EMAIL: " . $base);
        log_it(@violation);
        copy_dir($base);
    }
}

# For later review.
sub copy_dir {
    my $path = shift;
    if($debug){print "##copy_dir $path\n";}
    my $file = fileparse($path);
   
    if ($file =~ m/^msg/){
        my $basename = basename($path);
        my $newpath = $auditdir . $basename;
   
        if($debug){print "dircopy $path $newpath\n";}
        dircopy($path,$newpath);
    }
}

# Log file that is easy to ready because an employee goes through
# this file and decides if it is a REAL violation.
sub log_it {
    my @text = @_;
    my $line;
    if($debug){print "##log_it\n";}
    print LOG "---------------------------------------------\n";
    foreach $line (@text) {
        print LOG "$line\n";
    }
    print LOG "---------------------------------------------\n";
}

sub parse_head {
    my ($file, $violation_ref, $secure_ref) = @_;
    my @body;
    my $line;
    if($debug){print "##parse_head $file\n";}

    open(FILE,$file) || return 0;
        @body = <FILE>;
    close(FILE);

    foreach $line (@body)   {
        if ($line =~ m/^From/){
                        push (@$violation_ref, $line);
        } elsif ($line =~ m/^To/) {
                        push (@$violation_ref, $line);
        } elsif ($line =~ m/^Subject/) {
                        push (@$violation_ref, $line);
            if ($line =~ m/^secure/i )
            {
                $$secure_ref = 1;
            }
        }
    }
}

sub parse_pdf {
    my ($file, $violation_ref) = @_;
    my @body;
    my $new_file = $file . ".txt";
    my $CMD;

    if($debug){print "##parse_doc $dir $file\n";}
    $CMD = "/usr/bin/pdftotext \"" . $file . "\" > \"" . $new_file . "\"";
    if($debug){print "CMD: $CMD\n";}
        system($CMD);
        parse_text ($new_file, $violation_ref);
}

sub parse_doc {
    my ($file, $violation_ref) = @_;
    my @body;
    my $new_file = $file . ".txt";
    my $CMD;

    if($debug){print "##parse_doc $dir $file\n";}
    $CMD = "/usr/bin/antiword -st \"" . $file . "\" > \"" . $new_file . "\"";
    if($debug){print "CMD: $CMD\n";}
        system($CMD);
        parse_text ($new_file, $violation_ref);
}

sub parse_excel {
    my ($file, $violation_ref) = @_;
    my @body;
    my $new_file = $file . ".txt";
    my $CMD;

    if($debug){print "##parse_excel $file\n";}
    $CMD = "/usr/local/bin/antiexcel \"" . $file . "\" > \"" . $new_file . "\"";
    if($debug){print "CMD: $CMD\n";}
        system($CMD);
        parse_text ($new_file, $violation_ref);
}

sub parse_text {
    my ($file, $violation_ref) = @_;
    my @body;
    if($debug){print "##parse_text $file\n";}

    open(FILE,$file) || return 0;
        @body = <FILE>;
    close(FILE);

    compare_text(\@body, $violation_ref);
}

sub parse_message {
    my ($file, $violation_ref) = @_;
    my @body;
    if($debug){print "##parse_text $file\n";}

    open(FILE,$file) || return 0;
        @body = <FILE>;
    close(FILE);

    compare_text(\@body, $violation_ref);
}

# All of the earlier subroutines call this one.  
# It takes the text and looks for keywords.
sub compare_text {
    my ($text_ref, $violation_ref) = @_;
        my @difference;
    my @text_array;
    my @elements;
        my %count;
        my %rules;
        my $element;
    if($debug){print "##compare_text\n";}

    foreach $element (@$text_ref){
            @elements = split(' ', $element);
        push (@text_array, @elements);
    }

        # The parser was already created above.
        my @rule = ("DOB", "D.O.B.", "d.o.b.", "dob", "death:", "release", "admit", "admission", "Age:", "SSN", "Social", "Security", "Account", "Acct", "claimant", "MRI", "myelogram", "credit", "card");

    # Me being lazy.
        foreach $element (@rule)
        {
                $rules{$element} = 1;
        }

        foreach $element (@text_array)
        {
                if (exists $rules{$element})
                {
            if($debug){print "$element\n";}
            $element = "VIOLATION: " . $element;
                        push (@$violation_ref, $element);
                }
                # Social Security Number
                elsif($element =~ /\d{3}-?\d{2}-?\d{4}/)
                {
            if($debug){print "$element\n";}
            $element = "VIOLATION: " . $element;
                        push (@$violation_ref, $element);
                }
                # Credit Card Number or MRN
                elsif($element =~ /\d{4}-?\d{4}-?\d{4}-?\d{4}/)
                {
            if($debug){print "$element\n";}
            $element = "VIOLATION: " . $element;
                        push (@$violation_ref, $element);
                }

        }
}
Categories: Code, Linux Tags:

Mac OSX tftp server

February 23rd, 2011 No comments

At the Circus we have a network management server that runs all of the normal services needed to manage a small network and so I rarely need to fire up the tftp server on my laptop. Today was one of those days I needed a quick tftp server and I spent too much time figuring it out. This is my attempt to remedy that shortcoming.

What is ironic is that after I googled around I found that I had “self documented” in the /private/tftpboot directory, unfortunately I expected the tftp directory for the tftp server to be in /tftpboot. I realize I can just put a symlink from /tftpboot to /private/tfpboot but I learned when working on AIX it is better to understand the file system layout of a UNIX vendor than it is to make it like another OS. It will bite you eventually.

Here is a listing of the /private/tftboot directory, you will notice the very last file is tftp.txt. That is where I told myself how to do this in the past. It also appears most of the IOS images were for the testlab.

asa821-k8.bin
c1841-adventerprisek9-mz.150-1.M.bin
c2500-is-l.123-26.bin
c2600-adventerprisek9-mz.124-25c.bin
c3560e-ipbasek9npe-mz.122-55.SE1.bin
c3620-j1s3-mz.123-26.bin
c3640-a3js-mz.124-25b.bin
c3640.txt
tftp.txt

This is what I had listed in the tftp.txt file. It tells how to start and stop a service in Mac OSX using launchctl.

sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist
sudo launchctl unload -F /System/Library/LaunchDaemons/tftp.plist

For thoroughness I am including the tftp.plist file below. If I wanted the tftp daemon to start every time I turned on my laptop I would change Disabled to EnableTransactions.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <true/>
    <key>Label</key>
    <string>com.apple.tftpd</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/libexec/tftpd</string>
        <string>-s</string>
        <string>/private/tftpboot</string>
    </array>
    <key>inetdCompatibility</key>
    <dict>
        <key>Wait</key>
        <true/>
    </dict>
    <key>InitGroups</key>
    <true/>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
            <key>SockServiceName</key>
            <string>tftp</string>
            <key>SockType</key>
            <string>dgram</string>
        </dict>
    </dict>
</dict>
</plist>
Categories: Musings, Routing Tags:

CCIE

February 6th, 2011 No comments

I have added a CCIE category to the blog. Although I have been studying steadily I have only posted testlab scripts to date. I will most likely post very little CCIE specific content while I continue to study for the written until I am much closer to my written test day.

I have really struggled with my structure studying for the written. I am a hands on learner and cramming a bunch of reading without application makes it difficult for me to remember and understand the nuances of a technology. I would rather play with a protocol and learn about it through interaction than try to memorize a bunch of random facts for the written test. Recently I have been doing INE Workbook 1 labs as I feel they complement my reading well. They are not difficult and explore the intricacies of one protocol at a time. It is easy for me to do a lab and play around with the protocol to learn.

Reading another candidates blog I ran across his study plan which was taken from
this post. At the end of that blog entry is a list of core INE Workbook 1 labs you should do while preparing for the lab. They are below for convenience.

Bridging & Switching: 1.1-1.15
Frame-Relay: 2.1-2.10
IP Routing: 3.1-3.11
RIP: 4.1-4.6
EIGRP: 5.1-5.8
OSPF: 6.1-6.11, 6.21-6.31
BGP: 7.1-7.9, 7.16-7.26
IPv6: 9.1-9.5, 9.12-9.14, 9.17-9.20, 9.29-9.31
MPLS VPN: 14.1-14.7

That is 109 labs that INE recommends you complete before moving to more advanced labs which gives me a goal and structure. I plan to do these labs in the coming months to complement my reading. That also means I need only do 11 labs per month so I will cut back on labs on the weekends and do more reading and note taking. Actually I have already done ~25 of these labs so it is even fewer labs I need to do but I will do many of them multiple times so I’m not going to quibble with the numbers.

I have completely finished reading and taking notes for TCP/IP Vol I and am half way through Vol II. I will then read the Switching Exam Certification Guide and the QoS Exam Certification Guide again, followed by the CCIEv4 Exam Certification Guide. My goal is to pass the written next winter.

To put dates to my goals:
31 March — Finish Volume II
(Second child is due in April.)
30 June — Finish reading Switching Exam Certification Guide
31 August — Finish reading QoS Exam Certification Guide
31 October — Finish reading CCIEv4 Exam Certification Guide

Finally when I begin reading the CCIEv4 Exam Certification Guide I will begin to post more of my notes. What I found when studying for my CCNP was that immediately after I finished putting all of my notes on the web for a test was when I was the most prepared for theory based exams.

Categories: CCIE Tags:

Veritas/Symantec Baremetal Restore

February 1st, 2011 No comments

I spent a considerable amount of time over the last couple of months testing different restore processes. This is my documentation for restoring Veritas/Symantec backups to a Linux server.

The general outline is this:
1. Create a LiveUSB drive to boot CentOS with a persistent overlay.
2. Install Symantec backupexec on the LiveUSB drive.
3. Recreate the drive layout on the new server.
4. Restore to the new server.

Create LiveUSB
CentOS makes a LiveCD toolset for CentOS. They also have directions for how to create a LiveUSB drive with persistent overlay. Please follow those links for more in depth directions.

You must install CentOS LiveUSB on an ext2/3/4 formatted USB drive in order for Symantec to work. If you leave the VFat partition Symantec will not work properly and you will get the error “An unknown error occurred within the NDMP subsystem.” Once I reformatted the USB drive as ext3 and installed a new LiveUSB with persistent overlay Symantec worked. My guess is it has to do with permission bits but that is only a guess.

I downloaded the LiveCD tools for Centos here.

Here is some of my history from that server:

umount /mnt
fdisk /dev/sdb
mkfs -t ext3 /dev/sdb1
mkfs -t ext3 /dev/sdb2
livecd-iso-to-disk --overlay-size-mb 1500 CentOS-5.5-i386-LiveCD.iso /dev/sdb1
mount /dev/sdb1 /mnt
ls /mnt

LiveUSB Setup
I wanted to give it a persistent name and IP address for use in our data center. For some of this I was also shooting in the dark in order to get Symantec working, for thoroughness I include it here.

vi /etc/sysconfig/network
HOSTNAME=recovery.chainringcircus.org
vi /etc/sysconfig/networking/devices/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.1.200
GATEWAY=192.168.1.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
DNS1=192.168.1.201
DNS2=192.168.1.202
DOMAIN=chainringcircus.org

After I configured the hostname and network settings I rebooted to make sure that the persistent overlay worked. I also turned on sshd and set it to runlevel 3 in /etc/inittab because I did not want to mess with a gui, but that is your choice. When everything came up properly I installed Symantec and we did a test restore.

Install Symantec
I cover installing Symantec on Linux in another post here. You need to install an older package for compatibility:

yum install compat-libstdc++-296-2.96-138.i386

The specific Symantec rpms I installed are listed below. I did try a newer package from Symantec but it did not allow us to restore erroring with a different message. I will also say that was when we were on a VFat partition. Once I got everything working on an ext3 partition I quit testing.

VRTSvxmsa-4.2.1-211.i386.rpm
VRTSralus-10.00.5629-0.i386.rpm

Recreate Drive Layout
For thoroughness I am going to cover creating the logical volumes that are default for CentOS and RHEL.

First I need to lay out the drive mappings. This is from the old server which I am cloning onto a similar server. In this section I am just going to show the output of a number of commands that confirm the file system layout of the server.

File layout on the old server
From the file /etc/fstab:

LABEL=/boot             /boot                   ext3    defaults        1 2
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0

From the mount command:

/dev/sda1 on /boot type ext3 (rw)
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)

From the fdisk command:

Disk /dev/sda: 219.8 GB, 219823472640 bytes
255 heads, 63 sectors/track, 26725 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       26725   214564140   8e  Linux LVM

Working my way up from the bottom of the LVM stack with the physical volume, the volume group and finally the logical volume.

From pvdisplay:

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               204.62 GB / not usable 31.29 MB
  Allocatable           yes
  PE Size (KByte)       32768
  Total PE              6547
  Free PE               4
  Allocated PE          6543
  PV UUID               jAuzGO-3Zpz-4T3K-mqcI-Ql6D-1dqf-wj917q

From vgdisplay:

  --- Volume group ---
  VG Name               VolGroup00
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               204.59 GB
  PE Size               32.00 MB
  Total PE              6547
  Alloc PE / Size       6543 / 204.47 GB
  Free  PE / Size       4 / 128.00 MB
  VG UUID               LJc2HJ-D7Gr-ketA-5TSe-ppQM-m5di-4YMEgZ

From lvdisplay:

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                HcyaVT-DOEs-1Rdy-h7af-7i0t-P0EF-K2cCxy
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                202.53 GB
  Current LE             6481
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                ZpAnvu-Of5D-PoEO-HaDN-2krv-zIXp-1fF5av
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

On the old server the drive is broken into two partitions, sda1 and sda2:
sda1 /boot 100MB
sda2 Volume Group ~200GB

The volume group on the old server on the sda2 partition is broken into two logical volumes:
LogVol00 / ~200GB
LogVol01 swap ~2GB

It is important to remember that the drive mappings on the old server will not necessarily match the mappings on the new one. For instance on the old server the raid was on /dev/sda and on the new server the raid drive is mapped on /dev/sdb. That is only because I am booting from /dev/sda on the LiveUSB, under normal circumstance it will come back up as /dev/sda.

Working on the new server recreate the partitions

fdisk /dev/sdb
Command (m for help): p

Disk /dev/sdb: 1199.9 GB, 1199906488320 bytes
255 heads, 63 sectors/track, 145880 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-145880, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-145880, default 145880): +200M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (26-145880, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-145880, default 145880):
Using default value 145880

Command (m for help): a
Partition number (1-4): 1

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 1199.9 GB, 1199906488320 bytes
255 heads, 63 sectors/track, 145880 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          25      200781   83  Linux
/dev/sdb2              26      145880  1171580287+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
  /usr/sbin/lvmdiskscan
  /dev/ramdisk       [       16.00 MB]
  /dev/live-squashed [      669.80 MB]
  /dev/root          [        4.00 GB]
  /dev/ram           [       16.00 MB]
  /dev/live-osimg    [        4.00 GB]
  /dev/live          [        7.45 GB]
  /dev/ram2          [       16.00 MB]
  /dev/live-overlay  [        1.46 GB]
  /dev/sda2          [        7.47 GB] LVM physical volume
  /dev/ram3          [       16.00 MB]
  /dev/ram4          [       16.00 MB]
  /dev/ram5          [       16.00 MB]
  /dev/ram6          [       16.00 MB]
  /dev/ram7          [       16.00 MB]
  /dev/ram8          [       16.00 MB]
  /dev/ram9          [       16.00 MB]
  /dev/ram10         [       16.00 MB]
  /dev/ram11         [       16.00 MB]
  /dev/ram12         [       16.00 MB]
  /dev/ram13         [       16.00 MB]
  /dev/ram14         [       16.00 MB]
  /dev/ram15         [       16.00 MB]
  /dev/sdb1          [      196.08 MB]
  /dev/sdb2          [        1.09 TB]
  7 disks
  16 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume

Turn off the the LVM in order to make changes, this is just a precautionary step if you have repartitioned your drive.

lvm vgchange -an

Create the LVM.

  vgscan
  Reading all physical volumes.  This may take a while...

  pvcreate -ff /dev/sdb2
  Physical volume "/dev/sdb2" successfully created

Create and activate the volume groups.

  vgcreate VolGroup00 -l 0 -p 0 -s 32m /dev/sdb2
  Volume group "VolGroup00" successfully created

  vgchange -ay VolGroup00
  0 logical volume(s) in volume group "VolGroup00" now active

Finally, create the logical volumes. Even though I have 1.1T I decided to start using 800G, leaving myself room if I want to add another mount point.

  lvcreate -L 800000m -r auto -n LogVol00 VolGroup00
  Logical volume "LogVol00" created

  lvcreate -L 4096m -r auto -n LogVol01 VolGroup00
   Logical volume "LogVol01" created

Read in the new volume groups.

  vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup00" using metadata type lvm2

Format all of the partitions:

mkfs -t ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
[output removed for brevity]
mkfs -t ext3 /dev/VolGroup00/LogVol00
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
[output removed for brevity]
mkswap /dev/VolGroup00/LogVol01
Setting up swapspace version 1, size = 4294963 kB

Here are some quick commands if you mess up and need to delete any of the LVM stack.

lvremove -f /dev/VolGroup00/LogVol00
lvm lvremove -f /dev/VolGroup00/LogVol01
lvm vgchange -a n VolGroup00
lvm vgremove VolGroup00

Restore
Mount the root under /mnt and then have Veritas restore to that mount point.

mount -t ext3 /dev/VolGroup00/LogVol00 /mnt

If you have made it this far then you must really need the information. Here are a couple of screenshots from our backup guru to help in the restore process.

“Preserve Tree”, by default it is selected.
de-select

Select “Restore over existing files”, “Restore all information for files and directories” and “Preserve tree”.
select

Install grub on the new machine
During the restore we restored all of the files and directories to /mnt, including /boot. In order to get everything working again we need to setup the boot directory and then grub. But Red Hat and CentOS 4.X uses legacy grub.

Copy all of /mnt/boot to the real /boot directory.

mkdir /mnt/newboot
mount /dev/sdb1 /mnt/newboot
cp -r /mnt/boot/* /mnt/newboot/

umount /mnt/newboot

mount /dev/sdb1 /boot

grub> root (hd1,0)
 Filesystem type is ext2fs, partition type 0x83

grub> find /grub/stage1
 (hd1,0)

grub> setup (hd1)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd1)"...  16 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd1) (hd1)1+16 p (hd1,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.

grub > quit

Restore /dev and /tmp
Depending upon your backup options you may need to restore the /dev directory and create a tmp directory. You need to set the sticky bit on /tmp.

cp devices.tar /mnt/lvm/VolGroup00-LogVol00/
cd /mnt/lvm/VolGroup00-LogVol00/
tar -tvf devices.tar
tar -xvf devices.tar

chroot /mnt/lvm/VolGroup00-LogVol00/
mkdir /tmp
ls -al /
chmod a+rwx /tmp
chmod +t /tmp
exit

Finally you need to set up your ethernet interfaces by editing the file,
/etc/sysconfig/networking/devices/ifcfg-eth0

Categories: Linux Tags:

Password Aging

January 28th, 2011 No comments

At the Circus we have a password policy to change all passwords every 90 days. Today it was brought to my attention that one of the linux servers was not following that policy. I confirmed that was true and after a little digging I found that it was only accounts that had been migrated from AIX to linux. But we couldn’t force around 2000 users to all change their passwords at the same time because we would inundate the help desk.

This is the script that I wrote to fix the problem and distribute the password changes over a month. The result is that there are only 78 users per day that are forced to change their password each day over a 28 day period.

#!/bin/bash
# 2011-01-28
# Jud Bishop
# Checks for passwords set to never expire and gives an expiration date.
# Distributes the password changes over a 28 day spread.

X=0;

for I in `cat /etc/passwd | cut -d: -f 1`
do
        #echo $I
        #chage -l $I | egrep "Password expires" | cut -d : -f 2

        DATE=`chage -l $I | egrep "Password expires" | cut -d : -f 2 | cut -d \  -f 2`
        if [ $DATE = "never" ]
        then
                echo $I
                if [ $X -le "27" ]
                then
                        X=`expr $X + 1`
                else
                        X=1;
                fi
                echo $X $I
                chage -d  2010-11-$X -M 90 $I
        fi
done
Categories: Code, Linux Tags:

Military Personnel

January 8th, 2011 No comments

I just finished reading an article in the Atlantic concerning military personnel and recruitment titled “Why Our Best Officers Are Leaving.” As a veteran and former officer who enjoyed my time in service I felt the urge to comment publicly.

My stint in the Air Force was the formative years of my professional development. The military formed many of the core beliefs I have today. My view on documentation and succession are much different than my most of my private sector peers. One maxim that my wife and I do not see eye to eye on, “Early is on time, on time is late, late you have a problem.” Another saying that was often repeated was, “Do your current job well and your next job will take care of itself.”

Today my hair is just as short as when I was in, if not shorter and my shoes are still spit shined. Only my uniform has changed; from blues or BDUs to khakis and polos or slacks and dress shirts.

But what I really wanted to comment on was my career development. My first encounter with the Air Force Personnel Center (AFPC) was even before I went active duty. When we got our assignments as college seniors mine was to Offutt AFB, Nebraska. As a cyclist I was not pleased to be heading to a station with a 2 month summer, with fall and spring similarly abbreviated. My commanding officer at the detachment asked me if I wanted him to make a call to AFPC on my behalf and see if I get a more amenable station. I declined stating that I didn’t want to start my time in the Air Force fighting the system.

I worked hard at Offutt. Not as many hours as I do now, but I learned a great deal. The one big project I handled was the leg work, research and negotiation to settle a $1M lawsuit against the base. Our Colonel had given three of us the project and I was the one that finished the job. The other two lieutenants just didn’t find it interesting.

An aside. I was also given the task to get a squadron t-shirt designed and approved, but I just couldn’t find the time. Someone else finally did it. Now I believe it would have been a good experience because you had to work through all the red tape, but I just didn’t find that appealing.

When it came time for me to change duty stations my commanding officer called me into his office and told me he had made some phone calls and found me a position at the Air Force Logistics Management Agency (AFLMA).

I don’t believe what I did at the AFLMA was outstanding, I ran a website for the Air Force the last couple of years I was in. The website had pretty high visibility and I gave presentations to nearly every full bird Colonel and met privately with every General in my career field. I traveled extensively during this time and gave presentations like I was a salesman.

Another aside. I got married on Saturday and left for Washington, DC Sunday to give a presentation Monday morning at the Pentagon.

When I declared my intention to leave the Air Force the AFPC representative for my career field took me to lunch. He offered to station me anywhere in the world. When I told him my wife was English/South African and we were considering moving to England he offered to double billet me in England. Next he offered me a nice opening in New Zealand where I would be in charge of my own office. I declined them both and ended up in graduate school.

I just figured every Lieutenant and Captain had the same experience I did. You work hard, show initiative and let your mentors steer you through the maze of jobs and promotions. Imagine my surprise when I found that is not the case in the private sector.

Categories: Musings Tags:

Another TestLab Script

January 5th, 2011 No comments

I’m sorry that all of these TestLab scripts are a recurring theme. Work purchased four 3560s and two 1841s for the lab so I have been updating all of my scripts. When I was working on the lab I kept having sessions hang so I wrote a quick script to clear all of the lines on the terminal server.

#!/usr/bin/expect
# 2010-12-14 Jud Bishop
# tl-clear
# A short script to handle logging into a router in the lab.

set host "testlab.chainringcircus.org"
set pass "CHANGEME"
set enable "CHANGEME2"
set ctrlz \032

##############################
# Should not need any more changes.

spawn telnet $host
expect "Password:"
send "$pass\r"
expect "testlab>"
send "enable\r"
expect "Password:"
send "$enable\r"
expect "testlab#"
sleep 1

for { set i 1} {$i < 48} {incr i 1} {
    send "clear line $i\r"
    expect {
        -re ".*confirm.*" {send "y \r"}
        -re ".*Not allowed to clear current line.*" {send "\r"}
        -re ".*Invalid input detected at.*" {send "\r"}
    }
}
exit
Categories: Code, Routing Tags: