You are on page 1of 31

Linux Workshop

Linux Workshop
1/63
Content
1 Linux Introduction ................................................................................................................................................... 4
2 Linux basics .............................................................................................................................................................. 5
2.1 Get some information some the Linux ............................................................................................................... 6
2.2 Setting Up locatedb ............................................................................................................................................ 10
3 Linux preparation .................................................................................................................................................. 11
3.1 Installing Linux Packages .................................................................................................................................... 12
3.2 Validating Kernel Parameters ............................................................................................................................ 14
3.3 Setting Up the Host Name ................................................................................................................................. 15
4 Managing Storage on Linux .................................................................................................................................. 16
4.1 Monitoring Free Space ....................................................................................................................................... 17
4.2 Monitoring Disk Usage ....................................................................................................................................... 18
4.3 Working with Logical Volume Manager ............................................................................................................ 19
4.4 Partitioning a Disk .............................................................................................................................................. 24
5 Linux Booting and Cron ......................................................................................................................................... 28
5.1 Configuring Automatic Startup and Shutdown of the Database ..................................................................... 29

Linux Workshop
2/63
Conventions
The following text conventions are used in this document:
Convention Meaning
boldface Boldface type indicates graphical user interface elements
associated with an action or terms defined in text or the
glossary.
italic Italic type indicates emphasis, or placeholder variables for
which you supply particular values.
monospace Monospace type indicates commands within a paragraph,
URLs, code in examples, text that appears on the screen, or
text that you enter.
monospace + boldface Input commands
Italic + boldface Emphasis in a result from an action like an input command or a
user interface action.

Linux Workshop
3/63
Linux Introduction
Get some information some the Linux

1 Linux Introduction
No practice for this lesson.

Linux Workshop
4/63
Linux basics
Get some information some the Linux

2 Linux basics
Get information about the Linux basics.

Linux Workshop
5/63
Linux basics
Get some information some the Linux

2.1 Get some information some the Linux


This practice enables you to gather some information about the Linux operating system
that you are using. You also write a simple shell script.
1) Log in as root. Find out what groups the user you are logged in as belongs to. What is
the primary group?
Note: The password is ZumarFS4$
a) Enter the following at the OS prompt to see the group list for the current user,
which is root:
[root@dbse ~]# id
uid=0(root) gid=0(root) groups=0(root)

The primary group is root because it is listed as gid=, and not just in the groups=
list.
2) Which other users are in the dba group?
a) Enter the following at the OS prompt:
[root@dbse ~]# grep dba: /etc/group
dba:x:54322:oracle,grid
asmdba:x:54323:oracle,grid

There are two users in the dba group: oracle and grid
There is a difference between the primary and supplementary groups. The primary
group is the main one shown in /etc/passwd, that a user is in upon login. For a user
to be in a supplementary group, their user name is added to the group entry in
/etc/group. If you use id <user>, it will show the primary and the supplementary
groups. The supplementary groups give access to resources, but any new files are
created with primary group.
3) Change your prompt string to include the full directory path instead of just the last
subdirectory name. Test your change by navigating to the /home/oracle directory.
Question: Why does the prompt still end with a hash sign when you have specified it
to be a dollar sign? You may need to check the bash man page to answer this.
Note: Your prompt will look different from those shown here because of the specific
machine name being shown.
a) Enter the following at the OS prompt to see the current setting:
[root@dbse ~]# echo $PS1
[\u@\h \W]\$

b) Note that the directory specifier is \W, which represents the last subdirectory of
the current directory. Change it to \w to represent the entire current directory
path name. Note that to make the last character a hash sign, you must enter two
backslashes before the dollar ($) sign. The two backslashes are reduced to one
resulting in the final string having \$, which means display the dollar sign, unless
the user is root, in which case display the hash sign. Make this change by
entering the following:

Linux Workshop
6/63
Linux basics
Get some information some the Linux

[root@dbse ~]# PS1="[\u@\h \w]\\$ "

c) Test this by changing the directory to /home/oracle as shown in the following


box. Note that the prompt now displays the full current working directory.
[root@dbse ~]# cd /home/oracle
[root@dbse /home/oracle]#

d) To answer the question, enter the following on the command line to see the
bash man page:
[root@dbse /home/oracle]# man bash

e) When the man page appears, search for the PS1 string by entering the following:
/PS1

f) When the string is found, enter [N] repeatedly until you see the following:
PS1 The value of this parameter is expanded (see PROMPTING below) and used as
the primary prompt string. The default value is ``\s-\v\$ ''.

g) Note that you are directed to see the section on PROMPTING. So, enter the
following to find that section (case is important):
/PROMPTING

h) The following is displayed:


