Creating and extending Linux LVMs

Notes on how to create or add disk, volume groups and logical volume in Linux (RedHat)
1. First add disk to system by what ever means your system requires.
2. Find name of disk using fdisk
# fdisk -l /dev/sd* | grep i 'Disk'
For my examples below, it would have listed sdb but not had any partition data with it.
3. Create a new partition on the disk using fdisk
# fdisk /dev/sdb
n to create a new partition
p for primary
enter through the other options
w to write the config and exit
3. make sure the disk and partition are setup OK by using lslbk
# lslbk
4. create the physical volume (pv) on the new disk (sdb1)
# pvcreate /dev/sdb1
5. list current volume groups
# vgs
6a. to create a new volume group, use vgcreate with the volume group name (vg_oracle) and the disk device (/dev/sdb1)
# vgcreate vg_oracle /dev/sdb
6b. extend the current volume group to include the new physical volume use vgextend with the volume group name (vg_oracle) and the disk device (/dev/sdb1)
# vgextend vg_oracle /dev/sdb1
7a. to create a new volume group
# lvcreate -L 20G -n lv_u01 vg_oracle
7b. to extend the logical volume
to increase it by 100GB
# lvextend -L +100G /dev/mapper/vg01_data-lv_data
to increase it to use 25% of the free space
# lvextend -l +25%FREE /dev/mapper/vg01_data-lv_data
to increase it to use all of the free space
# lvextend -l +100%FREE /dev/mapper/vg01_data-lv_data
8a. then create a xfs file system
# mkfs /dev/vg_oracle/lv_u01
8b. or resize the xfs file system
# xfs_growfs /u01

Shell Redirect

Discard the output
Sometimes you will need to execute a command, but you don’t want the output displayed on the screen. In such cases, you can discard the output by redirecting it to the file /dev/null −

$ command > /dev/null

Here command is the name of the command you want to execute. The file /dev/null is a special file that automatically discards all its input.
To discard both output of a command and its error output, use standard redirection to redirect STDERR to STDOUT −

$ command > /dev/null 2>&1

Here 2 represents STDERR and 1 represents STDOUT. You can display a message on to STDERR by redirecting STDOUT into STDERR as follows −

$ echo message 1>&2

Setgid

When set on a directory,
Setting the setgid permission on a directory (e.g. “chmod g+s”) it causes new files and subdirectories created within it to inherit its group ID, rather than the primary group ID of the user who created the file (the owner ID is never affected, only the group ID).

Setting up SSH to use key pairs

If you SSH to the same server a lot and don’t want to type the password each time you can configure SSH so you don’t have to.

First login to your terminal as normal and run

$ ssh-keygen

This will ask you the name of the key pair file you want to use.
It will suggest ~/.ssh/id_rsa
It will also create an id_rsa.pub file.

Next you need to “copy” that file to the server you want to connect to, you do by using the ssh-copy-id command.

$ ssh-copy-id user@hostname

You will be prompted for your password one last time, but from that point on you should be able to connect without using your password.

NOTE: If you want to do the same thing to another host, all you need to do is use the ssh-copy-id command again and replace the hostname with the new hostname.

 

Setting the hostname on your Mac

Setting the hostname on your Mac using scuttle

  1. Open a terminal.
  2. Type the following command to change the primary hostname of your Mac:
    sudo scutil –set HostName <new host name>
  3. Type the following command to change the Bonjour hostname of your Mac:
    sudo scutil –set LocalHostName <new host name>
  4. Optional: If you also want to change the computer name, type the following command:
    sudo scutil –set ComputerName <new name>
Like this:
 sudo scutil --get HostName
 sudo scutil --get LocalHostName
 sudo scutil --get ComputerName

Unix Terminal Colors

When using a puTTY or terminal window to a Unix server some people like to set the colours of the text or background, some people don’t.
Sometimes I like to set the text colour to be like to old school Amber monitors.
To do this I use following colour settings
RED: 255, GREEN: 128, BLUE: 0
If also found a very nice blue colour once that I use occasionally.
RED: 5, GREEN: 150, BLUE: 229
If I want an old school green screen look, i usually just go with,
RED: 0, GREEN: 255, BLUE: 0