You are on page 1of 103

CentOS 7 Partition Management with fdisk Utility

File System
In computer system, a File System defines how data or information is stored and retrieved from a storage disk.
In Windows Operating System, the popular file systems are FAT32 and NTFS. On the other hand in Linux
Operating System, the popular file systems are ext2, ext3, ext4, xfs (current), vfat, swap, ZFS and GlusterFS.

The MBR holds the information about how the logical partitions that contains file systems are organized on the
disk.

In Linux Operating System the MBR can have maximum 15 partitions and among them 4 partitions are primary
and the rest are logical partitions.

On the other hand in the Windows Operating System, the MBR can have maximum 24 partitions where 4 are primary and
the rest are logical.

GUID Partition Table (GPT)


As we can see MBR has limitation on both partitions (4 primary partitions) and storage capacity (2TB), a new partition
table named GPT (Globally Unique Identifiers Partition Table) has been introduced (a part of the Unified Extensible
Firmware Interface (UEFI) ) that can have 128 partitions. The GPT uses 64 bit for logical block address and for disks with
512-byte sectors, maximum size is 9.4 ZB (9.4 × 1021 bytes) or 8 ZiB.
[root@localhost ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdc

[root@localhost ~]# lsblk


NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4.7G 0 part /boot
└─sda2 8:2 0 38.2G 0 part
├─centos-root 253:0 0 28G 0 lvm /
├─centos-swap 253:1 0 5.6G 0 lvm [SWAP]
└─centos-home 253:2 0 4.7G 0 lvm /home
sdb 8:16 0 20G 0 disk
sdc 8:32 0 20G 0 disk
sr0 11:0 1 4.4G 0 rom /run/media/root/CentOS 7 x86_64
Output we can see there are three disk drives (sda, sdb and sdc) and their present status is like the below description.
/dev/sda: It is the first SATA/SCSI disk where CentOS 7 is installed and has three partitions. /dev/sda1 is using as /boot
partion, /dev/sda2 is swap partition and /dev/sda3 is the root partition.
/dev/sdb:It is a raw SATA/SCSI disk drive.
/dev/sdc: It is a USB flash drive and has a partition /dev/sdc1 and its partition is informing that it is a NTFS formatted disk.
Linux normally cannot handle NTFS drive unlike FAT32. To play with NTFS drive in CentOS, you have to use NTFS3G utility.
File System Partition ID
NTFS 7
ext3/ext4/xfs 83
swap 82
LVM 8e
vfat f
RAID fd
Crating 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 0x8fded5d4.

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): 1
First sector (2048-41943039, default 2048): --------
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1000M
Partition 1 of type Linux and of size 1000 MiB is set
Command (m for help): w
The partition table has been altered!
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4.7G 0 part /boot
└─sda2 8:2 0 38.2G 0 part
├─centos-root 253:0 0 28G 0 lvm /
├─centos-swap 253:1 0 5.6G 0 lvm [SWAP]
└─centos-home 253:2 0 4.7G 0 lvm /home
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 1000M 0 part
sdc 8:32 0 20G 0 disk
sr0 11:0 1 4.4G 0 rom /run/media/root/CentOS 7 x86_64

[root@localhost ~]# fdisk -l


Device Boot Start End Blocks Id System
/dev/sdb1 2048 2050047 1024000 83 Linux

