Wednesday, November 9, 2011

linux commands

  • To check if ipv6 module is currently loaded in the system:
    # lsmod | grep ipv6
  • Disable ipv6
    In /etc/sysconfig/network: NETWORKING_IPV6=no
    In /etc/sysctl.conf: net.ipv6.conf.all.disable_ipv6 = 1
    Next: disable the IPv6 firewall: chkconfig ip6tables off
  • Disable disk journaling
    • create ext4 without journaling:
      mkfs.ext4 -O ^has_journal /dev/sda1
    • disable journaling:
      tune2fs -O ^has_journal /dev/sda1
    • enable writeback to improve performance:
      tune2fs -o journal_data_writeback /dev/sda1
    • require fsck: # e2fsck -f /dev/sda1
    • check fs options:
      dumpe2fs /dev/sda1 | grep -i 'Filesystem features'
    • modify fstab options:
      /dev/sda1 /test ext4 default,data=writeback,noatime,nodiratime 0 0
  • kernel modules are stored in /lib/modules/`uname -r`
    https://wiki.archlinux.org/index.php/Kernel_modules
    • settings pass to udev are in /etc/modprobe.d
    • For modules built into kernel, options can be passed to module using kernel command:
      modname.parametername=parametercontents
    • show loaded kernel modules: # lsmod
    • show module info # modinfo <module_name>
    • list options set for a loaded module # systool -v -m <module_name>
      systool in package "sysfsutils"
    • display comprehensive config for all modules # modprobe -c
    • list dependencies of a module # modprobe --show-depends <module_name>
    • manual load module # modprobe <module_name>
    • manual unload module # modprobe -r <module_name>
      or # rmmod <module_name>
    • reload config files # systemctl restart systemd-modules-load.service
  • View current firewall policy:
    # /sbin/iptables -L
  • # ifconfig -a; ip addr show
  • # findfs LABEL=/
  • Disable ipv6:
    To completely disable IPv6 in your system, all you have to do is save the following line in a file inside /etc/modprobe.d/ or /etc/modprobe.conf:
     install ipv6 /bin/true
    or
     options ipv6 disable=1
  • rpm "specifies multiple packages"
    rpm -q --queryformat "%{name}.%{arch}\n" package
  • rpm find dependency
    rpm -q --requires package (rpm -qR package)
    rpm -q --provides package
    rpm -q --whatrequires CAPABILITY
    rpm -q --whatprovides 
    CAPABILITY
  • find where specific package comes from
    yum info package
    yum list package
  • System Informations
    • CPU Information: #cat /proc/cpuinfo
    • memory usage: #free -m
    • disk partition: #fdisk -l
    • PCI devices: #lspci
    • USB devices: #lsusb
    • #lsdev
    • #lshw
    • ifconfig -a; ip addr show
    • Open ports and process
      sudo lsof -i
      sudo netstat -lptu
      sudo netstat -tulpn
  • System Status: top; vmstat; uptime; pgrep; free; iostat; mpstat; pmap; ss; netstat; iptraf; strace
  • Check swap usage: swapon -s; cat /proc/meminfo; cat /proc/swaps; free -m; vmstat; top
  • Check and make swap: cat /etc/fstab; fdisk -l /dev/sda2; mkswap /dev/sda2; swapon /dev/sda2
    use swapfie:
    1. create an (1GB) empty file: dd if=/dev/zero of=/swapfile bs=1024 count=1048576
    2. mkswap /swapfile
    3. create swap entry in /dev/fstab: /swapfile none swap sw 0 0
      (Linux 2.6 kernel added a new kernel parameter called swappiness to let administrators tweak the way Linux swaps. It is a number from 0 to 100 (default 60). In essence, higher values lead to more pages being swapped, and lower values lead to more applications being kept in memory, even if they are idle. alter it temporarily (until you next reboot) by typing as root: echo 50 > /proc/sys/vm/swappiness or permanently by changing the vm.swappiness parameter in the /etc/sysctl.conf file.
  • disable usb storage
    • remove driver:
      # mv /lib/modules/$(uname -r)/kernel/drivers/usb/storage/usb-storage.ko /var/tmp
    • prevent loading the module, but root can still manually load with insmod
      # echo 'install usb-storage : ' >> /etc/modprobe.conf
    • disable kernel support in grub.conf
      kernel /vmlinuz-2.6.18-128.1.1.el5 ro root=LABEL=/ nousb
  • mount usb storage
    • check usb support in included in kernel
      # lspci -v | grep HCI
      0000:00:1d.0 USB Controller: Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) USB UHCI
      ...
    • Make sure your external drive detected by system
      # dmesg | grep -i usb
      SLPB PCI0 HUB0 USB0 USB1 USB2 USBE
      usbcore: registered new driver usbfs
      usbcore: registered new driver hub
      USB Universal Host Controller Interface driver v2.3
      uhci_hcd 0000:00:1d.0: new USB bus registered, assigned bus number 1
      hub 1-0:1.0: USB hub found
      ...
    • If you cannot see your external USB drive in above dmesg output then try to load usb-uhci and usb-ohci modules (driver):
      # modprobe usb-uhci
      # modprobe usb-ohci
      # modprobe usb-storage
  • OpenIPMI command
    • ipmitool sensor
    • ipmitool mc info
    • ipmitool help
  • Force yum update:
    remove package from rpm database first: rpm -e --justdb --nodeps package_name
  • set up satellite client:
    download and run http://myserver/pub/bootstrap/bootstrap.sh
  • create local mirror of rhn satellite updates (http://kenfallon.com/how-to-mirror-rhn-behind-your-firewall/)
    1. Regist to satellite through proxy: rhn_register --nox --proxy=myproxy:8080
    2. Install the yum-utils package from the RHN: yum install yum-utils
    3. download the channel locally
      # yum repolist
      # reposync -p /opt/mylocalrepo/ --repoid=rhel-x86_64-server-5 -l # -l is for load plugin
      or #: reposync -l
      or #: reposync --gpgcheck -l --repoid=channel-id --download_path=/test/path
    4. add your own RPMs or RPM’s from EPEL, DAG, etc to the repository
    5. yummify the local directory using the createrepo command. This goes through all the RPM’s and extracts version and dependency information which it uses to generate XML metadata files that the yum command can understand. Run createrepo after add new packages.
      # createrepo /opt/mylocalrepo/
    6. (re-use the repodata of rhn:
      # yum –disablerepo=* –enablerepo=$RELEASE makecache
      # cp -f /var/cache/yum/$RELEASE/*.gz /var/cache/yum/$RELEASE/*.xml /opt/mylocalrepo/$RELEASE/repodata
      )
    7. Point apache at the local directory so that it’s accessible from an internal url e.g: http://myserver.local/myrepo/. You could also use NFS or FTP if you prefer. Once that is done you can distribute a yum config file for your new repo to /etc/yum.repos.d/my.repo on all the internal servers.

      [rhel-myrepo]
      name=My Red Hat Enterprise Linux $releasever - $basearch
      baseurl=http://myserver.local/myrepo/
      enabled=1
      gpgcheck=0
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    8. check new repo: yum repolist
    9. disable the Red Hat network by setting enabled = 0 in /etc/yum/pluginconf.d/rhnplugin.conf to prevent the server trying to connect directly to the RHN
  • create local dvd depot for RHEL6
    1. # mkdir /media/cdrom
    2. # mount /dev/cdrom /media/cdrom
    3. # cat > /etc/yum.repos.d/DVD.repo <<EOF
      [baseOS]
      name=Red Hat Enterprise Linux $releasever – $basearch baseOS
      baseurl=file:///media/cdrom
      enabled=1
      gpgcheck=1
      
      [ScalableFileSystem]
      name=Red Hat Enterprise Linux $releasever – $basearch ScalableFileSystem
      baseurl=file:///media/cdrom
      enabled=1
      gpgcheck=1
      
      [Workstation]
      name=Red Hat Enterprise Linux $releasever – $basearch Workstation
      baseurl=file:///media/cdrom
      enabled=1
      gpgcheck=1
      
      EOF

      Or just simply,
      [dvd]
      mediaid=1339640147.274118
      name= DVD for RHEL6
      baseurl=file:///media/cdrom/Server
      enabled=1
      gpgcheck=0
      
      Where mediaid is value comes from the .discinfo file located in the root of the DVD

  • clean all yum cache: # yum clean all
  • list of yum transactions: # yum history
    backup yum: # yum history undo x (x being the numeric value associated with the transaction list above).
  • exclude packages: # yum -x php -x httpd update
    or: # yum -x php,httpd update
    or: # yum -x docker\* update
  • list rpm package content: #rpm -q -filesbypkg -p filename.rpm
  • Compatible packages:
    RHEL6: # yum groupinstall "Compatibility Libraries"
            # yum groupinstall "Development Tools"

    RHEL5: # yum groupinstall "Legacy Software Support"
            # yum groupinstall "Legacy Software Development"
  • IPMItool
    Baseboard Management Controller (BMC), which acts as a hub for the various sensors throughout a system board. Second, IPMI became the standardized way to interact with the BMC. Service Processor (SP), such as Dell's Remote Access Card (DRAC) or Sun's Lights Out Manager (LOM), are add-on boards that add value to the BMC's capabilities, such as providing a Web interface, SSH interface, SNMP, or networking, but by no means a requirement for utilizing IPMI.
    • # ipmitool chassis status
    • # ipmitool chassis power status
    • read all sensors: ipmitool sdr list
      (sensor number|sensor id|sensor reading|sensor status)
    • # ipmitool sdr elist full
    • # ipmitool sdr entity # sensor data repository
    • # ipmitool sdr entity 20
    • # ipmitool sel list # system event log
    • # ipmitool sel list last 3
  • Mount which support for Chinese file name
    # mount /dev/hda2 /mnt/hda2/ -t vfat -o iocharset=utf8
    # mount /dev/hda5 /mnt/hda5/ -t ntfs -o iocharset=utf8
    /dev/sda1 /mnt/flash auto iocharset=gb2312,noauto,user 0 0
  • hpacucli utility
    Abbreviationschassisname = ch
    controller = ctrl
    logicaldrive = ld
    physicaldrive = pd
    drivewritecache = dwc
    hpacucli# hpacucli
    # hpacucli help
    Controller Commands
    Display (detailed) hpacucli> ctrl all show config
    hpacucli> ctrl all show config detail
    Statushpacucli> ctrl all show status
    Cachehpacucli> ctrl slot=0 modify dwc=disable
    hpacucli> ctrl slot=0 modify dwc=enable
    Rescanhpacucli> rescan
    Note: detects newly added devices since the last rescan
    Physical Drive Commands
    Display (detailed) hpacucli> ctrl slot=0 pd all show
    hpacucli> ctrl slot=0 pd 2:3 show detail
    Note: you can obtain the slot number by displaying the controller configuration (see above)
    Statushpacucli> ctrl slot=0 pd all show status
    hpacucli> ctrl slot=0 pd 2:3 show status
    Erasehpacucli> ctrl slot=0 pd 2:3 modify erase
    Blink disk LED hpacucli> ctrl slot=0 pd 2:3 modify led=on
    hpacucli> ctrl slot=0 pd 2:3 modify led=off
    Logical Drive Commands
    Display (detailed) hpacucli> ctrl slot=0 ld all show [detail]
    hpacucli> ctrl slot=0 ld 4 show [detail]
    Statushpacucli> ctrl slot=0 ld all show status
    hpacucli> ctrl slot=0 ld 4 show status
    Blink disk LED hpacucli> ctrl slot=0 ld 4 modify led=on
    hpacucli> ctrl slot=0 ld 4 modify led=off
    re-enabling failed drive hpacucli> ctrl slot=0 ld 4 modify reenable forced
    Create# logical drive - one disk
    hpacucli> ctrl slot=0 create type=ld drives=1:12 raid=0
    # logical drive - mirrored
    hpacucli> ctrl slot=0 create type=ld drives=1:13,1:14 size=300 raid=1
    # logical drive - raid 5
    hpacucli> ctrl slot=0 create type=ld drives=1:13,1:14,1:15,1:16,1:17 raid=5
    Note:
    drives - specific drives, all drives or unassigned drives
    size - size of the logical drive in MB
    raid - type of raid 0, 1 , 1+0 and 5
    Removehpacucli> ctrl slot=0 ld 4 delete
    Expandinghpacucli> ctrl slot=0 ld 4 add drives=2:3
    Extendinghpacucli> ctrl slot=0 ld 4 modify size=500 forced
    Sparehpacucli> ctrl slot=0 array all add spares=1:5,1:7
  • Get HP server serial number
    • # hpasmcli
      hpasmcli> show server
    • #dmidecode -t system


Mounting 13TB Raid
This is some quick info I learned while trying to mount a 13TB partition in RHEL 5.3. The main thing is that fdisk does not like to make partitions larger than 2.2TB because dos labels are not recognized. The second is that ext3 file system doesn't like anything bigger than 8Tb. So here is what I did to go around it. I had to used parted instead of fdisk to overcome that 2TB limit.
#parted /dev/sdd
#mklabel gpt
>mkpart primary 0 13000G
>quit
#yum install e4fsprogs
#mkfs.ext4 /dev/sdd1

To lay this all out I had to rename the label of the partition to gpt so I could use the larger partitionsize and then I installed support for ext4 and used that as the filesystem. Yes I know I punked out a bit but I am sick of trying to find work arounds for ext3.

No comments:

Post a Comment