There are many powerful tools available to do partition in Linux. Deleting and partitioning a storage device is very important because in large storage devices you need to manage different section with separate storage space. Partitioning is also very useful if you are using multiple operating systems (multiple operating systems means running Linux and windows on the same system).
Already mentioned there are different tools in Linux to do partition but in this page, I will use parted command for partitioning
Install Parted command
In most of the Linux operating systems, this command will already installed. But if in any case you do not have parted command installed by default you can install it. Follow the process below:
- Open terminal application in your Linux OS
- Run the following commands
$ sudo apt-get update
$ sudo apt-get install parted
- If you are using CentOs or fedora then use the following command
$ sudo yum install parted
Select the partitioning standard
There are partitioning standards GPT and MBR. GPT is more modern and widely used partitioning standard, while MBR is giving wider support among operating systems. If we do not have some special needs then we simply use GPT.
To choose GPT to run the following command.
$ sudo parted /dev/sda mklabel gpt
To choose MBR to run the following command
$ sudo parted /dev/sda mklabel mbr msdos
Create a new partition
When you have selected the partitioning format then you can create a partition. Run the following command to create new partition.
$ sudo parted -a opt /dev/sda mkpart primary ext4 0% 100%
We can check new partition created by running the following command
$ sudo lsblk
Create a filesystem on a new partition
Now we have created a new partition we can pass it filesystem by using mkfs.ext4 utility.
$ sudo mkfs.ext4 -L datapartition /dev/sda1
Once you have created a filesystem on new partition you have to mount this filesystem. It makes no recommendations on where to mount more permanent storage, so you can choose whichever scheme you would like. For this tutorial we will mount under /mnt/data.
Create the directory to mount the partition by running the following command
$ sudo mkdir -p /mnt/data
There are two ways to mount the partition temporary mount and mount the partition automatically at boot.
Mount the partition temporarily by typing the following command
$ sudo mount -o defaults /dev/sda1 /mnt/data
If you want that filesystem should mount each time system boots you can use the following command.
$ sudo nano /etc/fstab
Now save and close the file when you are finished. In this tutorial, we have learned how to create partition, format and mount the filesystem.
How do I partition a hard drive in Ubuntu?
How partitions are created in Linux?
How do I manually create a Linux partition?
What are different kinds of partitions available in Linux?
- data partition: normal Linux system data, including the root partition containing all the data to start up and run the system; and.
- swap partition: expansion of the computer’s physical memory, extra memory on hard disk.
What are three types of partitions?
How many partitions are required for Linux?
How can I see all partitions in Linux?
The ‘-l’ argument stand for (listing all partitions) is used with fdisk command to view all available partitions on Linux. The partitions are displayed by their device’s names. For example: /dev/sda, /dev/sdb or /dev/sdc.
How do I see drives in Linux?
- df. The df command in Linux is probably one of the most commonly used.
- fdisk. fdisk is another common option among sysops.
- lsblk. This one is a little more sophisticated but gets the job done as it lists all block devices.
How do I view partitions?
How do I list all devices in Linux?
- ls: List files in the file system.
- lsblk: List block devices (for example, the drives).
- lspci: List PCI devices.
- lsusb: List USB devices.
- lsdev: List all devices.
How do I list all USB devices in Linux?
- $ lsusb.
- $ dmesg.
- $ dmesg | less.
- $ usb–devices.
- $ lsblk.
- $ sudo blkid.
- $ sudo fdisk -l.
What are devices in Linux?
How do I find memory in Linux?
- Open the command line.
- Type the following command: grep MemTotal /proc/meminfo.
- You should see something similar to the following as output: MemTotal: 4194304 kB.
- This is your total available memory.
How do I increase memory on Linux?
How do I find hard drive size in Linux?
- Task: Display Hard Disk Partition Size. Open a command-line terminal (select Applications > Accessories > Terminal), and then type:
- Task: Display Hard Disk Partition Size in Mega bytes or GB or TB. Type the following command:
- Task: Display TOTAL Hard Disk Size.