PROMPTING
When executing interactively, bash displays the primary prompt PS1 when it is ready to read
a command, and the secondary prompt PS2 when it needs more input to complete a command.
Bash allows these prompt strings to be customized by inserting a number of backslash-escaped
special characters that are decoded as follows:
\a an ASCII bell character (07)
\d the date in "Weekday Month Date" format
(e.g., "Tue May 26")
\D{format}
the format is passed to strftime(3) and the result is inserted into the prompt
string; an empty format results in a locale-specific time representation. The
braces are required
\e an ASCII escape character (033)
\h the hostname up to the first â.â
\H the hostname
\j the number of jobs currently managed by the shell device name
\l the basename of the shellâs terminal
\n newline
\r carriage return
\s the name of the shell, the basename of $0 (the portion following the final slash)

i) Enter [j] repeatedly to scroll down to the section that describes the \$ string.
Note that the description for the \$ string states that it causes a dollar sign to be
displayed unless the user ID is 0 (root), in which case, the hash sign is displayed.
\! the history number of this command
\# the command number of this command
\$ if the effective UID is 0, a #, otherwise a $
\nnn the character corresponding to the octal number nnn

Answer: The prompt still ends with a hash sign because the \$ string indicates
that hash is to be used if the user is root.
j) Enter [q] to quit the man page.
4) Write a shell script called showargs.sh that displays each space-delimited parameter

Linux Workshop
7/63
Linux basics
Get some information some the Linux

that is passed to it, on a separate line. For example:


[root@dbse ~]# /tmp/showargs.sh abc 123 xyz
abc
123
xyz

a) Use an editor to create and edit the /tmp/showargs.sh file.


[root@dbse ~]# gedit /tmp/showargs.sh &

b) Enter the following lines into the file:


for fname in $*;
do
echo $fname
done

c) Save the file and exit the editor.


d) At the OS prompt, enter the following to run the script with some test
arguments:
[root@dbse ~]# cd /tmp
[root@dbse /tmp]# ./showargs.sh
bash: ./showargs.sh: Permission denied

Note that the script does not run.


5) Determine why the showargs.sh script did not run, correct that, and run it
successfully with test input.
a) The error is that permission was denied. So, check the permissions on the file by
entering the following command while in the /tmp directory:
[root@dbse /tmp]# ls -l showargs.sh
-rw-r--r--. 1 root root 38 Jul 12 23:21 showargs.sh

b) Note that none of the execute permissions are enabled for this file. Enable them,
and then verify by entering the following commands:
[root@dbse /tmp]# chmod +x showargs.sh
[root@dbse /tmp]# ls -l showargs.sh
-rwxr-xr-x. 1 root root 38 Jul 12 23:21 showargs.sh

c) Reattempt executing the script by entering the following:


[root@db11gse tmp]# ./showargs.sh a b c
a
b
c

6) Determine how long the system has been up by using the virtual file system.
Compare your result with the value returned by the uptime command.
a) At the OS prompt, enter the following to display the /proc/uptime contents. Your
results will vary from those shown.
[root@dbse tmp]# cat /proc/uptime
5257.85 5046.93

b) At the OS prompt, enter the following to run the uptime command:

Linux Workshop
8/63
Linux basics
Get some information some the Linux

[root@dbse tmp]# uptime


23:35:53 up 1:28, 2 users, load average: 0.01, 0.03, 0.08

c) The returned number of seconds of uptime is 5257.85. Dividing this by (60*60),


which is the number of seconds in an hour, results in approximately 1.46 hours.
Note: Your numbers will most certainly vary from those given here.

Linux Workshop
9/63
Linux basics
Setting Up locatedb

2.2 Setting Up locatedb


There are times during these practices when you may need to locate a file. In this practice,
you set up the data structure that supports that search.
1) Run the locate command to find all rpm files.
a) Enter the following at the OS prompt:
[root@dbse ~]# locate rpm
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory

b) Note that the locate command is not able to perform the search because the
locate DB cannot be initialized. Initialize it by entering the following command.
This takes about two minutes to run.
[root@dbse ~]# updatedb

c) Now run the locate command again.


[root@db11gse ~]# locate rpm | more
/boot/grub2/grub.cfg.1548776877.rpmsave
/etc/rpm
/etc/shells.rpmnew
/etc/grub.d/backup/boot_grub/grub.cfg.1548776877.rpmsave
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY
/etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-test
/etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
/etc/rpm/macros.color
/etc/rpm/macros.dist
/etc/rpm/macros.fjava
/etc/rpm/macros.gconf2
/etc/rpm/macros.jpackage
/etc/rpm/macros.perl
/etc/rpm/macros.up2date
/etc/selinux/targeted/active/modules/100/rpm
/etc/selinux/targeted/active/modules/100/rpm/cil
/etc/selinux/targeted/active/modules/100/rpm/hll
...

Linux Workshop
10/63
Linux preparation
Setting Up locatedb

3 Linux preparation
Prepare the Linux for install Oracle Database

Linux Workshop
11/63
Linux preparation
Installing Linux Packages