Mounting partition
[root@localhost ~]# mkfs.ext4 /dev/sdb1
[root@localhost ~]# mkdir /test/1
[root@localhost ~]# mount /dev/sdb1 /test/1/
[root@localhost ~]# lsblk
At this stage, our mounted partitions are temporary. If our Operating System gets restarted, these mounted
directory will be lost. So, we need to do permanent mount. To do permanent mount, we have to put entry in fstab
file. You can see current fstab entry with the following command.
RPM (Red Hat Package Manager

 is an default open source and most popular package management utility for Red Hat based systems like
(RHEL, CentOS and Fedora). The tool allows system administrators and users to install, update, uninstall, query, verify and
manage system software packages in Unix/Linux operating systems. The RPM formerly known as .rpm file, that includes
compiled software programs and libraries needed by the packages. This utility only works with packages that built
on .rpm format

RPM is free and released under GPL (General Public License).


RPM keeps the information of all the installed packages under /var/lib/rpm database.
RPM is the only way to install packages under Linux systems, if you’ve installed packages using source code, then rpm won’t
manage it.
RPM deals with .rpm files, which contains the actual information about the packages such as: what it is,

There are five basic modes for RPM command


Install : It is used to install any RPM package.
Remove : It is used to erase, remove or un-install any RPM package.
Upgrade : It is used to update the existing RPM package.
Verify : It is used to verify an RPM packages.
Query : It is used query any RPM package.
[root@tecmint]# rpm --checksig pidgin-2.7.9-5.el6.2.i686.rpm
[root@tecmint]# rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm

Preparing... ########################################### [100%]


1:pidgin ########################################### [100%]

-i : install a package


-v : verbose for a nicer display
-h: print hash marks as the package archive is unpacked.

check dependencies of RPM Package before Installing


[root@tecmint]# rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm

-q : Query a package


-p : List capabilities this package provides.
-R: List capabilities on which this package depends..

Install a RPM Package Without Dependencies


[root@tecmint]# rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm
Preparing... ########################################### [100%]
1:BitTorrent ########################################### [100%]
[root@tecmint]# rpm -q BitTorrent
BitTorrent-5.2.2-1.noarch

List all files of an installed RPM package


[root@tecmint]# rpm -ql BitTorrent

 List Recently Installed RPM Packages


[root@tecmint]# rpm -qa –last

List All Installed RPM Packages


[root@tecmint]# rpm -ql BitTorrent

List Recently Installed RPM Packages


[root@tecmint]# rpm -qa –last

List All Installed RPM Packages


[root@tecmint]# rpm –qa

Upgrade a RPM Package


[root@tecmint]# rpm -Uvh nx-3.5.0-2.el6.centos.i686.rpm

Remove a RPM Package


[root@tecmint]# rpm -evv nx
Remove an RPM Package Without Dependencies
[root@tecmint]# rpm -ev --nodeps vsftpd

Query a file that belongs which RPM Package


[root@tecmint]# rpm -qf /usr/bin/htpasswd

Query a Information of Installed RPM Package


[root@tecmint]# rpm -qi vsftpd

Verify a RPM Package


[root@tecmint downloads]# rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm

Verify all RPM Packages


[root@tecmint]# rpm –Va

Import an RPM GPG key


[root@tecmint]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

List all Imported RPM GPG keys


[root@tecmint]# rpm -qa gpg-pubkey*

rebuild Corrupted RPM Database


[root@tecmint]# cd /var/lib
# rpm -e --erase (remove, delete, expunge)

Network management / changing ip address using command and gui

# ip a

# nmcli -p dev

# systemctl restart network

# ip a s eth0

# nmtui edit eth0

Ifconfig

Ifconfig | grep inet

Ip addr
Introduction
In Linux, a repository is a central database of software. Linux distributions have a central repository for system and
commonly-used software.

Yum is a local repository for RPM package files. These packages compress available software for Linux distributions. With the
repository, you can download, install and hold packages on a local disk or remotely.

Prerequisites
Access to a user account with root or sudo privileges
Access to a terminal window/command-line (Menu > Applications > Utilities > Terminal)
The YUM (Yellowdog Updater Modified) package manager, installed by default
[root@localhost ~]# getenforce ------ to check firewall is activate
Enforcing
[root@localhost ~]# setenforce 0 -------- to disable firewall for temporary
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]#

[root@localhost ~]# rpm -q creterepo vsftpd deltarpm python-deltarpm ------ to check default installed packages
package creterepo is not installed
vsftpd-3.0.2-28.el7.x86_64
deltarpm-3.6-3.el7.x86_64
python-deltarpm-3.6-3.el7.x86_64
[root@localhost ~]#

[root@localhost ~]# mkdir /var/ftp/pub/yumserver

[root@localhost ~]# cp -var /run/media/root/CentOS\ 7\ x86_64/Packages/* /var/ftp/pub/yumserver/

You might also like