Saturday, January 26, 2019

Python - Buy 8 items and calculate the total

Buy 8 items and out of 8, 6 of them are taxable items. 2 are not. If total crosses $100, give 5% discount. Calculate the total.

print("Welcome to ABC store")
print("Please select the items from list below")
print('')
print("Items        Rate/per item($)")
print("-----        ----------------")
print("Apples          2 ")
print("Bananas         1")
print("Potatoes        3")
print("Medical1        5")
print("Medical2        4")
print("Item1           10")
print("Item2           8")

apple_rate=2
banama_rate=1
potatoes_rate=3
medicine1_rate=5
medicine2_rate=4
item1_rate=10
item2_rate=8

print("")
print("Please enter the quentity of the items you want to buy.")
apple = int(input('Quantity of apples: '))
banana = int(input('Quantity of banana: '))
potatoes = int(input('Quantity of potatoes: '))
medicine1 = int(input('Quantity of Medicine1: '))
medicine2 = int(input('Quantity of Medicine2: '))
item1 = int(input('Quantity of item1: '))
item2 = int(input('Quantity of item2: '))
total_items=apple+banana+potatoes+medicine1+medicine2+item1+item2

print("")
apple_total=apple_rate*apple
banana_total=banama_rate*banana
potatoes_total=potatoes_rate*potatoes
medicine1_total=medicine1_rate*medicine1
medicine2_total=medicine2_rate*medicine2
item1_total=item1_rate*item1
item2_total=item2_rate*item2

print("")
print("Apple Bill is $", apple_total)
print("Banana Bill is $", banana_total)
print("Potato Bill is $", potatoes_total)
print("Medicine1 Bill is $", medicine1_total)
print("Medicine2 Bill is $", medicine2_total)
print("Item1 Bill is $", item1_total)
print("Item2 Bill is $", item2_total)
print("")

taxed_item_total=apple_total+banana_total+potatoes_total+item1_total+item2_total
print("Taxable item total is $",taxed_item_total)
total_tax_bill=float(taxed_item_total*.05)
print("total tax is $",total_tax_bill)
print("")

total_taxable_item=taxed_item_total+total_tax_bill
nontax_total=medicine1_total+medicine2_total
print("Taxable total Bill is $", total_taxable_item)
print("Non-taxable item Bill is $",nontax_total)
total_all=total_taxable_item+nontax_total
print("The total of all item is $", total_all)

if total_all >=100:
    discount=total_all*.05
    grandtotal=total_all-discount
    print("Your total Bill is $", grandtotal)
    print("You saved $",discount," today")
else:
    print("Total Bill is $",total_all)

print("")
print("You have purchased total of",total_items,"items")
print("Thank you for shopping ABC store")



=================== Resumt ====================

Welcome to ABC store
Please select the items from list below

Items        Rate/per item($)
-----        ----------------
Apples          2 
Bananas         1
Potatoes        3
Medical1        5
Medical2        4
Item1           10
Item2           8

Please enter the quentity of the items you want to buy.
Quantity of apples: 2
Quantity of banana: 6
Quantity of potatoes: 7
Quantity of Medicine1: 3
Quantity of Medicine2: 8
Quantity of item1: 9
Quantity of item2: 2


Apple Bill is $ 4
Banana Bill is $ 6
Potato Bill is $ 21
Medicine1 Bill is $ 15
Medicine2 Bill is $ 32
Item1 Bill is $ 90
Item2 Bill is $ 16

Taxable item total is $ 137
total tax is $ 6.8500000000000005

Taxable total Bill is $ 143.85
Non-taxable item Bill is $ 47
The total of all item is $ 190.85
Your total Bill is $ 181.3075
You saved $ 9.5425  today

You have purchased total of 37 items
Thank you for shopping ABC store

Friday, January 25, 2019

Python - Installing Python Practicing tools Eclipse, PyCharm

There are so many IDE tools available. On of the best on Windows machines are followings
1. Eclipse
2. PyCharm
3. repl.it

-----------------------------------------------------------

1. Eclipse
Installing Eclipse IDE on Windows 10 for python3

Prerequisite task
a. Make sure you installed Python 3 on your system
b. Make sure you have enough disk space on your system.


a. Download Eclipse:
Go to official Eclipse website and download the software
https://www.eclipse.org/downloads/ and download latest Eclipse IDE for Windows.

I downloaded Eclipse IDE 2018‑12
https://www.eclipse.org/downloads/download.php?file=/oomph/epp/2018-12/R/eclipse-inst-win64.exe