3.1 Installing Linux Packages


In this practice, you determine whether all the packages required by Oracle Database are
installed, and install o reinstall them if needed.
Note: The scripts for this practice are in the /stage/labs directory.
1) Switch to the root user.
Start a terminal session by right-clicking in the desktop area and selecting Open
Terminal. Enter the following at the OS prompt. Use oracle as the password.
[oracle@dbse ~]$ su - root
Password:
Last login: Sat Jul 13 14:43:09 -05 2019 on pts/0

2) Determine the complete version number of your Linux kernel


Enter the following at the OS prompt:
[root@dbse ~]# uname -r
4.1.12-124.30.1.el7uek.x86_64

3) Determine whether your kernel is tainted.


Enter the following at the OS prompt:
[root@dbse ~]# cat /proc/sys/kernel/tainted
12288

4) Using the /proc file system, display the list of partitions. Enter the following at the
OS prompt:
[root@dbse ~]# cat /proc/partitions
major minor #blocks name

8 0 1073741824 sda
8 1 2097152 sda1
8 2 104861696 sda2
8 3 83890176 sda3
8 4 1 sda4
8 5 41947136 sda5
8 6 31461376 sda6
8 7 16781312 sda7
8 8 251662336 sda8
8 9 541034496 sda9
11 0 1048575 sr0
249 0 41943040 dm-0
249 1 16777216 dm-1
249 2 41943040 dm-2
...

Note: Depending on your system, you may see different output from what is shown.
5) Install all the required packages and configure the operating system using the yum
command to install the oracle-rdbms-server*. This takes a few minutes. Answer “y”
when prompted to download missing packages.
[root@db11gse ~]# yum list oracle-rdbms-server-*
Loaded plugins: langpacks, ulninfo
Installed Packages

Linux Workshop
12/63
Linux preparation
Installing Linux Packages

oracle-rdbms-server-11gR2-preinstall.x86_64 1.0-6.el7 @ol7_latest


Available Packages
oracle-rdbms-server-12cR1-preinstall.x86_64 1.0-7.el7 ol7_latest

Note: If already installed please not execute the following command.


[root@db11gse ~]# yum reinstall oracle-rdbms-server-11gR2-preinstall.x86_64
Loaded plugins: langpacks, ulninfo
adobe-linux-x86_64 | 2.9 kB 00:00
ol7_UEKR4 | 2.5 kB 00:00
ol7_latest | 2.7 kB 00:00
Resolving Dependencies
--> Running transaction check
---> Package oracle-rdbms-server-11gR2-preinstall.x86_64 0:1.0-6.el7 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Reinstalling:
oracle-rdbms-server-11gR2-preinstall x86_64 1.0-6.el7 ol7_latest 22 k

Transaction Summary
================================================================================
Reinstall 1 Package

Total download size: 22 k


Installed size: 53 k
Is this ok [y/d/N]: y
Downloading packages:
oracle-rdbms-server-11gR2-preinstall-1.0-6.el7.x86_64.rpm | 22 kB 00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : oracle-rdbms-server-11gR2-preinstall-1.0-6.el7.x86_64 1/1
Verifying : oracle-rdbms-server-11gR2-preinstall-1.0-6.el7.x86_64 1/1

Installed:
oracle-rdbms-server-11gR2-preinstall.x86_64 0:1.0-6.el7

Complete!

Linux Workshop
13/63
Linux preparation
Validating Kernel Parameters

3.2 Validating Kernel Parameters


The rpm oracle-rdbms-server-* automatically sets all kernel parameters to their
recommended values. Even though the rpm sets up the environment automatically, it
should still be validated.
1) You now need to view and modify kernel parameters to meet the requirements of an
Oracle database installation.
a) If not already logged in as root, execute the su command to start the user session
b) As the root user, enter the following at the OS prompt to go to the directory
where log of the configuration can be viewed:
[root@dbse ~]# cd /var/log/oracle-rdbms-server-11gR2-preinstall/results

c) Open orakernel.log in a file editor:


[root@dbse results]# gedit orakernel.log

d) Validate that the oracle user is created. Look for the Creating oracle user
passed line at the beginning of the orakernel.log file.
...
Creating oracle user passed

Verifying kernel parameters as per Oracle recommendations...


Trying to remove instances of - setting for fs.file-max is
fs.file-max is matching with preinstall config.
fs.file-max = 6815744
...

e) Validate that the kernel parameters are set correctly. Look for the Verifying &
setting of kernel parameters passed line in the file:
...
Check /etc/sysctl.d for backups
Verifying & setting of kernel parameters passed

Setting user limits using /etc/security/limits.conf

Verifying oracle user OS limits as per Oracle recommendations...


oracle soft nofile 1024
nofile soft limit is matching with preinstall config.
oracle hard nofile 65536
nofile hard limit is matching with preinstall config.
...

