Sunday, March 19, 2017

RHEL 7 - Disk partition


Disk partition - step by step guide

# cat /root/disklist
#!/bin/bash
#
fdisk -l | grep Disk | egrep "GB|MB" | awk '{print $2 "  " $3 " " $4}' | \
 awk -F"," '{print $1}' | awk -F: '{print $1 "  " $2 }'
[root@bishal ~]# export PATH=$PATH:/root
[root@bishal ~]# chmod u+x disklist
[root@bishal ~]# disklist


[root@bishal ~]# fdisk -l

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/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: 0x0006efee

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux
[root@bishal ~]# fdisk -l

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/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: 0x0006efee

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux
[root@bishal ~]# echo "- - -
> ^C
[root@bishal ~]# echo "- - -" >/sys/class/scsi_host/host
host0/ host1/ host2/
[root@bishal ~]# echo "- - -" >/sys/class/scsi_host/host[0,1,2]/scan
-bash: /sys/class/scsi_host/host[0,1,2]/scan: ambiguous redirect
[root@bishal ~]# echo "- - -" >/sys/class/scsi_host/host0/scan
[root@bishal ~]# fdisk -l

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/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: 0x0006efee

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux

Disk /dev/sdc: 8589 MB, 8589934592 bytes, 16777216 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


[root@bishal dev]# fdisk -l

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/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: 0x0006efee

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux

Disk /dev/sdc: 8589 MB, 8589934592 bytes, 16777216 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

[root@bishal dev]# fdisk /dev/sdc
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 0xb70de004.

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/sdc: 8589 MB, 8589934592 bytes, 16777216 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: 0xb70de004

   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): p
Partition number (1-4, default 1):
First sector (2048-16777215, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdc: 8589 MB, 8589934592 bytes, 16777216 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: 0xb70de004

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     4196351     2097152   83  Linux

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

Command (m for help): p

Disk /dev/sdc: 8589 MB, 8589934592 bytes, 16777216 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: 0xb70de004

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     4196351     2097152   83  Linux
/dev/sdc2         4196352    10487807     3145728   83  Linux

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3):
First sector (10487808-16777215, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-16777215, default 16777215): +8G
Value out of range.
Last sector, +sectors or +size{K,M,G} (10487808-16777215, default 16777215): 1
Value out of range.
Last sector, +sectors or +size{K,M,G} (10487808-16777215, default 16777215): +1G
Partition 3 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdc: 8589 MB, 8589934592 bytes, 16777216 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: 0xb70de004

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     4196351     2097152   83  Linux
/dev/sdc2         4196352    10487807     3145728   83  Linux
/dev/sdc3        10487808    12584959     1048576   83  Linux

Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (12584960-16777215, default 12584960):
Using default value 12584960
Last sector, +sectors or +size{K,M,G} (12584960-16777215, default 16777215):
Using default value 16777215
Partition 4 of type Extended and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdc: 8589 MB, 8589934592 bytes, 16777216 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: 0xb70de004

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     4196351     2097152   83  Linux
/dev/sdc2         4196352    10487807     3145728   83  Linux
/dev/sdc3        10487808    12584959     1048576   83  Linux
/dev/sdc4        12584960    16777215     2096128    5  Extended

Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (12587008-16777215, default 12587008):
Using default value 12587008
Last sector, +sectors or +size{K,M,G} (12587008-16777215, default 16777215): +1G
Partition 5 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdc: 8589 MB, 8589934592 bytes, 16777216 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: 0xb70de004

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     4196351     2097152   83  Linux
/dev/sdc2         4196352    10487807     3145728   83  Linux
/dev/sdc3        10487808    12584959     1048576   83  Linux
/dev/sdc4        12584960    16777215     2096128    5  Extended
/dev/sdc5        12587008    14684159     1048576   83  Linux

Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (14686208-16777215, default 14686208):
Using default value 14686208
Last sector, +sectors or +size{K,M,G} (14686208-16777215, default 16777215):
Using default value 16777215
Partition 6 of type Linux and of size 1021 MiB is set

Command (m for help): p

Disk /dev/sdc: 8589 MB, 8589934592 bytes, 16777216 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: 0xb70de004

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     4196351     2097152   83  Linux
/dev/sdc2         4196352    10487807     3145728   83  Linux
/dev/sdc3        10487808    12584959     1048576   83  Linux
/dev/sdc4        12584960    16777215     2096128    5  Extended
/dev/sdc5        12587008    14684159     1048576   83  Linux
/dev/sdc6        14686208    16777215     1045504   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): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
You have new mail in /var/spool/mail/root
[root@bishal dev]# part
parted     partprobe  partx
[root@bishal dev]# fdisk -l

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/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: 0x0006efee

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux

