Tuesday, July 14, 2020

how to make a Disk partition in Linux

How To Make A Partition

Creating and deleting partitions in Linux is a regular practice because storage devices (such as hard drives and USB drives) must be structured in some way before they can be used. In most cases, large storage devices are divided into separate sections called partitions. Partitioning also allows you to divide your hard drive into isolated sections, where each section behaves as its own hard drive. Partitioning is particularly useful if you run multiple operating systems.
 
In this tutorial we will attach a new storage device and than will create a new partition.
after that will create a filesystem of respected partition and than will make a mount point with desired location. 

Commands Overview

1) df -h        (Show Mounted point with filesystem)
 
2) lsblk        (Show Mounted point with filesystem in tree format)
 
3) sudo blkid   (Show available partition with and without created filesystem)

4) fdisk        (Show available storage devices)


Add/Attach new Hard-Disk.

  • fdisk -l    (use to view storage drive and also partition's)


# sudo fdisk -l



Create partition of new drive /dev/sdb

# sudo fdisk /dev/sdb



FDISK mange command 
  • m  (for show command help)
  • p   (for view partition table)
  • n   (for create mew partion)
  • d   (for delete partition)
  • w  (for save all the activity)

Create New Partition

Command (m for help):  n



Select (default p):  p


Partition number (3,4, default 3): 3


First sector (press enter for default value of  sector)


Last Sector (select number and add G, M, K) Ex: +5G



Command (m for help):  p
  • view your new partition, which you have created.



Command (m for help):  w
  • press w for save the partition.
  • after creating partition use partprobe and kpartx and also you can do rebbot the machine.

After Rebooting The Machine 

# sudo blkid 
  • show all hard-disk partition block.
  • and also show new created partition /dev/sdb3

Now create File System of newer partition.

# sudo mkfs.ext4  /dev/sdb3


# sudo blkid

  • check again /dev/sdb3 

Now mount the partition in the particular directory.

# sudo mount  /dev/sdb3 /tech2towards


  • above command will temporary mount the directory on the partition.
  • after reboot the server mounted directory will remove.
  • add permanent mount  point entry of directory in /etc/fstab file.


Add Permanent mount point entry in /etc/fstab  file.

# sudo blkid


  • copy below snap yellow marked line without comma(") from /dev/sdb3
  • copy line will use in fstab entry.

# sudo nano /etc/fstab
  • entry at the bottom of file, see below syntax.
  • UUID=("paste uuid number without comma" )  /tech2towards ext4 defaults 0 0
  • save the file Ctrl+x 
  • press y and enter

Now, Reboot the Machine, after reboot your mount point will added.

# df -h 





No comments:

Post a Comment

testing