11-07-2020

https://youtu.be/-rEm3lopuhw

 

 

Disk Management

 

Hard Disk (Hard Drive)

 

IDE – Linux will handle these kind fo devices /dev/hda

SCSI – Linux will handle these kind of devices /dev/sda

Virtual drive – Linux will handle these kind of devices /dev/vda

 

SCSI –

 

Small Computer System Interface is a set of standards for physically connecting and transferring data between computers and peripheral devices. The SCSI standards define commands, protocols, electrical, optical and logical interfaces

 

 

Very first drive

/dev/sda

Second drive

/dev/sdb

Third drive

/dev/sdc

 

 

26th drive

/dev/sdz

27th drive

/dev/sdaa

28th drive

/dev/sdab

 

 

List the disk

 

Lsblk

 

[root@zmpt01 ~]# lsblk

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   16G  0 disk

sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   15G  0 part

  centos-root 253:0    0 13.4G  0 lvm  /

  └─centos-swap 253:1    0  1.6G  0 lvm  [SWAP]

sdb               8:16   0   16G  0 disk

sdc               8:32   0    8G  0 disk

sr0              11:0    1 1024M  0 rom

 

Linux handles the devices as files

 

[root@zmpt01 ~]# ls -l /dev/sd*

brw-rw----. 1 root disk 8,  0 Nov  7 16:54 /dev/sda

brw-rw----. 1 root disk 8,  1 Nov  7 16:54 /dev/sda1

brw-rw----. 1 root disk 8,  2 Nov  7 16:54 /dev/sda2

brw-rw----. 1 root disk 8, 16 Nov  7 16:54 /dev/sdb      < ---Working on this disk

brw-rw----. 1 root disk 8, 32 Nov  7 16:54 /dev/sdc

 

Three comman ways to manage the disk

 

-          Fdisk – Fixed disk setup program

-          Gdisk – Same as fdisk, but uses GPT

-          LVM – Logical Volume Manager

 

 

FDISK

 

Fixed Disk Setup Program

 

/dev/sdb – 16GB

8GB

/dev/sdb1

 

 

 

 

 

[root@zmpt01 ~]# fdisk /dev/sdb

Command (m for help): m

Command (m for help): n

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-33554431, default 2048):   < ---hit enter

Last sector, +sectors or +size{K,M,G} (2048-33554431, default 33554431): +8G

Command (m for help): w

The partition table has been altered!

 

10-08-2020

https://youtu.be/QLM0NTsxtwA

 

Run partprobe

 

[root@zmpt01 ~]# partprobe

 

 

[root@zmpt01 ~]# lsblk

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   16G  0 disk

sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   15G  0 part

  centos-root 253:0    0 13.4G  0 lvm  /

  └─centos-swap 253:1    0  1.6G  0 lvm  [SWAP]

sdb               8:16   0   16G  0 disk

└─sdb1            8:17   0    8G  0 part          < ---New created partition

sdc               8:32   0    8G  0 disk

sr0              11:0    1 1024M  0 rom

 

Creating the file system

In computing, a file system or filesystem controls how data is stored(writing) and retrieved(access)

 

 

[root@zmpt01 ~]# mkfs.ext4 /dev/sdb1            < ---Command to create EXT4 file system

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)                       < ---4KB is the default black space (smallest useable block)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

524288 inodes, 2097152 blocks

104857 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2147483648

64 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

 

Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

 

 

 

 

Binary is base 2 = 1 0

1 = on

0 = off

 

2^8

 

 

 

4096 = 4kb  minimum useable

 

File Size

Disk Space used 4K

0

4 kb

1 kb

4kb

2 kb

4 kb

4 kb

4 kb

6 kb

8 kb

13 kb

16 kb

21

24 kb

 

 

File System structure

 

 

File System

Max Disk Size

Single file size

Ext2

32 TB

2 TB

Ext3

32 TB

2 TB

Ext4

1 Eib

16 TB

XFS

16 Eib

500 TB for RHEL - 7

100 TB for RHEL - 8

 

 

 

Mount the file system – makign it available for useage

 

[root@zmpt01 ~]# mkdir /DATA

 

[root@zmpt01 ~]# mount /dev/sdb1 /DATA/   < ---you have to provide absolute path when mounting

 

Command

Filesystem

Mount point/ location

Mount

/dev/sdb1

/DATA

 

 

 

To see the disk and mount point being used

 

