Disk managment in linux
[root@localhost ~]# #to view the hdd#
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 9.3G 0 part /boot
└─sda2 8:2 0 19.6G 0 part
├─cl-root 253:0 0 13G 0 lvm /
└─cl-swap 253:1 0 6.5G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
* To add the hdd
after adding physically
Restart
[root@localhost ~]# init 6
Then
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 9.3G 0 part /boot
└─sda2 8:2 0 19.6G 0 part
├─cl-root 253:0 0 13G 0 lvm /
└─cl-swap 253:1 0 6.5G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# #to see the details of the hdd#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# fdisk -l
[root@localhost ~]# #to make the primary partion#
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 9.3G 0 part /boot
└─sda2 8:2 0 19.6G 0 part
├─cl-root 253:0 0 13G 0 lvm /
└─cl-swap 253:1 0 6.5G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
sr0 11:0 1 1024M 0 rom
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xf1f81007.
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599): +10G
Created a new partition 1 of type 'Linux' and of size 10 GiB.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (20973568-104857599, default 20973568):
Last sector, +sectors or +size{K,M,G,T,P} (20973568-104857599, default 104857599):
+20G
Created a new partition 2 of type 'Linux' and of size 20 GiB.
Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (62916608-104857599, default 62916608):
Last sector, +sectors or +size{K,M,G,T,P} (62916608-104857599, default 104857599):
+10G
Created a new partition 3 of type 'Linux' and of size 10 GiB.
Command (m for help):
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# #to view the partion#
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 9.3G 0 part /boot
└─sda2 8:2 0 19.6G 0 part
├─cl-root 253:0 0 13G 0 lvm /
└─cl-swap 253:1 0 6.5G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
├─sdb1 8:17 0 10G 0 part
├─sdb2 8:18 0 20G 0 part
└─sdb3 8:19 0 10G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 9.3G 0 part /boot
└─sda2 8:2 0 19.6G 0 part
├─cl-root 253:0 0 13G 0 lvm /
└─cl-swap 253:1 0 6.5G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
├─sdb1 8:17 0 10G 0 part
├─sdb2 8:18 0 20G 0 part
└─sdb3 8:19 0 10G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]#
[root@localhost ~]# mkfs.ext4 /dev/sdb2
Mount Point - By default we can not access the hdd directly in linux system. For
this case we have to create a folder and
link it to the partion. This process is called mounting .
The Folder is called the mount point of the hdd.
[root@localhost ~]#
[root@localhost ~]# #how to use the partion#
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 9.3G 0 part /boot
└─sda2 8:2 0 19.6G 0 part
├─cl-root 253:0 0 13G 0 lvm /
└─cl-swap 253:1 0 6.5G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
├─sdb1 8:17 0 10G 0 part
├─sdb2 8:18 0 20G 0 part
└─sdb3 8:19 0 10G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]#
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd /root/Desktop/
[root@localhost Desktop]#
[root@localhost Desktop]# mkdir AWS-Sunday-Mount
[root@localhost Desktop]#
[root@localhost Desktop]#
[root@localhost Desktop]# #mount the /dev/sdb2 to /root/Desktop/AWS-Sunday-Mount/#
[root@localhost Desktop]#
[root@localhost Desktop]#
[root@localhost Desktop]# mount /dev/sdb2 /root/Desktop/AWS-Sunday-Mount/
[root@localhost Desktop]#
[root@localhost Desktop]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 867M 0 867M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 9.5M 886M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 14G 4.6G 8.6G 35% /
/dev/sda1 xfs 9.4G 382M 9.0G 5% /boot
tmpfs tmpfs 180M 4.6M 175M 3% /run/user/0
/dev/sdb2 ext4 20G 45M 19G 1% /root/Desktop/AWS-Sunday-Mount
[root@localhost Desktop]#
[root@localhost Desktop]# #to copy some data in this hdd#
[root@localhost Desktop]#
[root@localhost Desktop]#
[root@localhost Desktop]# cp -rv /etc/* /root/Desktop/AWS-Sunday-Mount/
[root@localhost Desktop]# # to unmont the disk#
[root@localhost Desktop]#
[root@localhost Desktop]# umount /root/Desktop/AWS-Sunday-Mount
[root@localhost Desktop]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 867M 0 867M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 9.5M 886M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 14G 4.6G 8.6G 35% /
/dev/sda1 xfs 9.4G 382M 9.0G 5% /boot
tmpfs tmpfs 180M 4.6M 175M 3% /run/user/0
[root@localhost Desktop]#