b. Install the software
- Double Click on downloaded file and choose: Eclipse IDE for C/C++ Developer
- Select the directory C:\Eclipse2 as your installation directory.
- Just click accept and install it.


A. Installation of the PyDev plug-in for Eclipse

- Open your Eclipse
- Go to help -> Install New Software
- Type the URL http://pydev.org/updates in the Work with:  field
- And click on Add
- You have two options.
a. PyDev
2. PyDev Mylyn Integration
- Select the first one. 1. PyDev
- Click next/yes.OK/ Trust certificate and complete the installation.

B. Configuring PyDev
- On your Eclipse software, click on Windows and click on preferences
- From the lift side listings, Double click on PyDev and Double click on Interpreters
- Click on Python Interpreter and click on New
Interpreter Name: Python3
Interpreter Executable: C:\Python3\python3.exe (or Python Installed Location)

- Click OK. Verify and select the PATH and click ok.


Writing First Python Program on Eclipse

First Change the Perspective
- Click on Windows on your Eclipse
- Click on  Perspective  and point to open Perspective and Other
- Click on PyDev
- Now, Eclipse will restart

Once Eclipse is restarted,
- Click on File  and point to New and click on PyDev Project
- Type the name of the Project Name (Python-Practice)
- Click Finish
- Now, Right Click on Project Name => New => File
- Type the file Name as hello.py and click finish.
- Type the following lines


