0% found this document useful (0 votes)
4 views

Command Guide-2

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)
4 views

Command Guide-2

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
You are on page 1/ 7

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

View Disk Information

To view available free space of a disk

[[email protected]]# hwbrowser &

To view the free space in a partition

[[email protected]]# df –h

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

[[email protected]]# du –sh

To know the block size of a partition

[[email protected]]# blockdev –getbsz <partition>

Label

To assign label to a partition

[[email protected]]# e2label <partition> <label name>

To view the existing labels

[[email protected]]# e2label <partition>

To see a mounted partition with its label

[[email protected]]# mount –l

Swap Partition

Create a new Partition

[[email protected]]# fdisk <device>

Format the partition as swap

[[email protected]]# mkswap <partition>

Turn on Swap

[[email protected]]# swapon <partition>


Check the status of swap used

[[email protected]]# swapon –s <partition>

Turn off swap

[[email protected]]# swapoff <partition>

Mounting a Partition Permanently

To mount a partition Permanently

[[email protected]]# vl /etc/fstab

Mounting Removable Devices

To mount cdrom drive

[[email protected]]# mount /dev/cdrom mnt

To mount a pen drive

[[email protected]]# 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

[[email protected]]# fdisk <device>

Update the partition table

[[email protected]]# partprobe <device>

Physical Volume

Create a physical volume from the previously created partitions


[[email protected]]# pvcreate <partition1> <partition2> <partition3>

To see the physical volume details

[[email protected]]# pvdisplay |less

Volume Group

Create a volume group

[[email protected]]# vgcreate <volume group name> <physical volume 1> <physical


volume 2>

To see the volume group details

[[email protected]]# vgdisplay <volume group name>

Logical volume

Create logical volume

[[email protected]]# lvcreate –L <size> <volume group name> -n <volume name>

Format the logical volume

[[email protected]]# mkfs.ext3 < volume name>

Create a mount point

[[email protected]]# mkdir <directory name>

Mounting a logical volume

[[email protected]]# mount <volume name > <mount point>

Re-sizing a logical volume

[[email protected]]# lvresize –L <+sizeM> <logical volume name>

To update the re-sized logical volume

[[email protected]]# resize2fs <logical volume name>

Removing logical volume

[[email protected]]# lvremove <logical volume name>


Extending the size of a volume group

[[email protected]]#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 > print.sh


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