f) Verify that the user limits are set correctly by looking for the Verifying &
setting of user limits passed line in the file:

g) Verify that the boot parameters are set correctly by looking for the “Verifying &
setting of boot parameters passed” line in the file.

h) If all the steps have been completed successfully, exit the editor.

Linux Workshop
14/63
Linux preparation
Setting Up the Host Name

3.3 Setting Up the Host Name


When you run Oracle Universal Installer, an error may occur if name resolution is not set
up. To avoid this error, before you begin installation, you must ensure that host names
are resolved only through the /etc/hosts file.
1) Verify that the /etc/hosts file is used for name resolution.
You can verify this by checking the hosts file entry in the nsswitch.conf file as follows:
[root@db11gse ~]# grep hosts /etc/nsswitch.conf
#hosts: db files nisplus nis dns
hosts: files dns myhostname

Note that there is a files entry, which means that host names are resolved only
through the /etc/hosts file.
2) Verify that the host name is set correctly. If it does not include the domain name
a) You can verify this by entering the hostname command as follows:
[root@dbse ~]# hostname
linuxdb.zfs.com

Note: The host name is not fully qualified. The hostname can be changed for
example using the command hostnamectl set-hostname linuxdb.zfs.com
b) Verify that the host name is corrected by entering the hostname command
again:
[root@db11gse ~]# cat /proc/sys/kernel/hostname
linuxdbse.zfs.com

c) Verify that the /etc/hosts file:


[root@dbgse ~]# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.80 linuxdbse.zfs.com linuxdbse

Linux Workshop
15/63
Managing Storage on Linux
Setting Up the Host Name

4 Managing Storage on Linux


In this practice you review the storage in linux

Linux Workshop
16/63
Managing Storage on Linux
Monitoring Free Space

4.1 Monitoring Free Space


1) Display information about disk storage on your database server. How much disk
space do you have free in the root partition?
Enter the following at the OS prompt:
[root@dbse ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 327M 1.7G 17% /dev/shm
tmpfs 2.0G 9.7M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/so-root 40G 4.6G 36G 12% /
/dev/sda1 2.0G 331M 1.7G 17% /boot
/dev/mapper/sw-u01 40G 8.8G 32G 22% /u01
/dev/mapper/so-home 40G 6.2G 34G 16% /home
/dev/mapper/so-var 20G 708M 20G 4% /var
/dev/mapper/ra-srv_oracle_db 240G 33M 240G 1% /srv/oracle/db

The root partition is always mounted on /. The available space on this system is
approximately 36 GB.
Note: Depending on your system, you may see different output from what is shown.

Linux Workshop
17/63
Managing Storage on Linux
Monitoring Disk Usage

4.2 Monitoring Disk Usage


1) Which directory under the /usr directory occupies the most disk space?
Enter the following at the OS prompt:
[root@dbse ~]# du -sh /usr/*
147M /usr/bin
0 /usr/etc
0 /usr/games
23M /usr/include
1.3G /usr/lib
1.2G /usr/lib64
130M /usr/libexec
32K /usr/local
63M /usr/sbin
1.4G /usr/share
190M /usr/src
0 /usr/tmp

The directory that uses the most disk space is /usr/share.


Note: Depending on your system, you may see different output from what is shown.

Linux Workshop
18/63
Managing Storage on Linux
Working with Logical Volume Manager

4.3 Working with Logical Volume Manager


In this practice, you work Logical Volume Manager (LVM) tool.
1) Lists block devices. By default, the lsblk command only displays non-empty devices.
However, you can force the tool to display empty devices as well. For this, use the -a
command line option.
root@dbse ~]# lsblk -a
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1T 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 100G 0 part
│ ├─so-root 249:0 0 40G 0 lvm /
│ ├─so-home 249:3 0 40G 0 lvm /home
│ └─so-var 249:4 0 20G 0 lvm /var
├─sda3 8:3 0 80G 0 part
│ ├─ar-srv_oracle_arc1 249:15 0 40G 0 lvm /srv/oracle/arc1
│ └─ar-srv_oracle_arc2 249:16 0 40G 0 lvm /srv/oracle/arc2
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 40G 0 part
│ └─sw-u01 249:5 0 40G 0 lvm /u01
├─sda6 8:6 0 30G 0 part
│ ├─rl-srv_oracle_orl1 249:11 0 10G 0 lvm /srv/oracle/orl1
│ ├─rl-srv_oracle_orl2 249:13 0 10G 0 lvm /srv/oracle/orl2
│ └─rl-srv_oracle_srl 249:14 0 10G 0 lvm /srv/oracle/srl
├─sda7 8:7 0 16G 0 part
│ └─sp-swap 249:1 0 16G 0 lvm [SWAP]
├─sda8 8:8 0 240G 0 part
│ └─ra-srv_oracle_db 249:2 0 240G 0 lvm /srv/oracle/db
└─sda9 8:9 0 516G 0 part
├─asm-disk1 249:6 0 100G 0 lvm
├─asm-disk2 249:7 0 100G 0 lvm
├─asm-disk3 249:8 0 100G 0 lvm
├─asm-disk4 249:9 0 100G 0 lvm
├─asm-disk5 249:10 0 100G 0 lvm
└─asm-disk6 249:12 0 16G 0 lvm
sr0 11:0 1 1024M 0 rom

