Creating new partition linux

How to Create a New Disk Partition in Linux

Storage devices such as a hard disk or USB drives need to structured before start using it. Partitioning is the process of slicing the disk into one more separate region called a partition. Most importantly a partition is required to install an operating system. The second common reason is that you can install multiple operating systems.

It is basically the first step for a newly installed disk. After creating a partition, the partition is formatted with a file system.

In this tutorial, I will go through steps to create a new partition on Linux distribution such as CentOS, Ubuntu, RHEL, and Debian.

1) List the partitions in Linux

To list the existing partition or block devices on your system you can use parted -l or fdisk -l or lsblk command. From this list, you can identify which disk you like to partition. The disk which is attached from storage devices (SANS) is normally visible in cat /proc/scsi/scsi or /proc/partitions file.

You can see unrecognized disk label error which indicates the new and unpartitioned disk.

We have two disks attached our system, first disk /dev/xvda have the Operating system installed and the second is /dev/xvdb .

2) Disk partitioning in Linux

In the section, we’ll create a single partition using the entire disk. Fdisk and parted are two tools used in Linux to create a disk partition. For creating partitions greater than 2 TB is not supported by fdisk.

Here, we will check how to create a partition using parted tool.

Set a partition type

The most common two partition types are MBR (msdos) and GPT. GPT uses more modern standard and MBR is supported across many operating systems.

If you don’t have a special requirement, then you can opt for GPT standard.

Instead of a one-liner command, you can also run parted command in an interactive way. In the example, I am changing disk label to msdos which is MBR format.

For MBR type, run the following command:

Creating a new partition

Even though the space for the new partition has been allocated and written to disk you still need to create a filesystem on that newly available space, so the next step is formatting the partition with the required filesystem.

If you check lsblk , can see a new partition /dev/xvdb1 listed:

Note: Parted defaults to ‘1000 kilobytes = 1 megabyte’ and not ‘1024 kilobytes = 1 megabyte’.

If you run parted command again to list partition, you no longer see any error:

Читайте также:  Windows anti virus protection

To slice the whole disk into multiple partitions, run mkpart specifying the size you want as follows:

You can add more partitions based on your requirement as shown below:

So we have created two primary partitions which are named shows as xvdb1 and xvdb2 .

Note: For the MBR scheme you have a limit of 4 primary partitions but in GPT there are no such limits.

You may also use the following parted command to list partitions information on the disk.

Note: Type quit to exit out from parted prompt and whatever changes made will be saved.

3) Create a filesystem

Linux supports different filesystem type such as Ext2, Ext3, Ext4, BtrFS, and GlusterFS. In the previous section, we have created two new partitions and now we can format it as an Ext4 filesystem.

Linux has an inbuilt utility called mkfs.ext4 , which can format a partition to Ext4 filesystem.

You can use -L option to set a partition label while formatting the partition.

Use e2label command to change the partition label as follows:

To print all partition table information such as Name, FSTYPE, LABEL, UUID and MOUNTPOINT use lsblk —fs .

4) Mount Filesystem

Finally, we are now going to mount the filesystem that enables to write data to mount point.

The following command will temporarily mount the filesystem:

It’s important to make sure that /etc/fstab file is updated to have newly created partitions get mounted automatically at boot time.

The fstab file should have any entry as follows:

Note: SCSI devices are identified as ‘sd’ and the letter immediately after ‘sd’ signifies the order in which it was first found. For example, sda1 means the first partition on the first drive. For explaining I have used Xen virtual disk which show devices as ‘/dev/xvd’.

To verify the filesystem is available use df command to list mounted partition and see its size.

Conclusion

In this tutorial, we learned how to partition, format, and mount a raw hard drive attached to the Linux system.

If you have any questions or feedback, feel free to leave a comment.

Источник

How to Create a Disk Partitions in Linux

In order to effectively use storage devices such as hard drives and USB drives on your computer, you need to understand and know how to structure them before using in Linux. In most cases, big storage devices are split into separate portions called partitions.

Partitioning enables you to split your hard drive into multiple parts, where each part acts as its own hard drive and this is useful when you are installing multiple operating systems in the same machine.

