Tag: linux

  • RHEL6 – Snapshotting an LVM Volume

    Oh-snapSnapshotting in the context of LVM is the process of taking a point-in-time image of a filesystem and creating a separate copy of that filesystem on another filesystem… using LVM of course.

    Snapshoting can be useful if you need to take a backup of a filesystem but want the filesystem to be a quiesced state when you do so. Using LVM and snapshots you just backup the snapshot of the original filesystem.

    First lets create the “master” filesystem using /dev/sdc1 which has partitioned as Linux LVM in fdisk.

    So create the physical volume

    >pvcreate /dev/sdc1

    Then create a volume group containing the physical volume

    >vgcreate test_vg /dev/sdc1

    Then create a logical volume called v1 which is 5gb in size. Note that this volume group is 10gb in total size.

    >lvcreate -n v1 -L 5G test_vg

    Then create a filesystem on that volume

    >mkfs -t ext4 /dev/test_vg/v1

    Then mount this volume to /v1 and put some data in it.

    >mkdir /v1

    >mount /dev/test_vg/v1 /v1

    >cp /var/tmp/VMwareTools-8.3.2-257589.tar /v1

    Ok, now that we have a logical volume with some data in it, lets make a snapshot of it.

    First lets make a mountpoint for our snapshot

    >mkdir /v2

    Now lets make the snapshot of /dev/test_vg/v1. Note that a snapshot volume can be as large or a small as you like but it must be large enough to hold all the changes that occur on the original volume during the lifetime of the snapshot. In this example I am creating a snapshot of 4gb.

    >lvcreate -n snapvol -L 4G -s /dev/test_vg/v1

    Using lvs or lvscan you can take a look at the snapshot volume.

    >lvscan

      ACTIVE   Original ‘/dev/test_vg/v1’ [5.00 GiB] inherit
      ACTIVE   Snapshot ‘/dev/test_vg/snapvol’ [4.00 GiB] inherit

    Now lets mount the snapshot readonly.

    >mount -o ro /dev/test_vg/snapvol /v2

    Now you can browse the contents of the snapshot, unmount it and mount it as needed. And back it up as well. Make sure that you remove the snapshot when done backing it up

    >lvremove /dev/test_vg/snapvol

  • RHEL6 – Accessing ISCSI Disks with Iscsiadm

    Pdp-8ISCSI is scsi (Small Computer System Interface) over IP. Where SCSI is the protocol and IP is the transport mechanism. This is going to be a quick and dirty overview of how to login to and mount an iscsi disk. This will not be an overview of how to share out a disk via iscsi. I may get around to writing that post, but it will not be today.

    Before we get started we need to understand a few simple terms.

    • ISCSI Initiator – the client that needs access to the ISCSI disk.
    • ISCSI Target – the remote disk.
    • ISCSI Target Portal – the server that is providing the Target to the Initiator
    • IQN – The “ISCSI Qualified Name” or more simply a unique name for the Initiator and the Target

    Now lets get down to business.

    First on the Target you must install the ISCSI utils.

    >yum -y install iscsi-initiator-utils.x86_64

    Then discover the any ISCSI targets provided by the Target Portal. In this case the IP address of my target portal will be 192.168.0.55.

    >iscsiadm -m discovery -t st -p 192.168.0.55.

    In the example above -m puts iscsiadm is discovery mode, -t st tells iscsiadm to look for a SCSI target, and -p is the target portal. The output of the above command will be the IQN of the target disk.

    For this example we will say that the IQN is

    iqn.2001-05.com.equallogic:6-8a0900-5e1812101-1cf000245514a8da-disk1

    Then log into the ISCSI target

    >iscsiadm -m node -T iqn.2001-05.com.equallogic:6-8a0900-5e1812101-1cf000245514a8da-disk1 -p 192.168.0.55 -l

    In the example above we are setting the mode to node, -T prefaces the ISCSI target, -p the portal, and -l means login.

    Now you need to identify which device is the iscsi target by looking at the output of dmesg or tail the messages file.

  • RHEL6 – Managing Swap Space

    54af9-6a00e551c39e1c8834017ee46a8c54970d-piSwap space on a Linux box is an area on disk that is used to hold inactive memory pages. This occurs when the system needs more memory then is currently available, so it swaps these inactive memory pages to disk.

    To create additional swap space on the fly you are either going to need a spare disk or free partition on a disk that you can use.

    First, using fdisk,  you will need to make sure that the partition type for the disk (or partition) is set to 82.

    Then setup the swap area using mkswap. In this example I am using /dev/sdb2, but your setup is bound to be different.

    >mkswap /dev/sdb2

    Then determine the UUID of the new swap space.

    >blkid /dev/sdb2

    Then add an entry to the /etc/fstab, so that the swap space is mounted at boottime. The show in the example below is the output of the blkid command above.

    >UUID=7b05f0a9-18d5-42e5-b259-78ba3a8cc1b7 swap                    swap    defaults        0 0

    Then activate your new swap space

    >swapon -a

    Then check to make sure everything worked by checkign for your new swap partition in the output of the command below.

    >swapon -s

    /dev/sdb2                             partition       4193276 7480    0

  • RHEL6 – Network Mounting User Home Directories

    Cartoon-house-008Seriously, who does not hate users and their home directories? However if it wasn’t for them, then nothing would ever break and the life of a sysadmin would be a very boring one. Anyway back to the subject at hand.

    First off, in order to mount a users home directory automatically upon login you need to make sure that you have autofs installed and configured to start at boot.

    Note that for this example lets assume that our home directories are shared via nfs on the server, nfsserver.example.com, on the exported volume /nfs/home/

    So first, on your local system, install autofs via yum if its not already installed.

    $ sudo yum install autofs

    Then extend the configurations of your automounter to mount the /nfs/home directory by adding the following line to the bottom of /etc/auto.master. The auto.master is a master map for the automounter, and it is referenced each time autofs is involked.

    /nfs/home   /etc/auto.guests

    In the example above, all accesses to /nfs/home will be directed to the map in /etc/auto.guests

    Now obviously we are going to need to  create a file called /etc/auto.guests.  Here you will add the line below.

    *    nfsserver.example.com:/nfs/home/&

    Here we are using the metacharacter “&” to elimiate the need to list out each and every username. By doing so each users home directory is mapped by default.

    Then start the automounter

    #service autofs start

  • RHEL – Managing Passwords with Chage

    Large_SkeletonKeyPTo understand the chage command  if might be best to make sure that you understand the /etc/shadow file, so lets look at a line from mine. Note that “:” is the field separator.

    chris:$6$MZsU1MdDNVs50KaP$.sPNd90oOieOHAMwWt5rVB1:15188:0:99999:7:::

    In the shadow file the fields are as follows:

    1. Username
    2. Password Hash
    3. Date of Last Password Change in days since the dawn of Unix Time
    4. Minimum Password Age
    5. Maximum Password Age
    6. Password Warning Period
    7. Password Inactive Period
    8. Account Expiration

    The basic options of the chage command are as follows

    • -M Max Days
    • -m Min Days
    • -I inactive
    • -E Expiry Date
    • -D 0 Force Password Change

    So first lets take a look at the current settings for user “chris”. You will see that the entries below match the options listed above.

    # chage -l chris

    Last password change                                    : Aug 02, 2011
    Password expires                                        : never
    Password inactive                                       : never
    Account expires                                         : never
    Minimum number of days between password change          : 0
    Maximum number of days between password change          : 99999
    Number of days of warning before password expires       : 7

    So lets say that we want to force user chris to update his password on next login

    #chage -d 0 chris

    and then set a minimum number of days of 10 between password changes

    #chage -m 10 chris

    or set an expiration date of 10/10/2020

    #chage -E 10/10/2020 chris

    You get the idea…

    Anyway the chage command can be run interactively as well if you do not pass any options to the command other than the username.

    Additional Resources:

    Managing Password Aging on AIX, Solaris, Linux

    7 Examples to Manage Linux Password Expiration and Aging Using chage

  • RHEL6 – Using ACLs to Grant and Restrict FIle Access.

    RangerRick

    Access Control Lists or ACLs provide more controll over file permissions than standard linux file permissions (UGO — user, group, other). For example lets say that you want all members of the group "students" to have the ability to read a file, however you want to allow one user in that group the ability to write to the file, well ACLs can help you do this.

    First thing that you need to know is that you cannot just start using ACLs right away, first you have to make sure that your filesystem is mounted so that ACLs are availible. This means adding ACL to the mount options in /etc/fstab.

    UUID=3fa4603e-9874-4f47-ae1c-3f7715a54238 /                       ext4    defaults,user_xattr

    So in my fstab, I change the line above to the line below. I know, exciting right?

    UUID=3fa4603e-9874-4f47-ae1c-3f7715a54238 /                       ext4    defaults,user_xattr.acl

    Now to view the permissions and ACLs on a file use the getfacl command, below i am checking the file RangerRick.jpg in /root/Pictures.  In the example below there are no ACLs assigned, btw.

    [root@fedora15 Pictures]# getfacl RangerRick.jpg
    # file: RangerRick.jpg
    # owner: root
    # group: root
    user::rw-
    group::r–
    other::r–

    So lets allow the user "chris" to write to the file, just just read it.

    [root@fedora15 Pictures] setfacl -m u:chris:w RangerRick.jpg

    Now run getfacl again and check out the difference

    [root@fedora15 Pictures]# getfacl RangerRick.jpg
    # file: RangerRick.jpg
    # owner: root
    # group: root
    user::rw-
    user:chris:-w-
    group::r–
    mask::rw-
    other::r–

    Additonal Examples:

    Lets give all users in the group "students" the ability to write to the file, since they may want to modify it and add a photochop their faces over the dear old racoon's face.

    [root@fedora15 Pictures] setfactl -m g:students:w RangerRick.jpg

    But oh no, user "bert" in the group "students", has decided to modify the file RangerRick.jpg in an in appropriate way, so lets remove his permissions altogether.

    [root@fedora15 Pictures] setfacl -x u:bert

    Lets say that we want to allow the user "chris" to be able to modify all existing and newly created files in the Pictures directory where the Ranger Rick picture lives.

    [root@fedora15 Pictures] setfacl -m d:u:chris:rw /root/Pictures

    Note that when a file has ACLs assigned to it, a plus "+" sign will appear in the output of an 'ls-l'

    -rw-rw-r–+ 1 root root 148011 Oct 12 15:06 RangerRick.jpg

    Honestly you will probably never need to use ACLs, but they are handy to have availible if you run into some sort of situation where you need to grant very particular permissions to files and directories.

  • LSI MegaCLI — Check For Failed Raid Controller Battery

    701590_rusty_batteryThere are several tools that you can use to monitor and configure and LSI SAS controller, however as I have found, some are easier than others to use and some do not always display the correct information.

    In my case my controller is a SAS 9260-8i, and when building a server I always make sure that I install the MegaRaid Storage Manager gui for configuring disks and setting up email alerts. However I have often found that this tool is sometimes confusing to use for other tasks so I also make sure that I install the MegaCLI (command line interface). Both utilities can be downloaded directly from LSI here.

    MegaRaid Storage Manager installs to /usr/local/MegaRAID Storage Manager, while the cli installs via rpm to /opt/MegaRAID/MegaCli.

    Anyway to check the battery status run the following (note i am running 64 bit os)

    #>./MegaCli64 -AdpBbuCmd -aAll

    Your output will be lengthy – but look for the line below to know if you need to replace your BBU.

    Battery Replacement required            : Yes

    Two additional usefull commands are:

    • megacli -AdpAllInfo -aALL lists all the adapters in the machine
    • megacli -PDList -aALL lists all disks and enclosures

    Note that there is an open source CLI called Megactl, and while its quick and easy to use to see a quick list of your disks and their statuses, its not shown itself to be accurate when it comes to detecting whether or not a battery has failed. You can get it here

    Additional Megacli command can be found here; https://twiki.cern.ch/twiki/bin/view/FIOgroup/DiskRefPerc