2) The df command stand for disk filesystem, it is used to get full summary of
available and used disk space usage of file system on Linux system
[root@dbse ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 351M 1.6G 18% /dev/shm
tmpfs 2.0G 9.7M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/so-root 40G 4.6G 36G 12% /
/dev/sda1 2.0G 331M 1.7G 17% /boot
/dev/mapper/ra-srv_oracle_db 240G 33M 240G 1% /srv/oracle/db
/dev/mapper/sw-u01 40G 8.8G 32G 22% /u01
/dev/mapper/so-home 40G 6.2G 34G 16% /home
/dev/mapper/so-var 20G 708M 20G 4% /var
/dev/mapper/ar-srv_oracle_arc1 40G 33M 40G 1% /srv/oracle/arc1
/dev/mapper/ar-srv_oracle_arc2 40G 33M 40G 1% /srv/oracle/arc2
/dev/mapper/rl-srv_oracle_srl 10G 33M 10G 1% /srv/oracle/srl
/dev/mapper/rl-srv_oracle_orl2 10G 33M 10G 1% /srv/oracle/orl2

Linux Workshop
19/63
Managing Storage on Linux
Working with Logical Volume Manager

/dev/mapper/rl-srv_oracle_orl1 10G 33M 10G 1% /srv/oracle/orl1


tmpfs 395M 0 395M 0% /run/user/54322
tmpfs 395M 32K 395M 1% /run/user/0

3) Extract the volumes information


a) Get the logical volume information
[root@dbse ~]# lvdisplay | grep -B 1 -A 16 /dev/rl/srv_oracle_orl1
--- Logical volume ---
LV Path /dev/rl/srv_oracle_orl1
LV Name srv_oracle_orl1
VG Name rl
LV UUID TYLSFl-Mpc3-kFQZ-j0zs-8eUD-Q8Ca-IpmjIn
LV Write Access read/write
LV Creation host, time dbee11prmy.localdomain, 2018-09-05 18:02:13 -0500
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 249:11

--- Logical volume ---


[root@dbse ~]# lvdisplay | grep -B 1 -A 16 /dev/rl/srv_oracle_orl2
--- Logical volume ---
LV Path /dev/rl/srv_oracle_orl2
LV Name srv_oracle_orl2
VG Name rl
LV UUID Ri96UQ-VYYS-QnU8-PsUX-3PBw-LdtG-Zj2LCK
LV Write Access read/write
LV Creation host, time dbee11prmy.localdomain, 2018-09-05 18:02:14 -0500
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 249:13

--- Logical volume ---


[root@dbse ~]# lvdisplay | grep -B 1 -A 16 /dev/rl/srv_oracle_srl
--- Logical volume ---
LV Path /dev/rl/srv_oracle_srl
LV Name srv_oracle_srl
VG Name rl
LV UUID KPmZRw-jxss-HDu2-GkbM-ST5i-RCc9-Rm02pz
LV Write Access read/write
LV Creation host, time dbee11prmy.localdomain, 2018-09-05 18:02:16 -0500
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit

Linux Workshop
20/63
Managing Storage on Linux
Working with Logical Volume Manager

Read ahead sectors auto


- currently set to 8192
Block device 249:14

--- Logical volume ---

b) Get the volume group information


[root@dbse ~]# vgdisplay rl
--- Volume group ---
VG Name rl
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 30.00 GiB
PE Size 4.00 MiB
Total PE 7680
Alloc PE / Size 7680 / 30.00 GiB
Free PE / Size 0 / 0
VG UUID U2obvg-XeR5-vrKN-rdTk-YxB1-hsNe-WirLPO

c) Get the physical volume information


[root@dbse ~]# pvdisplay | grep -B 2 -A 9 rl
--- Physical volume ---
PV Name /dev/sda6
VG Name rl
PV Size 30.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 7680
Free PE 0
Allocated PE 7680
PV UUID mPUBME-fZf7-OfGW-ekyI-YWkG-arm2-86tDX3

--- Physical volume ---

4) Umount, deactivate and remove logical volumes