In this article, we will explain how to partition a storage disk in Linux systems such as CentOS, RHEL, Fedora, Debian and Ubuntu distributions.

Creating a Disk Partition in Linux

In this section, we will explain how to partition a storage disk in Linux using the parted command.

The first step is to view the partition table or layout on all block devices. This helps you identify the storage device you want to partition. You can do this using parted or fdisk command. We will use the former for purposes of demonstration, as follows, where the -l flag means list partition layout on all block devices.

Читайте также:  Как активировать помощника windows

List Partitions in Linux

From the output of the above command, there are two hard disks attached to the test system, the first is /dev/sda and the second is /dev/sdb .

In this case, we want to partition hard disk /dev/sdb . To manipulate disk partitions, open the hard disk to start working on it, as shown.

At the parted prompt, make a partition table by running mklabel msdos or gpt, then enter Y/es to accept it.

Make Disk Label

Important: Make sure to specify the correct device for partition in the command. If you run parted command without a partition device name, it will randomly pick a storage device to modify.

Next, create a new primary partition on the hard disk and print the partition table as shown.

Create Partition in Linux

You can create another partition for the reaming space as shown.

Create Another Partition

To quit, issue the quit command and all changes are automatically saved.

Next, create the file system type on each partition, you can use the mkfs utility (replace ext4 with the file system type you wish to use).

Create Filesystem Type on Partition

Last but not least, to access the storage space on the partitions, you need to mount them by creating the mount points and mount the partitions as follows.

To check if the partitions are actually mounted, run the df command to report file system disk space usage.

Check Partitions Disk Space Usage

Important: You may need to update /etc/fstab file to mount newly created partitions automatically at boot time.

You might also like to read these following related articles:

That’s all! In this article, we have shown how to partition a storage disk, create a file system type on a partition and mount it in Linux systems. You can ask questions or share you thoughts with us via the comment form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How to Create a New Ext4 File System (Partition) in Linux

The ext4 or fourth extended filesystem is a widely-used journaling file system for Linux. It was designed as a progressive revision of the ext3 file system and overcomes a number of limitations in ext3.

It has significant advantages over its predecessor such as improved design, better performance, reliability, and new features. Although it is best suited for hard drives, it can also be used on removable devices.

Читайте также:  Почему пишет не удалось настроить обновления windows

This article will show you how to create a new ext4 file system (partition) in Linux. We will first of all look at how to create a new partition in Linux, format it with the ext4 file system and mount it.

Note: For the purpose of this article:

  • We will assume that you have added a new hard drive to your Linux machine, in which you will create the new ext4 partition, and
  • If you are operating the system as an administrative user, use the sudo command to gain root privileges to run the commands shown in this article.

Creating a New Partition in Linux

List the partitions using the fdisk -l or parted -l commands to identify the hard drive you want to partition.

List Linux Partitions

Looking at the output in the screenshot above, we have two hard disks added on the test system and we will partition disk /dev/sdb .

Now use parted command to start creating the partition on the selected storage device.

Then create a partition using the mkpart command, give it additional parameters like “primary” or “logical” depending on the partition type that you wish to create. Then select ext4 as the file system type, set the start and end to establish the size of the partition:

Create a New Ext4 Partition

To print the partition table on the device /dev/sdb or detailed information about the new partition, run the print command.

Print Partition Table

Now exit the program using the quit command.

Formatting New Ext4 Partition

Next, you need to properly format the new partition with the ext4 file system type using the mkfs.ext4 or mke4fs command as follows.

Format a New Ext4 Partition

Then label the partition using the e4label command as follows.

Mounting New Ext4 Parition in File System

Next, create a mount point and mount the newly created ext4 partition file system.

Now using the df command, you can list all file systems on your system together with their sizes in a human readable format (-h) , and their mount points and file system types (-T) :

Show Linux Filesystem with Mount Points

Lastly, add the following entry in your /etc/fstab to enable persistent mounting of the file system, even after a reboot.

You might also like to read these following related articles:

That’s all! In this article, we’ve explained how to create a new partition in Linux, format it with ext4 file system type and mount it as a filesystem. For more information or to share any queries with us, use the feedback form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Оцените статью