[root@zmpt01 ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

devtmpfs                 484M     0  484M   0% /dev

tmpfs                    496M     0  496M   0% /dev/shm

tmpfs                    496M  6.8M  489M   2% /run

tmpfs                    496M     0  496M   0% /sys/fs/cgroup

/dev/mapper/centos-root   14G  1.8G   12G  14% /

/dev/sda1               1014M  136M  879M  14% /boot

tmpfs                    100M     0  100M   0% /run/user/0

/dev/sdb1                7.8G   36M  7.3G   1% /DATA

 

 

[root@zmpt01 ~]# lsblk

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   16G  0 disk

sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   15G  0 part

  centos-root 253:0    0 13.4G  0 lvm  /

  └─centos-swap 253:1    0  1.6G  0 lvm  [SWAP]

sdb               8:16   0   16G  0 disk

└─sdb1            8:17   0    8G  0 part /DATA

sdc               8:32   0    8G  0 disk

sr0              11:0    1 1024M  0 rom

 

Unmount the disk

 

[root@zmpt01 ~]# umount /DATA/

 

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   16G  0 disk

sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   15G  0 part

  centos-root 253:0    0 13.4G  0 lvm  /

  └─centos-swap 253:1    0  1.6G  0 lvm  [SWAP]

sdb               8:16   0   16G  0 disk

└─sdb1            8:17   0    8G  0 part

sdc               8:32   0    8G  0 disk

sr0              11:0    1 1024M  0 rom

 

Reboot

 

[root@zmpt01 ~]# df –h

 

The file system is not mounted

 

FSTAB – File System Table

 

Configuration file helpful during boot for mounting disks

 

/etc/fstab

 

[root@zmpt01 ~]# vi /etc/fstab

 

Copy th existing line and paset into new line and edit as needed

 

Filesystem

Mount point

Filesystem type

OS handles this

priority

/dev/sdb1

/DATA                      

ext4

defaults

  0 0

 

[root@zmpt01 ~]# mount –a          < ---this command will read /etc/fstab and mounts the files if not already mounted

 

The file system will be mounted during boot up

 

***persistence with the reboot***

 

Changing the mount point

 

[root@zmpt01 DATA]# touch file{1..100}

 

 

/dev/sdb1                7.8G   36M  7.3G   1% /DATA   < ---Files are actually written to /dev/sdb1

 

[root@zmpt01 ~]# umount /DATA

[root@zmpt01 ~]# df –h

[root@zmpt01 ~]# cd /DATA/

[root@zmpt01 DATA]# ls

 

[root@zmpt01 ~]# mount /dev/sdb1 /IBM

[root@zmpt01 ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

devtmpfs                 484M     0  484M   0% /dev

tmpfs                    496M     0  496M   0% /dev/shm

tmpfs                    496M  6.8M  489M   2% /run

tmpfs                    496M     0  496M   0% /sys/fs/cgroup

/dev/mapper/centos-root   14G  1.8G   12G  14% /

/dev/sda1               1014M  136M  879M  14% /boot

tmpfs                    100M     0  100M   0% /run/user/0

/dev/sdb1                7.8G   36M  7.3G   1% /IBM         < ---mount point is changed to IBM, but data will still be available

 

[root@zmpt01 IBM]# ls

file1    file2   file30  file41  file52  file63  file74  file85  file96

 

UUID – Universal Unique Identifier

 

 

[root@zmpt01 ~]# blkid

 

/dev/sdb1: UUID="1dfbb3a5-8b04-4883-89e7-ceb9e78db6e4" TYPE="ext4"

 

[root@zmpt01 ~]# vi /etc/fstab

 

#/dev/sdb1 /DATA                       ext4     defaults        0 0

 

UUID=1dfbb3a5-8b04-4883-89e7-ceb9e78db6e4 /DATA                       ext4     defaults        0 0

 

[root@zmpt01 ~]# mount –a

 

[root@zmpt01 ~]# df –h

/dev/sdb1                7.8G   36M  7.3G   1% /DATA     < ---UUID is associated with /dev/sdb1

 

Mount using label

 

 

[root@zmpt01 ~]# e2label /dev/sdb1 zmpt01

 

[root@zmpt01 ~]# blkid

/dev/sda1: UUID="160e6caa-b0a9-468b-9de1-04189acc84ce" TYPE="xfs"

/dev/sda2: UUID="oLnQZF-bJU0-02T3-t0wF-DhnB-2JI6-CQI9f2" TYPE="LVM2_member"

/dev/sdb1: LABEL="zmpt01" UUID="1dfbb3a5-8b04-4883-89e7-ceb9e78db6e4" TYPE="ext4"

/dev/mapper/centos-root: UUID="5c79b16a-cfd4-4d5a-8e9c-b9b1a37b4936" TYPE="xfs"

/dev/mapper/centos-swap: UUID="c7801c38-9828-49b2-8a12-7610376d8b8a" TYPE="swap"

 

 

[root@zmpt01 ~]# vi /etc/fstab

 

LABEL="zmpt01" /DATA                       ext4     defaults        0 0       < ---using the LABEL

 

[root@zmpt01 ~]# mount -a

[root@zmpt01 ~]# df –h

/dev/sdb1                7.8G   36M  7.3G   1% /DATA                        < ---Mounted using LABEL

 

Multiple filesystem on same disk

 

 

 

/dev/sdb – 16GB

8GB

/dev/sdb1

Ext4

2GB

/dev/sdb2

XFS

2GB

/dev/sdb2

XFS

2GB

/de/sdb3

swap

 

 

[root@zmpt01 ~]# fdisk /dev/sdb

Command (m for help): m

Command (m for help):

 

p

Command (m for help): n

Select (default p): p

Partition number (2-4, default 2): 2

First sector (16779264-33554431, default 16779264):   < ---hit “Enter” – use default value

Last sector, +sectors or +size{K,M,G} (16779264-33554431, default 33554431): +2G

 

 

Command (m for help): p

 

Disk /dev/sdb: 17.2 GB, 17179869184 bytes, 33554432 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: 0x5460be06

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    16779263     8388608   83  Linux

/dev/sdb2        16779264    20973567     2097152   83  Linux     < ---New partition is created

 

Command (m for help): w

 

 

 

[root@zmpt01 ~]# lsblk

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0   16G  0 disk

sda1            8:1    0    1G  0 part /boot

└─sda2            8:2    0   15G  0 part

  centos-root 253:0    0 13.4G  0 lvm  /

  └─centos-swap 253:1    0  1.6G  0 lvm  [SWAP]

sdb               8:16   0   16G  0 disk

sdb1            8:17   0    8G  0 part /DATA

└─sdb2            8:18   0    2G  0 part                         < ---Newly created partition 2GB

sdc               8:32   0    8G  0 disk

 

 

[root@zmpt01 ~]# mkfs.xfs /dev/sdb2

 

 

 

[root@zmpt01 ~]# mount /dev/sdb2 /IBM/

 

 

 

[root@zmpt01 ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

devtmpfs                 484M     0  484M   0% /dev

tmpfs                    496M     0  496M   0% /dev/shm

tmpfs                    496M  6.8M  489M   2% /run

tmpfs                    496M     0  496M   0% /sys/fs/cgroup

/dev/mapper/centos-root   14G  1.8G   12G  14% /

/dev/sda1               1014M  136M  879M  14% /boot

tmpfs                    100M     0  100M   0% /run/user/0

/dev/sdb1                7.8G   36M  7.3G   1% /DATA

/dev/sdb2                2.0G   33M  2.0G   2% /IBM              < ---disk is mounted to /IBM

 

Make appropriate entry into /etc/fstab

 

/dev/sdb2 /IBM                       xfs     defaults        0 0

 

 

[root@zmpt01 ~]# mount –a

 

[root@zmpt01 ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

devtmpfs                 484M     0  484M   0% /dev

tmpfs                    496M     0  496M   0% /dev/shm

tmpfs                    496M  6.8M  489M   2% /run

tmpfs                    496M     0  496M   0% /sys/fs/cgroup

/dev/mapper/centos-root   14G  1.8G   12G  14% /

/dev/sda1               1014M  136M  879M  14% /boot

tmpfs                    100M     0  100M   0% /run/user/0

/dev/sdb1                7.8G   36M  7.3G   1% /DATA

/dev/sdb2                2.0G   33M  2.0G   2% /IBM              < ---disk is mounted to /IBM using mount -a

 

11-14-2020

https://youtu.be/AneCZr5-tLA

 

Extending inodes

 

To create random amount of blank files

 

touch file{1..110000}

 

 

[root@zmpt01 IBM]# df –h

 

/dev/sdb2                2.0G  582M  1.5G  29% /IBM

 

 

[root@zmpt01 IBM]# df –I    < ---this is used for checking the iNodes

 

/dev/sdb2               1048640 1048640       0  100% /IBM

 

 

Ext4 file system

 

[root@zmpt01 ~]# df -i /dev/sdb1

Filesystem     Inodes IUsed  IFree IUse% Mounted on

/dev/sdb1      524288   110 524178    1% /DATA

 

[root@zmpt01 ~]# umount /dev/sdb1

[root@zmpt01 ~]# mkfs.ext4 -N 1000000 /dev/sdb1       < ---ALL DATA will be deleted

 

[root@zmpt01 ~]# mount /dev/sdb1 /DATA/

[root@zmpt01 ~]# df -i

/dev/sdb1               1000448    11 1000437    1% /DATA

 

 

Increase the partition size

 

[root@zmpt01 ~]# df –h

/dev/sdb2                2.0G  582M  1.5G  29% /IBM   < --- Increase size of file system to 4GB

 

 

Unmount the partition that needs to be extended

 

[root@zmpt01 ~]# umount /IBM/

 

[root@zmpt01 ~]# fdisk /dev/sdb

Command (m for help): m

Command (m for help): d

Command (m for help): w

 

[root@zmpt01 ~]# fdisk /dev/sdb

Command (m for help): p

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): 2

First sector (16779264-33554431, default 16779264):

Using default value 16779264

Last sector, +sectors or +size{K,M,G} (16779264-33554431, default 33554431): +4G

Partition 2 of type Linux and of size 4 GiB is set

 

Command (m for help): p

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    16779263     8388608   83  Linux

/dev/sdb2        16779264    25167871     4194304   83  Linux

 

Command (m for help): w

 

[root@zmpt01 ~]# partprobe

 

[root@zmpt01 ~]# mount –a

 

[root@zmpt01 ~]# df –h

/dev/sdb2                2.0G  582M  1.5G  29% /IBM

 

[root@zmpt01 ~]# xfs_growfs /dev/sdb2

 

[root@zmpt01 IBM]# df –h

/dev/sdb2                4.0G  582M  3.5G  15% /IBM

 

Patititon Inforamtion

 

-          You can have maximum of four primary partitions on single disk

-          If you want to create more than four partitions

-          Then you need to create extended partion, then you can nest multiple partitions inside extended partition

 

 

 

 

SWAP

Swap is a space on a disk that is used when the amount of physical memory (RAM ) is full. When a lunux system runs out of RAM, inactive pages are moved from RAM to swap space. Swap space can take the form of either a dedicated swap partition or a swap file.

 

-          What is swap? Swap is standby memory

-          It’s a virtual memory used from hard drive

-          Real memory is 1GB

-          SWAP memory is 1.6 GB

-          Total useable size is 2.6 GB

-          If the real memory is full the swap is utilized

-          OS will mvoe inactive processes to the swap memory

-          Think of it as a safety net for Physical Memory.

 

 

[root@zmpt01 ~]# fdisk /dev/sdb

 

Command (m for help): p

 

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    16779263     8388608   83  Linux

/dev/sdb2        16779264    25167871     4194304   83  Linux

 

Command (m for help): m

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): 3

First sector (25167872-33554431, default 25167872):

Using default value 25167872

Last sector, +sectors or +size{K,M,G} (25167872-33554431, default 33554431): +2G

Partition 3 of type Linux and of size 2 GiB is set

 

Command (m for help): m

Command (m for help): t

Partition number (1-3, default 3): 3

Hex code (type L to list all codes): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'

 

Command (m for help): p

 

Disk /dev/sdb: 17.2 GB, 17179869184 bytes, 33554432 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: 0x5460be06

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    16779263     8388608   83  Linux

/dev/sdb2        16779264    25167871     4194304   83  Linux

/dev/sdb3        25167872    29362175     2097152   82  Linux swap / Solaris

 

Command (m for help): w

 

[root@zmpt01 ~]# partprobe

 

[root@zmpt01 ~]# mkswap /dev/sdb3   < ---creates the swap partition

 

 

[root@zmpt01 ~]# swapon /dev/sdb3  < ----make the swap useable

 

[root@zmpt01 ~]# vi /etc/fstab

 

/dev/sdb3 swap                    swap    defaults        0 0

 

[root@zmpt01 ~]# free -h

              total        used        free      shared  buff/cache   available

Mem:           991M        284M        345M        1.6M        360M        549M

Swap:          3.6G        279M        3.3G

 

 

 

[root@zmpt01 ~]# swapoff /dev/sdb3

 

[root@zmpt01 ~]# free -h

              total        used        free      shared  buff/cache   available

Mem:           991M        283M        347M        1.6M        360M        550M

Swap:          1.6G        278M        1.3G

 

[root@zmpt01 ~]# free -h

              total        used        free      shared  buff/cache   available

Mem:           991M        283M        347M        1.6M        360M        550M

Swap:          1.6G        278M        1.3G

 

[root@zmpt01 ~]# vi /etc/fstab

 

[root@zmpt01 ~]# swapon –a

 

[root@zmpt01 ~]# free -h

              total        used        free      shared  buff/cache   available

Mem:           991M        284M        345M        1.6M        360M        549M

Swap:          3.6G        278M        3.3G