[root@dbse ~]# umount /dev/rl/srv_oracle_orl1
[root@dbse ~]# umount /dev/rl/srv_oracle_orl2
[root@dbse ~]# umount /dev/rl/srv_oracle_srl
[root@dbse ~]# lvchange -an /dev/rl/srv_oracle_orl1
[root@dbse ~]# lvchange -an /dev/rl/srv_oracle_orl2
[root@dbse ~]# lvchange -an /dev/rl/srv_oracle_srl
[root@dbse ~]# lvremove /dev/rl/srv_oracle_orl1
Logical volume "srv_oracle_orl1" successfully removed
[root@dbse ~]# lvremove /dev/rl/srv_oracle_orl2
Logical volume "srv_oracle_orl2" successfully removed
[root@dbse ~]# lvremove /dev/rl/srv_oracle_srl
Logical volume "srv_oracle_srl" successfully removed

Linux Workshop
21/63
Managing Storage on Linux
Working with Logical Volume Manager

5) Remove the volume group


[root@dbse ~]# vgremove rl
Volume group "rl" successfully removed

6) Remove physical volume


[root@dbse ~]# pvremove /dev/sda6
Labels on physical volume "/dev/sda6" successfully wiped.
[root@dbse ~]# dd if=/dev/zero of=/dev/sda6 bs=1k count=4096
124+0 records in
124+0 records out
126976 bytes (127 kB) copied, 0.00405393 s, 31.3 MB/s

7) List the block device information


[root@dbse ~]# lsblk -a
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1T 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 100G 0 part
│ ├─so-root 249:0 0 40G 0 lvm /
│ ├─so-home 249:10 0 40G 0 lvm /home
│ └─so-var 249:11 0 20G 0 lvm /var
├─sda3 8:3 0 80G 0 part
│ ├─ar-srv_oracle_arc1 249:2 0 40G 0 lvm /srv/oracle/arc1
│ └─ar-srv_oracle_arc2 249:3 0 40G 0 lvm /srv/oracle/arc2
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 40G 0 part
│ └─sw-u01 249:14 0 40G 0 lvm /u01
├─sda6 8:6 0 30G 0 part
├─sda7 8:7 0 16G 0 part
│ └─sp-swap 249:1 0 16G 0 lvm [SWAP]
├─sda8 8:8 0 240G 0 part
│ └─ra-srv_oracle_db 249:15 0 240G 0 lvm /srv/oracle/db
└─sda9 8:9 0 516G 0 part
├─asm-disk1 249:4 0 100G 0 lvm
├─asm-disk2 249:5 0 100G 0 lvm
├─asm-disk3 249:6 0 100G 0 lvm
├─asm-disk4 249:7 0 100G 0 lvm
├─asm-disk5 249:8 0 100G 0 lvm
└─asm-disk6 249:9 0 16G 0 lvm
sr0 11:0 1 1024M 0 rom

8) Create a new logical volume called arc1 and arc2.


a) Create the physical volume
[root@dbse ~]# pvcreate /dev/sda6
Physical volume "/dev/sda6" successfully created.

b) Create the volume group


[root@dbse ~]# vgcreate rl /dev/sda6
Volume group "rl" successfully created

c) Create two logical volumes


[root@dbse ~]# lvcreate -L 14GB -n srv_oracle_orl1 rl
Logical volume "srv_oracle_orl1" created.
[root@dbse ~]# lvcreate -l 100%FREE -n srv_oracle_orl2 rl
Logical volume "srv_oracle_orl2" created.

Linux Workshop
22/63
Managing Storage on Linux
Working with Logical Volume Manager

d) Format the volumes


[root@dbse ~]# mkfs -t xfs /dev/mapper/rl-srv_oracle_orl1
[root@dbse ~]# mkfs -t xfs /dev/mapper/rl-srv_oracle_orl2

e) Mount the volumes


[root@dbse ~]# mount /dev/mapper/rl-srv_oracle_orl1 /srv/oracle/orl1
[root@dbse ~]# mount /dev/mapper/rl-srv_oracle_orl1 /srv/oracle/orl2

f) Modified /etc/fstab and comment the line /dev/mapper/rl-srv_oracle_srl


/srv/oracle/srl
[root@db11gse ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Wed Sep 5 19:02:26 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/so-root / xfs defaults 0 0
UUID=92dca5fa-4fa8-4911-9951-287fdc65b2ea /boot xfs defaults 0
0
/dev/mapper/so-home /home xfs defaults 0 0
/dev/mapper/ar-srv_oracle_arc1 /srv/oracle/arc1 xfs defaults 0 0
/dev/mapper/ar-srv_oracle_arc2 /srv/oracle/arc2 xfs defaults 0 0
/dev/mapper/ra-srv_oracle_db /srv/oracle/db xfs defaults 0 0
/dev/mapper/rl-srv_oracle_orl1 /srv/oracle/orl1 xfs defaults 0 0
/dev/mapper/rl-srv_oracle_orl2 /srv/oracle/orl2 xfs defaults 0 0
# /dev/mapper/rl-srv_oracle_srl /srv/oracle/srl xfs defaults 0 0
/dev/mapper/sw-u01 /u01 xfs defaults 0 0
/dev/mapper/so-var /var xfs defaults 0 0
/dev/mapper/sp-swap swap swap defaults 0 0

Linux Workshop
23/63
Managing Storage on Linux
Partitioning a Disk

4.4 Partitioning a Disk


Parted is a famous command line tool that allows you to easily manage hard disk
partitions. It can help you add, delete, shrink and extend disk partitions along with the file
systems located on them.
Note: Pleas create an attach the disk sdb in your machine
1) Check Parted Version and exit from parted
[root@dbse ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) quit

