Knowledgebase
linux clients
Posted by Jason Gerfen on 05 May 2010 06:57 AM

Linux Client/Desktop Information


This page should help you with the installation, configuration, administration and troubleshooting of a new linux client. We are currently using a Gentoo based linux distribution.

Installation


Manual Installation




  1. HDD Configuration



    • In order to install new linux desktop you will need a bootable System Rescue CD as we currently do not have the auto configuration scripts or a linux bootable image loaded on the PXE server. You can download the System Rescue CD from [http://www.sysresccd.org/Download here].

    • Once you have a bootable System Resuce CD simply boot to the CD-ROM on the machine you wish to install the linux image

    • Next you will have to format the existing HDD using fdisk. Below is an example of determining the current disk information:

      %> fdisk -l

      Disk /dev/sda: 160.0 GB, 160041885696 bytes
      255 heads, 63 sectors/track, 19457 cylinders
      Units = cylinders of 16065 * 512 = 8225280 bytes
      Disk identifier: 0x00000000

      Device Boot Start End Blocks Id System
      /dev/sda1 * 1 17 136521 83 Linux
      /dev/sda2 18 19457 156151800 5 Extended
      /dev/sda5 18 3665 29302528+ 83 Linux
      /dev/sda6 3666 3790 1004031 82 Linux swap / Solaris
      /dev/sda7 3791 19457 125845146 83 Linux


    • Now that we know our main HDD is on '/dev/sda' we can perform a format and recreation of the our desired HDD partitions (the 'fdisk /dev/sda' will drop us into the fdisk shell where we can perform commands):

      %> fdisk /dev/sda

      The number of cylinders for this disk is set to 19457.
      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)

      Command (m for help): d
      Partition number (1-7): 1
      Command (m for help): d
      Partition number (1-7): 2


    • Now that we have removed the existing partition tables we can proceed to recreate them (First we will create our '/boot' partition):

      Command (m for help): n
      Command action
      e extended
      p primary partition (1-4)
      p (ENTER)
      1 (ENTER)
      (ENTER)
      +128M (ENTER)


    • Now we will create an extended partition which broken up into logical partitions for '/home', '/' & '/swap':
       
      Command (m for help): n
      Command action
      e extended
      p primary partition (1-4)
      e (ENTER)
      2 (ENTER)
      (ENTER)
      (ENTER)


    • The next partition will be our first logical partition for '/':

      Command (m for help): n
      Command action
      l logical (5 or over)
      p primary partition (1-4)
      l (ENTER)
      5 (ENTER)
      (ENTER)
      +30000M (ENTER)


    • Now another logical partition for our '/swap' disk:

      Command (m for help): n
      Command action
      l logical (5 or over)
      p primary partition (1-4)
      l (ENTER)
      6 (ENTER)
      (ENTER)
      +1024M (ENTER)


    • Our final logical partition will be used for the '/homes' directory and should take up the remainder of partition 2 on /dev/sda:

      Command (m for help): n
      Command action
      l logical (5 or over)
      p primary partition (1-4)
      l (ENTER)
      7 (ENTER)
      (ENTER)
      (ENTER)


    • Now we need to set the bootable flag to our primary partition on /dev/sda1:

      Command (m for help): a
      1 (ENTER)


    • We need to set our partition type as 'swap' on the logical partition /dev/sda6:

      Command (m for help): t
      6 (ENTER)
      82 (ENTER)


    • Now we just need to write out the partition schemes, but lets make sure your output looks like the following:

      Command (m for help): p

      Disk /dev/sda: 160.0 GB, 160041885696 bytes
      255 heads, 63 sectors/track, 19457 cylinders
      Units = cylinders of 16065 * 512 = 8225280 bytes
      Disk identifier: 0x00000000

      Device Boot Start End Blocks Id System
      /dev/sda1 * 1 17 136521 83 Linux
      /dev/sda2 18 19457 156151800 5 Extended
      /dev/sda5 18 3665 29302528+ 83 Linux
      /dev/sda6 3666 3790 1004031 82 Linux swap / Solaris
      /dev/sda7 3791 19457 125845146 83 Linux


    • Now to write out the current partition information and we can move on to the next part of the installation:

      Command (m for help): w






  2. Network setup



    • Now that we have our HDD prepared we are now ready to temporarily initialize the networking interface in order to connect to the image server.

    • First lets get the interface enabled. The command shown below will show us a list of available network interfaces on the machine.

      %> /sbin/ifconfig
      eth0 Link encap:Ethernet HWaddr 00:0E:0C:CF:85:66
      inet6 addr: fe80::20e:cff:fecf:8566/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:11155260 errors:0 dropped:0 overruns:0 frame:0
      TX packets:5943291 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:100
      RX bytes:8421010012 (8030.9 Mb) TX bytes:712474265 (679.4 Mb)
      Base address:0xe400 Memory:febc0000-febe0000

      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING MTU:16436 Metric:1
      RX packets:336 errors:0 dropped:0 overruns:0 frame:0
      TX packets:336 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:19280 (18.8 Kb) TX bytes:19280 (18.8 Kb)


    • If you only have the 'lo' interface shown you may need to initialize the 'eth0' or 'eth1' interface using the following command:

      %> /sbin/ifconfig eth0 up
      %> /sbin/ifconfig eth1 up


    • Because we use something called a 'statically configured DHCPD server' for ALL of the lab & public computing areas (this helps prevent rogue client connections on the network), You may need to obtain the 'MAC' or Hardware address of the machine and add it to the list of static hosts using the [https://dhcp.scl.utah.edu phpDHCPAdmin application]. If you are unsure of which IP configuration information to assign this host please refer to the current list of IP per lab/public area page. (link up soon).

    • Next you will need to have our linux client attempt to obtain an IP address (again, the client must be configured on the DHCPD server prior to this step), subnet mask, and gateway in order to connect to our image server where we can finish the installation process. To have our client obtain an IP through DHCP perform the following command:

      %> /etc/init.d/net.eth0 restart
      %> /etc/init.d/net.eth1 restart
      %> /sbin/ifconfig
      eth0 Link encap:Ethernet HWaddr 00:0E:0C:CF:85:66
      inet addr:155.97.16.161 Bcast:155.97.16.255 Mask:255.255.255.128
      inet6 addr: fe80::20e:cff:fecf:8566/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:11159537 errors:0 dropped:0 overruns:0 frame:0
      TX packets:5946153 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:100
      RX bytes:8426028757 (8035.6 Mb) TX bytes:712963149 (679.9 Mb)
      Base address:0xe400 Memory:febc0000-febe0000

      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING MTU:16436 Metric:1
      RX packets:336 errors:0 dropped:0 overruns:0 frame:0
      TX packets:336 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:19280 (18.8 Kb) TX bytes:19280 (18.8 Kb)


    • The 'inet addr' section should show you a valid IP address. Now we should ensure we have a valid Gateway & Subnet information assigned from the DHCP server. You can look at this configuration information with the following command(s):

      %> /sbin/route
      Kernel IP routing table
      Destination Gateway Genmask Flags Metric Ref Use Iface
      155.97.16.128 * 255.255.255.128 U 0 0 0 eth0
      loopback * 255.0.0.0 U 0 0 0 lo
      default 155.97.16.129 0.0.0.0 UG 0 0 0 eth0




  3. Network Share Connection



    • Now that we have our required information assigned to our network interface, lets map a network folder to this machine so we may proceed to finish up the installation. The current image server is a network share on 'odin.scl.utah.edu'. The following command will get our share mapped locally:

      %> mkdir /mnt/odin
      %> mount -o username=,password= //odin.scl.utah.edu/images /mnt/odin
      %> ls /mnt/odin
      4200XP-F.002 4200XP-H.011 CNTR-C.011 CNTR-E.023 XP1735-A.014
      4200XP-F.003 4200XP-H.012 CNTR-C.012 CNTR-E.024 XP1735-A.015
      4200XP-F.004 4200XP-H.013 CNTR-C.013 CNTR-E.PQI XP1735-A.016
      4200XP-F.005 4200XP-H.014 CNTR-C.014 CW.ERR XP1735-A.017
      4200XP-F.006 4200XP-H.015 CNTR-C.015 FICHE-F.002 XP1735-A.018
      4200XP-F.007 4200XP-H.016 CNTR-C.016 FICHE-F.003 XP1735-A.019
      4200XP-F.008 4200XP-H.017 CNTR-C.017 FICHE-F.004 XP1735-A.020
      4200XP-F.009 4200XP-H.018 CNTR-C.018 FICHE-F.PQI XP1735-A.021
      ....





  4. Transferring Linux Image to HDD



    • Ok now we can proceed to use the 'partimage' application to push the remote compressed image onto the local HDD. The following commands are scripted to allow you to skip prompts from the 'partimage' software: (this may take some time to finish)

      %> partimage restore /dev/sda1 /mnt/odin/dev/Gentoo32-O-sda1-128MB.000
      %> partimage restore /dev/sda5 /mnt/odin/dev/Gentoo32-O-sda5-30GB.000
      %> partimage restore /dev/sda7 /mnt/odin/dev/Gentoo32-O-sda7-30GB.000





Automated Installation




  1. HDD Configuration



    • Because we needed a method of automatically detecting, removing and recreating partitions within a Linux kernel a script was developed to assist to remove the need for human interaction. Below is an example of using the script as an interactive application:

      %> ./disks
      Choose partition scheme...
      >> 1 - Standard (default)
      >> 2 - Extended
      >> 3 - Logical extended
      >> 4 - Scheme help
      >> 5 - About
      >> 6 - Quit
      Enter your selection:


    • And here is an example of a scripting usage to assist in automation. During the USB Key boot process this script should automatically initialize based on configured options:

      %> ./disks default | extended | logical


    • The details listed below show details on the 3 current partition scheme types

      Current Partition schemes available:
      Standard (default) partition scheme:
      Primary (bootable) [/:ALL] | Swap [/swap:1GB]

      Extended partition scheme:
      Primary (bootable) [/:30GB] | Swap [/swap:1GB] | Primary [/home:ALL]

      Logical extended partition scheme:
      Primary (bootable) [/boot:128MB]
      -Extended [ALL]
      -Logical [/:30GB] | Swap [/swap:1GB] | Extended [/home:ALL]


    • This automated disk partitioning utility can be downloaded [http://bashautopartition.scl.utah.edu/downloads/bashautopartition.tgz here] and the current project details can be found [http://tyr.scl.utah.edu/index.php/BashAutopartition here].





  2. Network Setup



    • With this script we can automate the network configuration and startup.

      #!/bin/bash
      dhcpcd eth0
      dhcpcd eth1





  3. Network Share Connection



    • Here we automate the network share connectivity

      #!/bin/bash
      mkdir /mnt/odin
      mount -t smbfs -o username=,password= //odin.scl.utah.edu/images /mnt/odin





    Transfering Linux Image to HDD



    • This portion of the linux client installation allows us to automate the linux image extraction process

      #!/bin/bash
      partimage -e -B=x restore /dev/sda1 /mnt/odin/dev/
      partimage -e -B=x restore /dev/sda1 /mnt/odin/dev/
      partimage -e -B=x restore /dev/sda1 /mnt/odin/dev/






Automated Installation USB ISO File



  1. To make this automated installation very simple you can download the USB Drive ISO [http://bashautopartition.scl.utah.edu/downloads/auto-gentoo-install-usb.iso here]. It is based on the [http://www.sysresccd.org/Sysresccd-manual-en_How_to_install_SystemRescueCd_on_an_USB-stick RescueCD USB Guide] minus the custom utilities I outlined above.

  2. Once you have the .ISO file downloaded you will need to create a vfat file system on your USB disk

    %> mkfs.vfat /dev/

  3. Make sure the USB drive is bootable with the [http://syslinux.zytor.com/ syslinux] utility with the following command

    %> syslinux /dev/
    %> sync

  4. Now extract the ISO file onto our USB drive

    %> dd if=auto-gentoo-install-usb.iso of=/dev/

  5. At this point you should be able to boot to the USB drive and it should partition the local drive, setup the temporary networking interface, mount a remote share and extract the Linux client OS onto the drive.



Configuration


Manual Configuration




  1. How to Mount & Chroot to new Image OS



    • Because we have a new image on the current HDD we will need to mount the file system then we can use a utility called 'chroot' to change into the OS to make system wide configuration changes. (The '/proc', 'swap' etc. are required for the chroot and system updates)

      %> mkdir /mnt/new
      %> mkdir /mnt/new/{boot,root}
      %> mkdir /mnt/new/root/home
      %> mkswap /dev/sda6
      %> mount /dev/sda5 /mnt/new/root
      %> mount /dev/sda1 /mnt/new/root/boot
      %> mount /dev/sda7 /mnt/new/root/home
      %> mount -t proc none /mnt/new/root/proc
      %> mount -o bind /dev /mnt/new/root/dev


    • Now that we have our partitions mounted we can essentially change or 'chroot' into this and use it as our Operating system

      %> chroot /mnt/new/root /bin/bash






  2. GRUB & Bootloader Configuation



    • Next we need to do some configuration for the GRUB boot loader and also load GRUB onto the MBR

      %> grep -v rootfs /proc/mounts > /etc/mtab
      %> grub-install /dev/sda





  3. Static Network Address Configuration



    • First we will assign a unique hostname to our machine

      %> echo "newhost" >> /etc/conf.d/hostname


    • Here is an example of setting up the ip address netmask and gateway information

      %> echo "config_eth0=("155.97.16.161 netmask 255.255.255.128")" >> /etc/conf.d/net
      %> echo "routes_eth0=("default via 155.97.16.129")" >> /etc/conf.d/net


    • Now we will need to provide some information regarding your DNS servers. This is used to resolve FQDN information.

      %> echo "Search SCL.UTAH.EDU" >> /etc/resolv.conf
      %> echo "domain scl.utah.edu" >> /etc/resolv.conf
      %> echo "nameserver 155.97.15.2" >> /etc/resolv.conf
      %> echo "nameserver 155.97.16.130" >> /etc/resolv.conf






  4. Printer Configuration



    • And finally we need to configure the printer settings for the area (MMC, Union, Benchmark Labs & Public areas)

      %> cp /etc/cups/{NAME OF LAB/PUBLIC AREA FILE} /etc/cups/printers.conf






  5. Cleanup & Restart



    • Now we just need to cleanup and restart the machine

      %> exit
      %> unmount /mnt/new/boot
      %> unmount /mnt/new/root/dev
      %> unmount /mnt/new/root/proc
      %> unmount /mnt/new/root/home
      %> unmount /mnt/new/root
      %> reboot






Automated Configuration




  1. Automount HDD Partitions & CHROOT Automation ====

    • We automate the mounting of our newly imaged partitions and chroot into the new OS environment using the script show below:








  2. The 'execute-configs' script



    • This script is used to execute all of the system configuration scripts for networking, printing etc.

      #!/usr/bin/perl
      #
      # execute-configs
      # Gathers active network interface information
      # Executes system configuration scripts with
      # network information as optional switches
      #
      # 08.05.2008
      # jason.gerfen@scl.utah.edu
      #

      use strict;
      use Net::FTP;

      my $ifconfig = '/sbin/ifconfig';

      my ( $ftp,
      $ETH,
      $MAC,
      $IP,
      %ETH ) = '';

      my $code = "0";
      my $ifconfig = "/sbin/ifconfig";

      sub GetActiveInterface {
      open( DATA, "$ifconfig |" ) || die "ERROR: Could not open network interface.\n";
      while( my $data = ) {
      if( $data =~ /(eth[0-9]).*HWaddr\s([0-9a-f]{2}\:[0-9a-f]{2}\:[0-9a-f]{2}\:[0-9a-f]{2}\:[0-9a-f]{2}\:[0-9a-f]{2})/i ) {
      $ETH{ 'ETH' } = $1;
      $ETH{ 'MAC' } = $2;
      }
      if( ( $data =~ /inet\saddr:((\d+){1,3}\.(\d+){1,3}\.(\d+){1,3}\.(\d+){1,3})/ ) && ( $data !~ /127.0.0.1/ ) ) {
      $ETH{ 'IP' } = $1;
      }
      if( &ChkData( $ETH{ 'ETH' }, $ETH{ 'MAC' }, $ETH{ 'IP' } ) == 0 ) {
      $ETH = $ETH{ 'ETH' }; $MAC = $ETH{ 'MAC' }; $IP = $ETH{ 'IP' };
      }
      }
      close( DATA );
      }

      sub ChkData( $eth, $mac, $ip ) {
      my $ret; my $eth = shift; my $mac = shift; my $ip = shift;
      if( ( defined( $eth ) ) && ( defined( $mac ) ) && ( defined( $ip ) ) ) {
      if( ( $eth =~ /eth[0-9]/i ) &&
      ( $mac =~ /[0-9a-f]{2}\:[0-9a-f]{2}\:[0-9a-f]{2}\:[0-9a-f]{2}\:[0-9a-f]{2}\:[0-9a-f]{2}/i ) &&
      ( $ip =~ /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/i ) &&
      ( $ip !~ /127.0.0.1/ ) ) {
      $ret = 0;
      } else {
      $ret = 1;
      }
      } else {
      $ret = 1;
      }
      return $ret;
      }

      if( $ENV{'USER'} ne "root" ) {
      print "execute-configs - \n";
      print "--------------------------------------------------------------\n";
      print "You must have root privledges to run this script\n";
      print "--------------------------------------------------------------\n";
      exit;
      } else {
      print "execute-configs - \n";
      print "I perform the execution all of the system\nconfiguration scripts, bow down...\n";
      print "--------------------------------------------------------------\n";
      while( $code eq "0" ) {
      &GetActiveInterface;
      if( -e "config-network" ) {
      print "Executing ./config-network --mac=$MAC\n";
      system( "./config-network --mac=$MAC" );
      $code = "1";
      }
      if( -e "config-printer" ) {
      print "Executing ./config-printer --ip=$IP\n";
      system( "./config-printer --ip=$IP" );
      $code = "1";
      }
      }
      print "--------------------------------------------------------------\n";
      }







  3. GRUB & Bootloader Configuation ====

    • We use the following automated tool to automate the GRUB configuration and setup








  4. Static Network Address Configuration



    • Since automation is the easiest way to perform mass installations we use the following script to auto configure the network and route data based on information stored in the current database for the phpDHCPAdmin application.

      #!/usr/bin/perl

      # Network configuration scrip
      # 08.05.2008
      # Jason Gerfen

      # Packages to use
      use strict;
      use DBI;
      use POSIX qw(strftime);
      use Getopt::Long;

      my ( $eth,
      $mac,
      $ip,
      $MAC,
      $IP,
      $NAME,
      $SUB,
      $NET,
      $GTW,
      $DNS1,
      $DNS2,
      $NME1,
      $NME2 ) = '';

      GetOptions( "mac=s" => \$mac );

      my $date = strftime('%m.%d.%Y', localtime());

      my $netwk = "/etc/conf.d/net"; # Path & name for our IP and gateway configuration file
      my $host = "/etc/conf.d/hostname"; # Path & name of our hostname file
      my $dns = "/etc/resolv.conf"; # Path & name of resolv.conf (dns)
      my $tmp = "/tmp/conf"; # Path & name of temporary file (used for system output)
      my $domain = "scl.utah.edu"; # Default Domain for system (ex. scl.utah.edu)

      # Global database variables (please define these)
      my $dbName = "datatbasename"; # Name of Database to use
      my $dbHost = "databasehostname"; # Hostname of database server
      my $dsn = "dbi:mysql:host=$dbHost;database=$dbName"; # Driver to use for database
      my $user = 'username'; # Database username
      my $pass = 'password'; # Database password

      my %vlan_22 = ( sub => "155.97.241.0",
      msk => "255.255.255.0",
      rtr => "155.97.241.1",
      dns1 => "155.97.241.130",
      dns2 => "155.97.15.2",
      nme1 => "dc4\-rh.scl.utah.edu",
      nme2 => "dc1\-mmc.scl.utah.edu" );

      my %vlan_27 = ( sub => "155.97.14.0",
      msk => "255.255.255.0",
      rtr => "155.97.14.1",
      dns1 => "155.97.15.2",
      dns2 => "155.97.16.130",
      nme1 => "loki.scl.utah.edu",
      nme2 => "dc1\-mmc.scl.utah.edu" );

      my %vlan_29 = ( sub => "155.97.15.0",
      msk => "255.255.255.0",
      rtr => "155.97.15.1",
      dns1 => "155.97.15.2",
      dns2 => "155.97.16.130",
      nme1 => "dc1\-mmc.scl.utah.edu",
      nme2 => "loki.scl.utah.edu" );

      my %vlan_31 = ( sub => "155.97.8.0",
      msk => "255.255.255.0",
      rtr => "155.97.8.1",
      dns1 => "155.97.8.2",
      dns2 => "155.97.15.2",
      nme1 => "dc5\-pub.scl.utah.edu",
      nme2 => "dc1\-mmc.scl.utah.edu" );

      my %vlan_151 = ( sub => "155.97.18.0",
      msk => "255.255.255.0",
      rtr => "155.97.18.1",
      dns1 => "155.97.18.3",
      dns2 => "155.97.15.2",
      nme1 => "dc3\-un.scl.utah.edu",
      nme2 => "dc1\-mmc.scl.utah.edu" );

      my %vlan_461 = ( sub => "155.97.16.128",
      msk => "255.255.255.128",
      rtr => "155.97.16.129",
      dns1 => "155.97.16.130",
      dns2 => "155.97.15.2",
      nme1 => "loki.scl.utah.edu",
      nme2 => "dc1\-mmc.scl.utah.edu" );

      sub getDBData
      {
      my $dbconn = DBI->connect( $dsn, $user, $pass ) or die "Could not connect to database\n";
      my $search = $dbconn->prepare( "SELECT ip,hostname FROM hosts WHERE mac = '$MAC'" );
      $search->execute;
      while( my @row = $search->fetchrow_array() )
      {
      $IP = $row[0];
      $NAME = $row[1];
      }
      if( !$IP && !$NAME ) {
      print "Could not find $MAC in database\n";
      exit;
      }
      }

      # Determine our network settings
      sub DetermineNetworkSettings
      {
      if( $IP =~ /^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/ ) {
      if( $3 eq "241" ) {
      $SUB = $vlan_22{ sub };
      $NET = $vlan_22{ msk };
      $GTW = $vlan_22{ rtr };
      $DNS1 = $vlan_22{ dns1 };
      $DNS2 = $vlan_22{ dns2 };
      $NME1 = $vlan_22{ nme1 };
      $NME2 = $vlan_22{ nme2 };
      } elsif( $3 eq "14" ) {
      $SUB = $vlan_27{ sub };
      $NET = $vlan_27{ msk };
      $GTW = $vlan_27{ rtr };
      $DNS1 = $vlan_27{ dns1 };
      $DNS2 = $vlan_27{ dns2 };
      $NME1 = $vlan_27{ nme1 };
      $NME2 = $vlan_27{ nme2 };
      } elsif( $3 eq "15" ) {
      $SUB = $vlan_29{ sub };
      $NET = $vlan_29{ msk };
      $GTW = $vlan_29{ rtr };
      $DNS1 = $vlan_29{ dns1 };
      $DNS2 = $vlan_29{ dns2 };
      $NME1 = $vlan_29{ nme1 };
      $NME2 = $vlan_29{ nme2 };
      } elsif( $3 eq "8" ) {
      $SUB = $vlan_31{ sub };
      $NET = $vlan_31{ msk };
      $GTW = $vlan_31{ rtr };
      $DNS1 = $vlan_31{ dns1 };
      $DNS2 = $vlan_31{ dns2 };
      $NME1 = $vlan_31{ nme1 };
      $NME2 = $vlan_31{ nme2 };
      } elsif( $3 eq "18" ) {
      $SUB = $vlan_151{ sub };
      $NET = $vlan_151{ msk };
      $GTW = $vlan_151{ rtr };
      $DNS1 = $vlan_151{ dns1 };
      $DNS2 = $vlan_151{ dns2 };
      $NME1 = $vlan_151{ nme1 };
      $NME2 = $vlan_151{ nme2 };
      } elsif( $3 eq "16" ) {
      $SUB = $vlan_461{ sub };
      $NET = $vlan_461{ msk };
      $GTW = $vlan_461{ rtr };
      $DNS1 = $vlan_461{ dns1 };
      $DNS2 = $vlan_461{ dns2 };
      $NME1 = $vlan_461{ nme1 };
      $NME2 = $vlan_461{ nme2 };
      } else {
      print "Could not locate VLAN / Subnet settings for $IP\n";
      exit;
      }
      }
      }

      sub ConfigureNetwork
      {
      $MAC = lc( $MAC );
      my $sysconfig = $netwk;

      open( HST, "> $host" ) || warn "Could not open $host\n";
      print HST "$NAME.$domain\n";
      close( HST );

      open( IP, "> $sysconfig" ) || warn "Could not open $sysconfig\n";
      print IP "config_eth0=(\"$IP netmask $NET broadcast $SUB\")\n";
      print IP "routes_eth0=(\"default via $GTW\")\n";
      print IP "config_eth1=(\"$IP netmask $NET broadcast $SUB\")\n";
      print IP "routes_eth1=(\"default via $GTW\")\n";
      close( IP );

      open( DNS, "> $dns" ) || warn "Could not open $dns\n";
      print DNS "nameserver $DNS1\n";
      print DNS "nameserver $DNS2\n";
      print DNS "search $NME1 $NME2\n";
      close( DNS );
      }

      sub Main {
      if( $ENV{'USER'} ne "root" ) {
      print "config-network \n";
      print "--------------------------------------------------------------\n";
      print "You must have root privledges to run this script\n";
      print "--------------------------------------------------------------\n";
      exit;
      } else {
      print "config-network \n";
      print "--------------------------------------------------------------\n";
      print "Looking up machine in database...\n";
      $MAC = $mac;
      &getDBData;
      print "Processing data for network configuration...\n";
      &DetermineNetworkSettings;
      &ConfigureNetwork;
      print "The following settings have been applied:\n
      IP Address: $IP
      MAC Address: $MAC
      HostName: $NAME
      Subnet: $SUB
      Mask: $NET
      Gateway: $GTW
      DNS: $DNS1
      DNS: $DNS2\n";
      print "--------------------------------------------------------------\n";
      }
      }

      sub ShowHelp {
      print <
      config-network - jason.gerfen\@scl.utah.edu
      ------------------------------------------
      Setup networking for machine from
      data retrieved from a database.

      Usage: ./config-network --mac=[MAC]
      Revision: 0.10

      Supported options are:

      mac STRING Hardware Address for interface.

      EOF
      exit;

      }

      if( defined( $mac ) ) {
      &Main;
      } else {
      &ShowHelp;
      }






  5. Printer Configuration



    • And finally the automatic setup based on subnet of our printer configuration

      #!/usr/bin/perl
      #
      # config-printer
      #
      # Configure the printers.conf and printcap
      # files based on subnet machine is configured
      # for.
      #
      # 08.05.2008
      # jason.gerfen@scl.utah.edu
      #

      use strict;
      use Getopt::Long;

      my ( $ip_s ) = '';

      GetOptions( "ip=s" => \$ip_s );

      my $print_conf = "/etc/cups/printers.conf";
      my $print_desc = "/etc/cups/printcap";
      my $union_dc = "dc4-rh.scl.utah.edu";
      my $emcb_dc = "dc4-rh.scl.utah.edu";
      my $mmc_dc = "dc4-rh.scl.utah.edu";
      my $res_dc = "dc4-rh.scl.utah.edu";
      my $pub_dc = "155.97.8.2";

      my %vlan_22 = ( printer1 => "$res_dc",
      printque1 => "Pet-1",
      printdes1 => "Peterson Lab Black and White Printer",
      printer2 => "$res_dc",
      printque2 => "Petcolor",
      printdes2 => "Peterson Lab Color Printer",
      printer3 => "$res_dc",
      printque3 => "Sage-1",
      printdes3 => "SagePoint Lab Black and White Printer" );

      my %vlan_29 = ( printer1 => "$mmc_dc",
      printque1 => "mmcpc",
      printdes1 => "MMC Lab Black and White Printer",
      printer2 => "$mmc_dc",
      printque2 => "mmccolor",
      printdes2 => "MMC Lab Color Printer" );

      my %vlan_31a = ( printer1 => "$pub_dc",
      printque1 => "fa-1",
      printdes1 => "Fine Arts Public Printer" );

      my %vlan_31b = ( printer1 => "$pub_dc",
      printque1 => "gd-1",
      printdes1 => "Government Documents Printer" );

      my %vlan_31c = ( printer1 => "$pub_dc",
      printque1 => "gr-1",
      printdes1 => "General Reference Printer 1",
      printer2 => "$pub_dc",
      printque2 => "gr-2",
      printdes2 => "General Reference Printer 2" );

      my %vlan_31d = ( printer1 => "$pub_dc",
      printque1 => "sc-1",
      printdes1 => "Science Reference Printer" );

      my %vlan_31e = ( printer1 => "$pub_dc",
      printque1 => "sr-1",
      printdes1 => "Special Reserves Printer" );

      my %vlan_132 = ( printer1 => "$union_dc",
      printque1 => "un-1",
      printdes1 => "Union Lab Black and White Printer" );

      my %vlan_461 = ( printer1 => "155.97.17.202",
      printque1 => "",
      printdes1 => "PC Group Black and White Printer" );

      my ( $HASHREF,
      $IP,
      $HOSTNAME,
      $PRINTER1, $PRINTER2, $PRINTER3,
      $QUE1, $QUE2, $QUE3,
      $DESCRIPTION1, $DESCRIPTION2, $DESCRIPTION3 ) = undef;

      sub DetermineLab
      {
      my $iserror = "";
      $IP = $ip_s;
      if( $IP =~ /^\d{1,3}\.\d{1,3}\.(\d{1,3})\.(\d{1,3})$/ ) {
      my $subnet = $1;
      my $ip = $2;
      if( $subnet == 241 ) {
      print "\tPeterson/Sage Printers\n";
      $HASHREF = \%vlan_22;
      } elsif( $subnet == 15 ) {
      print "\tMMC Printers\n";
      $HASHREF = \%vlan_29;
      } elsif( $subnet == 8 ) {
      if( ( $ip < 60 ) and ( $ip > 67) ) {
      print "\tFine Arts Printers\n";
      $HASHREF = \%vlan_31a;
      } elsif( ( $ip > 30 ) && ( $ip <= 47 ) ) {
      print "\tGovernment Documents Printers\n";
      $HASHREF = \%vlan_31b;
      } elsif( ( $ip > 98 ) and ( $ip < 135 ) ) {
      print "\tGeneral Reference Printers\n";
      $HASHREF = \%vlan_31c;
      } elsif( ( $ip > 80) and ( $ip < 84 ) ) {
      print "\tScience Reference Printers\n";
      $HASHREF = \%vlan_31d;
      } elsif( ( $ip > 149) and ( $ip < 165 ) ) {
      print "\tSpecial Collections Printers\n";
      $HASHREF = \%vlan_31e;
      } else {
      print "\tNo Printers found for Public IP\n";
      $iserror = 1;
      }
      } elsif( $subnet == 18 ) {
      print "\tUnion Printers\n";
      $HASHREF = \%vlan_132;
      } elsif( $subnet == 16 ) {
      print "\tPC Group Printers\n";
      $HASHREF = \%vlan_461;
      } elsif( $subnet == 1) {
      print "\tSandbox Printers\n";
      $HASHREF = \%vlan_22;
      } else {
      print "\tNo Printers found for Lab IP\n";
      $iserror = "ERROR";
      }
      }
      return $iserror;
      }

      # set our configuration data
      sub WriteConfigs
      {
      $PRINTER1 = $$HASHREF{"printer1"};
      $PRINTER2 = $$HASHREF{"printer2"};
      $PRINTER3 = $$HASHREF{"printer3"};
      $QUE1 = $$HASHREF{"printque1"};
      $QUE2 = $$HASHREF{"printque2"};
      $QUE3 = $$HASHREF{"printque3"};
      $DESCRIPTION1 = $$HASHREF{"printdes1"};
      $DESCRIPTION2 = $$HASHREF{"printdes2"};
      $DESCRIPTION3 = $$HASHREF{"printdes3"};

      open( PRNT, "> $print_conf" ) || warn "Could not open $print_conf make sure the \$print_conf variables are defined";
      if( defined $QUE1 ) {
      print PRNT "\n";
      print PRNT " Info $DESCRIPTION1\n";
      print PRNT " Location $DESCRIPTION1\n";
      print PRNT " DeviceURI lpd://$PRINTER1/$QUE1\n";
      print PRNT " State Idle\n";
      print PRNT " Accepting Yes\n";
      print PRNT " JobSheets none none\n";
      print PRNT " QuotaPeriod 0\n";
      print PRNT " PageLimit 0\n";
      print PRNT " KLimit 0\n";
      print PRNT "\n";
      }
      if( defined $QUE2 ) {
      print PRNT "\n";
      print PRNT " Info $DESCRIPTION2\n";
      print PRNT " Location $DESCRIPTION2\n";
      print PRNT " DeviceURI lpd://$PRINTER2/$QUE2\n";
      print PRNT " State Idle\n";
      print PRNT " Accepting Yes\n";
      print PRNT " JobSheets none none\n";
      print PRNT " QuotaPeriod 0\n";
      print PRNT " PageLimit 0\n";
      print PRNT " KLimit 0\n";
      print PRNT "
      \n";
      }
      if( defined $QUE3 ) {
      print PRNT "\n";
      print PRNT " Info $DESCRIPTION3\n";
      print PRNT " Location $DESCRIPTION3\n";
      print PRNT " DeviceURI lpd://$PRINTER3/$QUE3\n";
      print PRNT " State Idle\n";
      print PRNT " Accepting Yes\n";
      print PRNT " JobSheets none none\n";
      print PRNT " QuotaPeriod 0\n";
      print PRNT " PageLimit 0\n";
      print PRNT " KLimit 0\n";
      print PRNT "
      \n";
      }
      close( PRNT );

      open( CAP, "> $print_desc" ) || warn "Could not open $print_desc make sure the \$print_desc variables is defined";
      if( defined $QUE1 ) {
      print CAP "$QUE1\|$DESCRIPTION1:$HOSTNAME:$DESCRIPTION1\n";
      }
      if( defined $QUE2 ) {
      print CAP "$QUE2\|$DESCRIPTION2:$HOSTNAME:$DESCRIPTION2\n"
      }
      if( defined $QUE3 ) {
      print CAP "$QUE3\|$DESCRIPTION3:$HOSTNAME:$DESCRIPTION3\n"
      }
      close( CAP );
      }

      sub ShowHelp {
      print <
      config-printer - jason.gerfen\@scl.utah.edu
      ------------------------------------------
      Setup printing options for machine based
      on subnet.

      Usage: ./config-printer --ip=[IP]
      Revision: 0.10

      Supported options are:

      ip STRING IP Address of machine

      EOF
      exit;

      }

      if( defined( $ip_s ) ) {
      &Main;
      } else {
      &ShowHelp;
      }

      sub Main {
      if( $ENV{'USER'} ne "root" ) {
      print "config-printer \n";
      print "--------------------------------------------------------------\n";
      print "You must have root privledges to run this script\n";
      print "--------------------------------------------------------------\n";
      exit;
      } else {
      print "config-printer \n";
      print "--------------------------------------------------------------\n";
      print "Looking up lab information...\n";
      if( &DetermineLab ne "ERROR" ) {
      print "The following settings have been applied:\n";
      &WriteConfigs;
      if( defined $PRINTER1 ) {
      print "\tPrinter: $PRINTER1\n";
      print "\tQUE: $QUE1\n";
      }
      if( defined $PRINTER2 ) {
      print "\tPrinter: $PRINTER2\n";
      print "\tQUE: $QUE2\n";
      }
      if( defined $PRINTER3 ) {
      print "Printer: $PRINTER3\n";
      print "\tQUE: $QUE3\n";
      }
      } else {
      print "The sort_settings() subroutine failed!\n";
      }
      }
      }






  6. Cleanup & Restart ====

    • Auto cleanup and restarting of the OS so users can then log in

      #!/usr/bin/perl
      # Gentoo cleanup script
      # Written by Jeff Robinson, Jason Gerfen and Seth Walsh
      # 05/10/2007

      use strict;
      use warnings;
      use POSIX qw(strftime);
      use Date::Calc qw(Date_to_Days);

      # Arrays
      my @delusers;

      # Global variables
      my $expiredays = "3";

      sub check_user
      {
      if( $ENV{'USER'} ne "root" ) {
      print "You must have root privledges to run this script\n";
      exit;
      } else {
      print "Removing expired user accounts:\n";
      }
      }

      sub check_dates_names
      {
      print "Checking account ages...\n";
      my $currentday = strftime( "%d", localtime() );
      my $currentmonth = strftime( "%m", localtime() );
      my $currentyear = strftime( "%Y", localtime() );
      my $currentdays = Date_to_Days($currentyear,$currentmonth,$currentday);

      my @homedirs = `ls -ld --time-style=long-iso /home/*`;
      foreach (@homedirs)
      {
      $_ =~ m/^\S+\s+\d+\s+\w+\s+\w+\s+\d+\s+(\d{4})-(\d{2})-(\d{2})\s+\d{2}:\d{2}\s+\/home\/(\w+)$/x;
      my $user = $4;
      my $userdays = Date_to_Days($1,$2,$3);
      if($userdays + $expiredays < $currentdays)
      {
      if($4 !~ m/admin|default/)
      {
      push(@delusers, $user);
      }
      }
      }
      }

      sub del_passwd_shadow
      {
      foreach(@delusers)
      {
      print "Removing user $_ from the system...\n";
      my $deluser = "/usr/sbin/userdel " . $_;
      system( "$deluser" );
      }
      }

      sub del_home_dirs
      {
      foreach (@delusers)
      {
      print "Removing $_\'s home directory\n";
      my $delhome = "rm -dfr /home/" . $_;
      system( "$delhome" );
      }
      }

      sub clean_system
      {
      print "Cleaning up /tmp directory...\n";
      my $cleantmp = "rm -dfr /tmp/*";
      system( "$cleantmp" );
      }

      check_user();
      check_dates_names();
      del_passwd_shadow();
      del_home_dirs();
      clean_system();






Administration


Manual Administration Information




  1. Installing software



    • Gentoo has a fairly robust package management system available to you from the command line. Some examples of installation, updating & removing software packages is detailed below:
      %> emerge 
      %> emerge --remove
      %> emerge -uDNa





  2. Performing security updates



    • Because security updates for installed software are considered mission critical for the uptime of server and desktops alike you must ensure these are run at least once a week
      %> glsa-check -f affected





  3. Rebuilding broken dependencies

    • Occasionally you will run into software that is missing dependencies of required software packages. To fix this simply run the command below.
      %> revdep-rebuild




(0 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).