Disk /dev/sdc: 8589 MB, 8589934592 bytes, 16777216 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: 0xb70de004

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     4196351     2097152   83  Linux
/dev/sdc2         4196352    10487807     3145728   83  Linux
/dev/sdc3        10487808    12584959     1048576   83  Linux
/dev/sdc4        12584960    16777215     2096128    5  Extended
/dev/sdc5        12587008    14684159     1048576   83  Linux
/dev/sdc6        14686208    16777215     1045504   83  Linux
[root@bishal dev]# if you don't see partition^C
[root@bishal dev]# partx /dev/sdc
NR    START      END SECTORS  SIZE NAME UUID
 1     2048  4196351 4194304    2G
 2  4196352 10487807 6291456    3G
 3 10487808 12584959 2097152    1G
 4 12584960 16777215 4192256    2G
 5 12587008 14684159 2097152    1G
 6 14686208 16777215 2091008 1021M
[root@bishal dev]# mkfs.
mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.fat     mkfs.minix   mkfs.msdos   mkfs.vfat    mkfs.xfs
[root@bishal dev]# mkfs.xfs /dev/sdc1
meta-data=/dev/sdc1              isize=256    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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
[root@bishal dev]# pwd
/dev
[root@bishal dev]# mkdir /opt/apps1
[root@bishal dev]# df -h /opt/apps1
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  9.3G  8.5G  53% /
[root@bishal dev]# mount /dev/sdc1 /opt/apps1/
[root@bishal dev]# echo $?
0
[root@bishal dev]# df -h /opt/apps1/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc1       2.0G   33M  2.0G   2% /opt/apps1
[root@bishal dev]# cd /opt/apps
-bash: cd: /opt/apps: No such file or directory
[root@bishal dev]# cd /opt/apps1/
[root@bishal apps1]# echo "Life is beautiful">greet.txt
[root@bishal apps1]# cat greet.txt
Life is beautiful
[root@bishal apps1]# pwd
/opt/apps1
[root@bishal apps1]# ls -l
total 4
-rw-r--r--. 1 root root 18 Mar 19 09:51 greet.txt
[root@bishal apps1]# cd ..
[root@bishal opt]# umount /opt/apps1/^C
[root@bishal opt]# cd -
/opt/apps1
[root@bishal apps1]# pwd
/opt/apps1
[root@bishal apps1]# umount /opt/apps1
umount: /opt/apps1: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@bishal apps1]# fuser /opt/apps1
/opt/apps1:           7649c
[root@bishal apps1]# pst
pstack      pstree      pstree.x11  pstruct
[root@bishal apps1]# pstr
pstree      pstree.x11  pstruct
[root@bishal apps1]# pstree 7649
bash───pstree
[root@bishal apps1]# pwd
/opt/apps1
[root@bishal apps1]# lsof /opt/apps1/
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
bash    7649 root  cwd    DIR   8,33       22  128 /opt/apps1
lsof    9573 root  cwd    DIR   8,33       22  128 /opt/apps1
lsof    9574 root  cwd    DIR   8,33       22  128 /opt/apps1
[root@bishal apps1]# cd /
[root@bishal /]# pwd
/
[root@bishal /]# fuser /opt/apps1
[root@bishal /]# lsof /opt/apps1/
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
[root@bishal /]# umount /opt/apps1/
[root@bishal /]# df -h /opt/apps1
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  9.3G  8.5G  53% /
[root@bishal /]# cd /opt/apps1
[root@bishal apps1]# ls
[root@bishal apps1]# ls -l
total 0
[root@bishal apps1]# ls -la
total 0
drwxr-xr-x. 2 root root  6 Mar 19 09:49 .
drwxr-xr-x. 5 root root 42 Mar 19 09:49 ..
[root@bishal apps1]# pwd
/opt/apps1
[root@bishal apps1]# pwd
/opt/apps1
[root@bishal apps1]# cat > myfile.txt
This file is from root, not on mountpoint
[root@bishal apps1]# pwd
/opt/apps1
[root@bishal apps1]# ls -l
total 4
-rw-r--r--. 1 root root 42 Mar 19 09:57 myfile.txt
[root@bishal apps1]# df -h .
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  9.3G  8.5G  53% /
[root@bishal apps1]# pwd
/opt/apps1
[root@bishal apps1]# cd ..
[root@bishal opt]# mount /dev/sdc1 /opt/apps1/
[root@bishal opt]# df -h / opt/apps1
df: ‘opt/apps1’: No such file or directory
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  9.3G  8.5G  53% /
[root@bishal opt]# df -h /opt/apps1/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc1       2.0G   33M  2.0G   2% /opt/apps1
[root@bishal opt]# cd /opt/apps1
[root@bishal apps1]# ls -l
total 4
-rw-r--r--. 1 root root 18 Mar 19 09:51 greet.txt
[root@bishal apps1]# pwd
/opt/apps1
[root@bishal apps1]# cat greet.txt
Life is beautiful
[root@bishal apps1]# df -h /opt/apps1/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc1       2.0G   33M  2.0G   2% /opt/apps1
[root@bishal apps1]#


[root@bishal app2]# df -h .
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdf2      1014M   33M  982M   4% /opt/app2
[root@bishal app2]# blkid /dev/sdf2
/dev/sdf2: UUID="369645b2-831a-4c8b-bbad-926408849e08" TYPE="xfs"
[root@bishal app2]# vi /etc/fstab
 UUID="369645b2-831a-4c8b-bbad-926408849e08" /opt/app1 xfs defaults 0 0
[root@bishal app2]# df -h

No comments:

Post a Comment