2) Switch to Different Disk


[root@dbse ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) select /dev/sdb
Using /dev/sdb
(parted) p
Error: /dev/sdb: unrecognised disk label
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 12.9GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted)

3) Now the first step is to give the new disk a label name with:
(parted) mklabel gpt
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 12.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags

4) Now create the new partition with mkpart. The listed units are in megabytes (MB).
We will create a 10 GB partition starting from 1 to 10000:
(parted) mkpart
Partition name? []? one
File system type? [ext2]? ext4
Start? 1
End? 10000
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 12.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Linux Workshop
24/63
Managing Storage on Linux
Partitioning a Disk

Number Start End Size File system Name Flags


1 1049kB 10.0GB 9999MB one

(parted)

5) Resize Linux Disk Partition. You will be asked for the number of the partition that you
will resize. Enter it’s number. After that, you will be asked to set the new ending
point for this partition. Remember that by default the units are in MB. In our
example, we have set the new partition size to 11 GB, and exit from parted:
(parted) resizepart
Partition number? 1
End? [10.0GB]? 11000
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 12.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 1049kB 11.0GB 11.0GB one

(parted) q

6) Make two partitions more


[root@db11gse ~]# parted -a optimal /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 12.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 1049kB 11.0GB 11.0GB one

(parted) mkpart
Partition name? []? two
File system type? [ext2]? ext4
Start? 11.0GB
End? 11.2GB
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 12.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 1049kB 11.0GB 11.0GB one
2 11.0GB 11.2GB 199MB two

(parted) mkpart
Partition name? []? three

Linux Workshop
25/63
Managing Storage on Linux
Partitioning a Disk

File system type? [ext2]? ext4


Start? 11.2GB
End? 11.4GB
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 12.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 1049kB 11.0GB 11.0GB one
2 11.0GB 11.2GB 199MB two
3 11.2GB 11.4GB 200MB three

(parted)

7) Delete Linux Partition (if a partition already have data the number partition is
reassigned to other number).
(parted) rm 2
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 12.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 1049kB 11.0GB 11.0GB one
3 11.2GB 11.4GB 200MB three

(parted)

8) Change Linux Partition Flag


Using parted, you can change the state of a flag for disk partitions. The supported
flags are:
 boot
 root
 swap
 hidden
 raid
 lvm
 lba
 legacy_boot
 irst
 esp
 palo
The states can be either on or off. To change a flag simply run set command within
parted:
(parted) set 1 hidden on
(parted) p
Model: ATA VBOX HARDDISK (scsi)

Linux Workshop
26/63
Managing Storage on Linux
Partitioning a Disk

Disk /dev/sdb: 12.9GB


Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 1049kB 11.0GB 11.0GB one hidden
3 11.2GB 11.4GB 200MB three

(parted) quit
Information: You may need to update /etc/fstab.

[root@db11gse ~]#

Linux Workshop
27/63
Linux Booting and Cron
Partitioning a Disk

5 Linux Booting and Cron


Configuring some automatic task for Oracle on Linux

Linux Workshop
28/63
Linux Booting and Cron
Configuring Automatic Startup and Shutdown of the Database

5.1 Configuring Automatic Startup and Shutdown of the Database


For dealing with reboots, either planned or unplanned, it is good to have your database
start up automatically. This provides higher database availability and reduces the chance
of error. In this practice, you configure the database to start and stop when the OS boots
and shuts down. In addition, you edit the dbstart and dbshut scripts to include starting
and stopping DB Control.
1) Disable the database bankdb, asm and listener for avoid oracle automatic restart
functionality.
[root@dbse oracle]# . oraenv
ORACLE_SID = [root] ? +ASM
The Oracle base has been set to /u01/app/11.2.0
[root@dbse ~]# srvctl disable database -d bankdb
[root@dbse ~]# srvctl disable asm
[root@dbse ~]# srvctl disable listener -l listener
[root@dbse ~]# reboot
...
[root@dbse ~]# ps -fea | grep pmon
root 4827 4421 0 18:26 pts/0 00:00:00 grep --color=auto pmon
[root@dbse ~]# lsnrctl status

2) By editing the /etc/oratab file, configure the ASM and bankdb instances to be
automatically started and stopped when the operating system is started and
stopped.
As the oracle user, edit the /etc/oratab file by changing the third field, which is
delimited by a colon, from N to Y. The resulting lines should appear as follows:
+ASM:/u01/app/11.2.0/grid:Y
bankdb:/u01/app/oracle/product/11.2.0/dbhome_1:Y