# Hello World on Python
print (“Hello, World !!!")

Now, Save the file and execute the program.

- To complete, type
- Ctrl+S to save the file
- Ctrl+B to Build the program
- Ctrl+F11 to execute the program

Review the output
You can add more lines to learn more.



2. There is another great tool called PyCharm, simply download and practice.
https://www.jetbrains.com/pycharm/

- Simply down and install it. So simple. Download the edu version which comes with example.
Superb tool !!!

3. Other tool to practice Python is to use the online verson of
http://repl.it

Once of the great tool available online.

Python - Installation on Linux and Windows 10

A. Installing on Linux
a. To install python on Linux, you have to use software installation tool such as yum for redhat
# yum search python
# yum install python

By default, python is install on most operating systems. You may already have version 2.x installed.

After the installation, you must set PATH for version 3.


A. Installing Python3 in Windows

1. Download python3 from the web

As of now, the latest version is - Python 3.7.2 - 2018-12-24
https://www.python.org/downloads/windows/
I downloaded,
https://www.python.org/ftp/python/3.7.2/python-3.7.2-amd64.exe

2. Installation process
a. Create a directory Python3 under the C drive.
b. Double click the python installer and choose customize.
c. Chose installation directory as C:\Python3 and click on Install
d. Accept the default options and continue until inish.

B. Setting up the Environment Variable (Windows 10)

a. Right Click on My Computer or This PC
b. Click on Properties; and then click on on Advanced System Settingsor
c. Click on Advanced and then on Environment Variables at the bottom.
d. On your Environment Variable windows, look under system variables.
e. Search the variable Path and once found, double click to edit
f. Click on New and type c:\Python3 and click ok.
g. Once you click ok, you will see something like this.
C:\Program Files (x86)\iCLS Client\;......;C:\Python3

C. Writing your python code
a. Create a directory under Documents [ C:\Users\devi\Documents\Python-Practice ]
b. Right Click on the directory and click on Text Document
c. Rename the file as hellp.py
d. Open the file and type
    print("Hello, World !!!")
e. Save the file.
f. Press Windows Button and R at the same time, a pop up windows shows up
g. Type cmd and click OK.
h. You will see dos windows. Go to your code location
   cd C:\Users\Devi Neopane\Documents\Python-Practice
h. Now at the prompt, type, python hellp.py

You should see the output.

If you don't get the correct output, you have to review your PATH.

Friday, January 11, 2019

Python - Learn by example - Variable assignment

# Defining variables
# Block of code is called shout
#
def myvar1():
    a=10; b=30; c=a+b; d=a+b+c; print(d)
    print("The Sun of", a, b, "and", c, "is:", d)

myvar1()


Python - Learn by example - Variables and Function

# define variables
x=5
y=6
#x=y
y=x

print ("x = ", x)
print ("y =", y)

===============

a='Hello '
b='World !!!'

c=a + b
print("To put together a + b, we get:- ", c)

# Assigning numerical values
x=5
y=2
z=x+y
z1=x-y
z2=x*y
z3=x/2

print("The value stored on memory location is", id(a))
print("The Sum of", x, "and", y, "is", z)
print("The sub of x and y is", z1)
print ("The multiplicaiton of", x, "and", y, "is", z2)
print ("The division of x and y is", z3)

# Using function


def mymath1():
    # define variables
    x=5
    y=2
    z=x+y
    z1=x-y
    z2=x*y
    z3=x/2
    print("The Sum of", x, "and", y, "is", z)
    print("The sub of x and y is", z1)
    print ("The multiplicaiton of", x, "and", y, "is", z2)
    print ("The division of x and y is", z3)

# calling the function
mymath1()


# Input from user, accepts a input value from user
a=input('Please enter a value: ')

print("User input is",a )

# Use function to accept value from user input
def domath():
    a=input('Please enter a number you like: ')
    b=input('Please enter a second value: ')
    c=a+b
    print("Output is as a string ")
    print("The sum of", a, "and", a, "is: ", c)
 
domath()

# Here you will get out put like below
# Please enter a number you like: 5
# Please enter a second value: 2
# The sum of 5 and 5 is:  52
# The reason is it treats these value as string so
# the program put both value together.
# if you want to perform mathematical operation, do the following,
#
def domymath():
    a=int(input("Please enter a number: "))
    b=int(input("Please enter another number "))

    c=a+b
    print("Output as numerical value")
    print("The sum of", a, "and", b, "is: ", c)

domymath()


# ========================================
# Playing with string

a=input('Please enter a string you like: ')
print ("You entered: ", a)
# Use function to accept value from user input as string
def dostring():
    a=input('Please enter a string you like: ')
    b=input('Please enter a second value: ')
    c=a+b
    print("Output is as a string")
    print("The sum of", a, "and", a, "is: ", c)
 
dostring()

# Here we will use decimal value for mathematical operation.
#
def domyfloat():
    # enable 2 lines below and test it. it will throw error if you pass
    # letter because letters are treated as string...
    # a=int(input("Please enter a string: "))
    # b=int(input("Please enter another non-number: "))
    # so you have to change integer to fload to change number to string.
    a=float(input("Please enter a folating value here: "))
    b=float(input("Please enter another floating value link 3.2: "))

    c=a+b
    print("Output as floating point value")
    print("The sum of", a, "and", b, "is: ", c)

domyfloat()



Phthon - Learn by Example - Hello World

# My python program
# # sign is comment

print ('Hello, World !!!')
print ("I am learning Python")

#---------------------------------

print ('I like it')
# The line below is comment
''' Multi line comment'''
''' How is everything
I am sort of liking it
and this
is really
cool '''
print ('Learning Python is cool')

Monday, January 7, 2019

RHEL - Extending /boot Partition from 200M to 500M on CentOS / RHEL


Extending /boot Partition from 200M to 500M on CentOS / RHEL


Some dev env, you will have multiple kernel instances and takes up lots of space.
Here is the step to extend /boot partition on your system.

We will be using LVM to create /boot partition.
Or you can use a physical partition as well if possible.

1. Check the available space on your Volume Group
# vgs; lvs

2. Create a logical volume
# lvcreate -n boot -L 500M root-boot
or
# lvcreate -n boot -L 500M /dev/root-boot/boot

3. Create filesystem and add entry to fstab and mount it.
# lvscan
# mkfs.xfs /dev/root-boot/boot
# vi /etc/fstab
/dev/root-boot/boot /boot1 xfs defaults 0 0

# mount -a

4. copy all files from /boot to /boot1
# cp -rp /boot/* /boot1

5. Comment out old entry for /boot and change mount point for new device to /boot.
# /dev/sda1 /boot xfs default 0 0
/dev/root-boot/boot /boot xfs defaults 0 0

6. Reboot your machine and verify your system is up and running..
# reboot

RHEL- Using Google Public DNS on your linux systems

Copied from
https://developers.google.com/speed/public-dns/docs/using

Configure your network settings to use Google Public DNS

When you use Google Public DNS, you are changing your DNS "switchboard" operator from your ISP to Google Public DNS.
In most cases, the IP addresses used by your ISP's domain name servers are automatically set by your ISP via the Dynamic Host Configuration Protocol (DHCP). To use Google Public DNS, you need to explicitly change the DNS settings in your operating system or device to use the Google Public DNS IP addresses. The procedure for changing your DNS settings varies according to operating system and version (Windows, Mac or Linux) or the device (computer, phone, or router). We give general procedures here that might not apply for your OS or device; please consult your vendor documentation for authoritative information.

Important: Before you start

Before you change your DNS settings to use Google Public DNS, be sure to write down the current server addresses or settings on a piece of paper. It is very important that you keep these numbers for backup purposes, in case you need to revert to them at any time.
We also recommend that you print this page, in the event that you encounter a problem and need to refer to these instructions.

Google Public DNS IP addresses

The Google Public DNS IP addresses (IPv4) are as follows:
  • 8.8.8.8
  • 8.8.4.4
The Google Public DNS IPv6 addresses are as follows:
  • 2001:4860:4860::8888
  • 2001:4860:4860::8844
You can use either address as your primary or secondary DNS server. You can specify both addresses, but do not specify the same address as both primary and secondary.
You can configure Google Public DNS addresses for either IPv4 or IPv6 connections, or both. For IPv6-only networks with a NAT64 gateway using the 64:ff9b::/96 prefix, you can use Google Public DNS64 instead of Google Public DNS IPv6 addresses, providing connectivity to IPv4-only services without any other configuration.
Some devices use separate fields for all eight parts of IPv6 addresses and cannot accept the :: IPv6 abbreviation syntax. For such fields enter:
  • 2001:4860:4860:0:0:0:0:8888
  • 2001:4860:4860:0:0:0:0:8844
Expand the 0 entries to 0000 if four hex digits are required.

Change your DNS servers settings

Because the instructions differ between different versions/releases of each operating system, we only give one version as an example. If you need specific instructions for your operating system/version, please consult your vendor's documentation. You may also find answers on our user group.
Many systems allow you to specify multiple DNS servers, to be contacted in a priority order. In the following instructions, we provide steps to specify only the Google Public DNS servers as the primary and secondary servers, to ensure that your setup will correctly use Google Public DNS in all cases.

Windows

DNS settings are specified in the TCP/IP Properties window for the selected network connection.
Example: Changing DNS server settings on Windows 7
  1. Go to the Control Panel.
  2. Click Network and Internet > Network and Sharing Center >Change adapter settings.
  3. Select the connection for which you want to configure Google Public DNS. For example:
    • To change the settings for an Ethernet connection, right-click Local Area Connection > Properties.
    • To change the settings for a wireless connection, right-click Wireless Network Connection > Properties.
    If you are prompted for an administrator password or confirmation, type the password or provide confirmation.
  4. Select the Networking tab. Under This connection uses the following items, select Internet Protocol Version 4 (TCP/IPv4) or Internet Protocol Version 6 (TCP/IPv6) and then click Properties.
  5. Click Advanced and select the DNS tab. If there are any DNS server IP addresses listed there, write them down for future reference, and remove them from this window.
  6. Click OK.
  7. Select Use the following DNS server addresses. If there are any IP addresses listed in the Preferred DNS server or Alternate DNS server, write them down for future reference.
  8. Replace those addresses with the IP addresses of the Google DNS servers:
    • For IPv4: 8.8.8.8 and/or 8.8.4.4.
    • For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844.
    • For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point.
  9. Restart the connection you selected in step 3.
  10. Test that your setup is working correctly; see Test your new settings below.
  11. Repeat the procedure for additional network connections you want to change.

Mac OS

DNS settings are specified in the Network window.
Example: Changing DNS server settings on Mac OS 10.5
  1. Click Apple > System Preferences > Network.
  2. If the lock icon in the lower left-hand corner of the window is locked, click the icon to make changes, and when prompted to authenticate, enter your password.
  3. Select the connection for which you want to configure Google Public DNS. For example:
    • To change the settings for an Ethernet connection, select Built-In Ethernet, and click Advanced.
    • To change the settings for a wireless connection, select Airport, and click Advanced.
  4. Select the DNS tab.
  5. Click + to replace any listed addresses with, or add, the Google IP addresses at the top of the list:
    • For IPv4: 8.8.8.8 and/or 8.8.4.4.
    • For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844.
    • For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point.
  6. Click Apply > OK.
  7. Test that your setup is working correctly; see Test your new settings below.
  8. Repeat the procedure for additional network connections you want to change.

Linux

In most modern Linux distributions, DNS settings are configured through Network Manager.
Example: Changing DNS server settings on Ubuntu
  1. Click System > Preferences > Network Connections.
  2. Select the connection for which you want to configure Google Public DNS. For example:
    • To change the settings for an Ethernet connection, select the Wired tab, then select your network interface in the list. It is usually called eth0.
    • To change the settings for a wireless connection, select the Wireless tab, then select the appropriate wireless network.
  3. Click Edit, and in the window that appears, select the IPv4 Settings or IPv6 Settings tab.
  4. If the selected method is Automatic (DHCP), open the dropdown and select Automatic (DHCP) addresses only instead. If the method is set to something else, do not change it.
  5. In the DNS servers field, enter the Google Public DNS IP addresses, separated by a comma:
    • For IPv4: 8.8.8.8 and/or 8.8.4.4.
    • For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844.
    • For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point.
  6. Click Apply to save the change. If you are prompted for a password or confirmation, type the password or provide confirmation.
  7. Test that your setup is working correctly; see Test your new settings below.
  8. Repeat the procedure for additional network connections you want to change.
If your distribution doesn't use Network Manager, your DNS settings are specified in /etc/resolv.conf.
Example: Changing DNS server settings on a Debian server
  1. Edit /etc/resolv.conf:
    sudo vi /etc/resolv.conf
  2. If any nameserver lines appear, write down the IP addresses for future reference.
  3. Replace the nameserver lines with, or add, the following lines:
    For IPv4:
    nameserver 8.8.8.8 nameserver 8.8.4.4
    For IPv6:
    nameserver 2001:4860:4860::8888 nameserver 2001:4860:4860::8844
    For IPv6-only, you can use Google Public DNS64 instead of the above IPv6 addresses.
  4. Save and exit.
  5. Restart any Internet clients you are using.
  6. Test that your setup is working correctly; see Test your new settings below.
Additionally, if you are using DHCP client software that overwrites the settings in /etc/resolv.conf, you will need to set up the client accordingly by editing the client's configuration file.
Example: Configuring DHCP client sofware on a Debian server
  1. Back up /etc/resolv.conf:
    sudo cp /etc/resolv.conf /etc/resolv.conf.auto
  2. Edit /etc/dhcp3/dhclient.conf:
    sudo vi /etc/dhcp3/dhclient.conf
  3. If there is a line containing domain-name-servers, write down the IP addresses for future reference.
  4. Replace that line with, or add, the following line:
    For IPv4:
    prepend domain-name-servers 8.8.8.8, 8.8.4.4;
    For IPv6:
    prepend domain-name-servers 2001:4860:4860::8888, 2001:4860:4860::8844;
    For IPv6-only, you can use Google Public DNS64 instead of the above IPv6 addresses.
  5. Save and exit.
  6. Restart any Internet clients you are using.
  7. Test that your setup is working correctly; see Test your new settings below.

Routers

Every router uses a different user interface for configuring DNS server settings; we provide only a generic procedure below. For more information, please consult your router documentation.
To change your settings on a router:
  1. In your browser, enter the IP address to access the router's administration console.
  2. When prompted, enter the password to access network settings.
  3. Find the screen in which DNS server settings are specified.
  4. If there are IP addresses specified in the fields for the primary and seconday DNS servers, write them down for future reference.
  5. Replace those addresses with the Google IP addresses:
    • For IPv4: 8.8.8.8 and/or 8.8.4.4.
    • For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844.
    • For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point.
  6. Save and exit.
  7. Restart your browser.
  8. Test that your setup is working correctly; see Test your new settings below.
Some routers use separate fields for all eight parts of IPv6 addresses and cannot accept the :: IPv6 abbreviation syntax. For such fields enter:
  • 2001:4860:4860:0:0:0:0:8888
  • 2001:4860:4860:0:0:0:0:8844
Expand the 0 entries to 0000 if four hex digits are required.

Mobile or other devices

DNS servers are typically specified under advanced Wi-Fi settings. However, as every mobile device uses a different user interface for configuring DNS server settings, we provide only a generic procedure below. For more information, please consult your mobile provider's documentation.
To change your settings on a mobile device:
  1. Go to the screen in which Wi-Fi settings are specified.
  2. Find the screen in which DNS server settings are specified.
  3. If there are IP addresses specified in the fields for the primary and seconday DNS servers, write them down for future reference.
  4. Replace those addresses with the Google IP addresses:
    • For IPv4: 8.8.8.8 and/or 8.8.4.4.
    • For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844.
    • For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point.
  5. Save and exit.
  6. Test that your setup is working correctly; see Test your new settings below.

Test your new settings

To test that the Google DNS resolver is working:
  1. From your browser, enter a hostname URL (such as http://www.google.com/). If it resolves correctly, bookmark the page, and try accessing the page from the bookmark.
    If all of these tests work, everything is working correctly. If not, go to step 2.
  2. From your browser, type in a fixed IP address. You can use http://216.218.228.119/ (which points to the test-ipv6.com website) as the URL.1
    • If you are using Google Public DNS64 on an IPv6-only system, use http://[64:ff9b::d8da:e477]/ as the URL instead. If this test does not work, you do not have access to a NAT64 gateway at the reserved prefix 64:ff9b::/96 and cannot use Google Public DNS64.
    • If you are using an IPv6-only system without Google Public DNS64, use http://[2001:470:1:18::119]/ as the URL instead.
    If this works correctly, bookmark the page, and try accessing the page from the bookmark. If these tests work (but step 1 fails), then there is a problem with your DNS configuration; check the steps above to make sure you have configured everything correctly. If these tests do not work, go to step 3.
  3. Roll back the DNS changes you made and run the tests again. If the tests still do not work, then there is a problem with your network settings; contact your ISP or network administrator for assistance.
If you encounter any problems after setting Google Public DNS as your resolver, please run the diagnostic procedure.
1 Google thanks Jason Fesler for granting permission to use test-ipv6.com URLs for browser DNS testing purposes.

Switch back to your old DNS settings

If you had not previously configured any customized DNS servers, to switch back to your old settings, in the window in which you specified the Google IP addresses, select the option to enable obtaining DNS server addresses automatically, and/or delete the Google IP addresses. This will revert your settings to using your ISP's default servers.
If you need to manually specify any addresses, use the procedures above to specify the old IP addresses.
If necessary, restart your system.

Saturday, January 5, 2019

RHEL- Filesystem creation lab


1. Add 5 new LUN - 2 GB each
-> one disk - create regular filesystem of 1Gb and mount at /opt/mydisk
   - Create another patition and add as a swap device.

Solution
--------
1. Use fdisk program to create 2 partition - /dev/sdb1 /dev/sdb2
2. partprobe /dev/sdb
3. Create filesystem: mkfs.xfs /dev/sdb1
4. mkswap /dev/sdb1; swapon /dev/sdb1


2. Use 2 disks - create LVM partition. Create a filesystem with 3GB in size and mount at /opt/myapp1
  - Create 1GB swap partition and add it to the system.

Solution
--------
- Create LVM partition
- Create Physical volume/ Volume Group
- Create Logical volume - one for filesystem and one for swap
- add entry to /etc/fstab
- Mount the filesystem

3. Use remaining 2 disks - create a filesystem with exetnt size of 16M and mount at /opt/myapp2
Hint: Create VG with 16MB extent

- Create patition
- Create physical volume
- Create VG with extent size of 16MB
- Create logical volume
- Add entry to fstab
- Mount the filesystem.


===============Detail steps===============

1. Use fdisk program to create 2 partition

[root@localhost ~]# fdisk -l  | grep Disk | egrep "GB|MB" | awk '{print $2 " " $3 " " $4}' | awk -F: '{print $1 " " $2}' | awk -F, '{print $1}'
[root@localhost ~]# vi disk-size.sh
[root@localhost ~]# sh disk-size.sh


1. List the devices on the system
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008320e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdd: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

2. Create a partition
[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x034c7125.

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x034c7125

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): +1G
Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x034c7125

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3. Create filesystem
[root@localhost ~]# mkfs.xfs  /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

4. Add device entry to fstab
[root@localhost ~]# blkid /dev/sdb1
/dev/sdb1: UUID="0e4a16ca-cd6a-422a-a0fc-516a64818456" TYPE="xfs"
[root@localhost ~]# blkid /dev/sdb1 | awk '{print $2}'
UUID="0e4a16ca-cd6a-422a-a0fc-516a64818456"
[root@localhost ~]# blkid /dev/sdb1 | awk '{print $2}' >> /etc/fstab
[root@localhost ~]# vi /etc/fstab
[root@localhost ~]# cat /etc/fstab
/dev/mapper/centos-root /       xfs     defaults        0 0
/dev/sda1       /boot   xfs     defaults        0 0
/dev/mapper/centos-swap         swap    swap    defaults        0 0


#blkid /dev/sdc5 /opt/data1  xfs  default  0 0
#:wUUID="9c1f225f-aca6-4f09-9290-e3357d83fb14" /opt/test xfs  defaults  0 0
UUID="0e4a16ca-cd6a-422a-a0fc-516a64818456" /opt/best xfs defaults 0 0

5. Mount the filesystem.
[root@localhost ~]# mkdir /opt/best; mount /opt/best; df -h /opt/best
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1      1014M   33M  982M   4% /opt/best
[root@localhost ~]#