0% found this document useful (0 votes)
11 views7 pages

CentOS/RHEL Disk Partitioning Guide

Uploaded by

yarzarayeko970
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

CentOS/RHEL Disk Partitioning Guide

Uploaded by

yarzarayeko970
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Linux Basic and Advanced Disc Partitioning for CentOS / RHEL 7/6

View Disk Information

To view available free space of a disk

[root@[Link]]# hwbrowser &

To view the free space in a partition

[root@[Link]]# df –h

To view the total amount of used space in a partition / directory

[root@[Link]]# du –sh

To know the block size of a partition

[root@[Link]]# blockdev –getbsz <partition>

Label

To assign label to a partition

[root@[Link]]# e2label <partition> <label name>

To view the existing labels

[root@[Link]]# e2label <partition>

To see a mounted partition with its label

[root@[Link]]# mount –l

Swap Partition

Create a new Partition

[root@[Link]]# fdisk <device>

Format the partition as swap

[root@[Link]]# mkswap <partition>

Turn on Swap

[root@[Link]]# swapon <partition>


Check the status of swap used

[root@[Link]]# swapon –s <partition>

Turn off swap

[root@[Link]]# swapoff <partition>

Mounting a Partition Permanently

To mount a partition Permanently

[root@[Link]]# vl /etc/fstab

Mounting Removable Devices

To mount cdrom drive

[root@[Link]]# mount /dev/cdrom mnt

To mount a pen drive

[root@[Link]]# mount /dev sda1 /mnt

What is Logical Volume Manager (LVM)?

 LVM is a method of allocating hard drive space into logical volumes that can be easily
resized.
 With LVM, the hard drive or set of hard drives is allocated to one or more physical
volumes.
 The physical volumes are then combined into volumes groups.
 Each volumes group is divided into logical volumes, which are formatted with a file
system like ext3 and are then mounted.

Creating Partitions

Make Multiple Partitions

[root@[Link]]# fdisk <device>

Update the partition table

[root@[Link]]# partprobe <device>

Physical Volume

Create a physical volume from the previously created partitions


[root@[Link]]# pvcreate <partition1> <partition2> <partition3>

To see the physical volume details

[root@[Link]]# pvdisplay |less

Volume Group

Create a volume group

[root@[Link]]# vgcreate <volume group name> <physical volume 1> <physical


volume 2>

To see the volume group details

[root@[Link]]# vgdisplay <volume group name>

Logical volume

Create logical volume

[root@[Link]]# lvcreate –L <size> <volume group name> -n <volume name>

Format the logical volume

[root@[Link]]# mkfs.ext3 < volume name>

Create a mount point

[root@[Link]]# mkdir <directory name>

Mounting a logical volume

[root@[Link]]# mount <volume name > <mount point>

Re-sizing a logical volume

[root@[Link]]# lvresize –L <+sizeM> <logical volume name>

To update the re-sized logical volume

[root@[Link]]# resize2fs <logical volume name>

Removing logical volume

[root@[Link]]# lvremove <logical volume name>


Extending the size of a volume group

[root@[Link]]#vgextend <volume group name ><physical volume name>

Create MS-DOS Disk Linux Partition


------------------------------------
Display Linux Partition Table
#fdisk -l /dev/sdb

#parted /dev/sdb

or

#parted
(parted)select /dev/sdb

(parted)mklabel gpt or msdos

(parted)unit GB or TB

(parted)rm number (Remove Partition)

(parted)mkpart primary 0.00GB 5.00GB

(parted)print

(parted)quit

#mkfs.ext4 /dev/sdb1
#mkdir /mydisk
#mount /dev/sdb1 /mydisk
-----------------------------------------------------------------------------------------
Create GPT Disk Linux Partition
#fdisk -l /dev/sdb

#parted /dev/sdb

or

#parted
(parted)select /dev/sdb
(parted)mklabel gpt
(parted)unit TB
(parted)mkpart primary 0.00TB 3.00TB
(parted)print
(parted)quit
#mkfs.ext4 /dev/sdb1
#mkdir /mydisk
#mount /dev/sdb1 /mydisk
------------------------------------------------------------------------------------------
Create LVM Partition
#fdisk /dev/sdb
>n
type: p
start: Enter
end: Enter
>p
>t
type:8e
>p
>w

#fdisk /dev/sdc
>n
type: p
start: Enter
end: Enter
>p
>t
type:8e
>p
>w

#pvcreate /dev/sdb1 /dev/sdc1


#pvdisplay
#pvscan

#vgcreate VolGroup00 /dev/sdb1 /dev/sdc1


#vgdisplay
#vgscan

#lvcreate -L 20G -n HDD01 VolGroup00


#lvscan
#lvdisplay

#lvmdiskscan
#lvextend -L100G /dev/VolGroup00/HDD01 ==> Resize to 100GB Logical Volume
#lvextend -L+100G /dev/VolGroup00/HDD01 ==> Increase to 200GB Logical Volume

#pvcreate /dev/sdd1
#vgextend VolGroup00 /dev/sdd1

#xfs_growfs /dev/VolGroup00/HDD02 (For XFS Filesystem)


#resize2fs /dev/VolGroup00/HDD01 (For ext2,ext3,ext4)

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

#echo “Hello World”


#echo “Today is `date`”
#echo –e “Hello\tWorld”
#echo –e “Hello\nWorld”

#os=RedHat
#ver=7

#echo $os $ver


#echo ${os} ${ver}

#echo –e “$os\t$ver”
#echo –e “$os\n$ver”

#cat <<EOF > [Link]


echo hello world
echo hello world
echo “Today is `date`”
EOF

#read os
Redhat

#read ver
7

#echo $os $ver

#hello()
>{
>echo “Hello World”
>echo “Today is `date`”
>}

Function command syntax:

hello()
{
echo “Hello World”
echo “Today is `date”
}

IF Condition command syntax:

if [ condition ]; then
command
command
fi

if [ condition ]; then
command
command
else
command
command
fi

IF Condition command example-01:

if [ $UID -ne 0 ]; then


echo Non root user. Please run as root.
else
echo Root user
fi

You might also like