Note: May not exists any character or word after the N or Y


3) Create the file ~oracle/labs/dbora script to invokes dbstart and dbshut scripts.
[root@db11gse ~]# mkdir -p ~oracle/labs
[root@db11gse ~]# vi ~oracle/labs/dbora
[root@db11gse ~]# cat /home/oracle/labs/dbora
#! /bin/sh -x
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
# directory for your installation.
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
#
PATH=${PATH}:$ORACLE_HOME/bin
export ORACLE_HOME PATH
#

#
case $1 in
'start')
su - oracle -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" &
;;
'stop')
su - oracle -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" &
;;

Linux Workshop
29/63
Linux Booting and Cron
Configuring Automatic Startup and Shutdown of the Database

*)
echo "usage: $0 {start|stop}"
exit
;;
esac
#
exit

4) Copy the dbora script from the /home/oracle/labs directory to a directory such that
it is invoked during startup and shutdown of the system.
As the root user, enter the following command at the OS prompt:
[root@dbse ~]# cp /home/oracle/labs/dbora /etc/rc.d/init.d

5) Set the permissions for the dbora script to 750 and set the group to dba.
As root, enter the following command at the OS prompt:
[root@db11gse ~]# chmod 750 /etc/rc.d/init.d/dbora
[root@db11gse ~]# chgrp dba /etc/rc.d/init.d/dbora

6) Establish links in the dbora script such that it is invoked during the OS startup and
shutdown in runlevels 3 and 5. The shutdown, or kill scripts, should be executed
first and the startup scripts should be executed last.
As root, enter the following commands:
[root@dbse ~]# ln -s /etc/rc.d/init.d/dbora /etc/rc3.d/S99dbora
[root@dbse ~]# ln -s /etc/rc.d/init.d/dbora /etc/rc3.d/K01dbora
[root@dbse ~]# ln -s /etc/rc.d/init.d/dbora /etc/rc5.d/S99dbora
[root@dbse ~]# ln -s /etc/rc.d/init.d/dbora /etc/rc5.d/K01dbora
[root@dbse ~]# ls -l /etc/rc3.d/*dbora*
lrwxrwxrwx. 1 root root 22 Jul 16 09:46 /etc/rc3.d/K01dbora -> /etc/rc.d/init.d/dbora
lrwxrwxrwx. 1 root root 22 Jul 16 09:46 /etc/rc3.d/S99dbora -> /etc/rc.d/init.d/dbora
[root@dbse ~]# ls -l /etc/rc5.d/*dbora*
lrwxrwxrwx. 1 root root 22 Jul 16 09:47 /etc/rc5.d/K01dbora -> /etc/rc.d/init.d/dbora
lrwxrwxrwx. 1 root root 22 Jul 16 09:47 /etc/rc5.d/S99dbora -> /etc/rc.d/init.d/dbora

Note that the startup scripts start with S99 forcing them to run last. The kill scripts
start with K01 forcing them to run first.
7) Test starting the ASM and dbora database
a) Run the dbstart script by entering the following as root:
[root@dbse ~]# /etc/rc.d/init.d/dbora start

b) Check that the instance is running by issuing the ps commands that are used in
the previous step:
[root@dbse ~]# ps -ef | grep pmon_bankdb
oracle 22597 1 0 13:07 ? 00:00:00 ora_pmon_bankdb
root 22986 21163 0 13:10 pts/0 00:00:00 grep --color=auto pmon_bankdb

8) Test stopping the database instances using dbora.


Enter the following as the root user:
[root@dbse ~]# /etc/rc.d/init.d/dbora stop

Linux Workshop
30/63
Linux Booting and Cron
Configuring Automatic Startup and Shutdown of the Database

Note that shutdown is in progress even though the dbora command returns
immediately. This is because, within the script, dbshut is called with an ampersand
following it, causing it to run in the background.
9) While the databases are being shut down, check whether the instances are still
running. Check for the pmon_bankdb processes.
Run the following command until the only result returned is the grep command
itself.
[root@dbse ~]# ps -ef | grep pmon_bankdb
oracle 21706 1 0 13:01 ? 00:00:00 ora_pmon_bankdb
root 21934 21163 0 13:03 pts/0 00:00:00 grep --color=auto pmon_bankdb
[root@dbse ~]# ps -ef | grep pmon_bankdb
root 22278 21163 0 13:05 pts/0 00:00:00 grep --color=auto pmon_bankdb

The instances have been shut down.


10) Test whether these scripts will be called and will function properly during a reboot.
Enter the following at the OS prompt, as the root user:
# sync; sync; reboot

The system reboots. As the system reinitializes, check for the pmon processes by using
the ps commands used earlier.

Linux Workshop
31/63

You might also like