Linux

Replace an HD using LVM (CentOS)

Let's suppose you want to replace the disk in a system that uses LVM and has a separate /boot partition. In this case we also presume that /boot is identified in fstab via a label.

  • Insert the new disk (sdb) and replicate the partition layout
  • Replicate the content of the /boot partition to the new disk
  • Label the new boot:
  e2label /dev/sdb1 /boot
  • Extend the volume group with the new partition:
  pvcreate /dev/sdb2
  vgextend VolGroup00 /dev/sdb2
  • Move data from the old partition and remove it:
  pvmove /dev/sda2
  vgreduce VolGroup00 /dev/sda2
  • Fix grub:
  root (hd1,0)
  setup (hd1)
  quit
  • Remove the old disk and reboot

Rescan SCSI bus

for bus in /sys/class/scsi_host/host*/scan ; do
  echo "- - -" > $bus
done

Red Hat/Centos

Install an init script

chkconfig --add scriptname
chkconfig scriptname on
service scriptname start

Delete an init script

chkconfig --del scriptname

Package management

rpm -ivh mypkg.rpm   # install
rpm -Uvh mypkg.rpm   # Update
rpm -qa              # list installed packages
rpm -qi mypkg        # package info
rpm -ql mypkg        # package contents

Curses setup menu

setup

Network configuration

Launch the graphical tool with:

system-config-network

Register to RHN

rhn_register

Additional package repositories

Disable yum autoupdate daemon

service yum-updatesd stop
chkconfig yum-updatesd off

Mount a Mac OS X DMG

To open an Apple Mac OS X Disk Image (.dmg) in linux you can try:

  1. Uncompress the image using dmg2img
  2. Mount the uncompressed .img as directed by the dmg2img output

I never managed to make it work BTW :-(

IPtables cheatsheet

A nice explanation picture borrowed from http://billauer.co.il/ipmasq-html.html

Enabling forwarding

echo 1 > /proc/sys/net/ipv4/ip_forward

Masquerade / SNAT

With masquerade you don't need to know the address of the external interface (good for dynamic IP). Furthermore, when the connection goes down the connection/translation table gets cleared

iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

With Source NAT you have to specify the IP of the outgoing interface, and the slate table are retained:

iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4

Securing connection

When using – for example – NAT and wanting to allow only outgoing connections:

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! eth1 -j ACCEPT
iptables -P INPUT DROP
iptables -A FORWARD -i eth1 -o eth1 -j REJECT
unix/linux.txt · Last modified: 2011/11/22 17:49 by ap
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki