Creating and Resizing XFS Partitions

Chưa phân loại
Making partitions and resizing them can help you maintain the simplicity and cleanliness of your installation and disk arrangements. In this article, we will be using VirtualBox to demonstrate how to create a proper partition and format it with XFS filesystem. We will also be mentioning some standard practices that are necessary for the bare metal systems, but optional for virtual ones.

Understanding the disk layout

If you have a new disk attached to your system, or to your VM, a handy command to list all the attached block storage command is quite helpful. The following command lists all the block storage devices attached to the system. This includes raw disks, primary partitions, logical partitions and even network attached storage.


Here, we have attached a new 1TB disk which shows up as device sdb. The sda device above it is where the operating system is installed and you can see that it has a root partition and a swap partition.

The second disk, however, has no partitions and is not formatted with a filesystem. From here on, you can do two things:

  1. Use the entire disk and install the filesystem on top of it.
    This is as simple as running:

    $mkfs.xfs /dev/sdb
  2. Or, you can partition it into more manageable chunks for which we need to use the parted utility. We will be following this procedure.

Partitioning the disk

To start partitioning the disk, you can either use gparted which is a graphical utility. Nevertheless, let’s use the universal command-line interface so that it works across platforms in the same way.

First thing to understand here is that the disk can be interfaced with a special file, known as the device node, which will be used to refer the actual disk. In our case the device node is sdb and its full path is /dev/sbd, it might be under a different name in your case. This file points to the physical device, but it would not actually contain the data that is stored in the disk. That information will show up in the directory where you mount the device (more on that later).

To get started with partitioning, enter:

$parted -a optimal /dev/sdb

This would start the parted command-line utility with our new disk in focus.

Typing print would list all the various partitions on the disk, but since there are none, we will see an error message.

Now let’s add a gpt label (along with a gpt table) to the disk.

(parted) mklabel gpt

This will give your disk (and its partitions) a globally unique ID which is really crucial if you are going to plug the disk out and insert it via a different physical port. Having a globally unique ID removes that explicit dependence on the port number that most operating systems rely on when identifying resources.

Having labeled the disk, you are ready to create the first partition on it.

(parted)unit GB
(parted)mkpart primary 0 200

The first command sets the units in GB which is more convenient and the second command creates a primary partition from the start of the disk (except a small reserved memory in the beginning) till the 200th Gigabyte. Let us verify this.


Now you can exit the parted utility by entering quit. And we can see that the layout for block devices have a new member.


A partition has emerged as sdb1 from the sdb disk and it has its own device node and it is ready to be used.

Note: The size of the partition as shown in lsblk command differs from the parted utility’s output and this is because the former consider 1024MB to be equal to 1GB, whereas, the latter takes 1000MB as 1GB.

Making and mounting XFS filesystem

When it comes to making any filesystem on Ubuntu, the most common command is of the type mkfs.filesystemName in case of XFS the command is simple.

$mkfs.xfs /dev/sdb1

Where, sdb1 is our target partition.

Now we have a partition and a filesystem format for it. But it is still not a part of the system’s directory tree (loosely called as the root filesystem). We need to mount it, and traditionally the /mnt/ directory is used for this, although you can do it anywhere.

$mount /dev/sdb1 /mnt/
$df -h

Resizing the partition

If you have enough unallocated space, then resizing the filesystem to occupy the extra space is done in two steps:

  1. Resizing the partition: Let’s unmount the filesystem first:
    $umount /dev/sdb1

    Going back to the parted utility you can see the state of current state of the disk.

    $parted -a optimal /dev/sdb
    (parted) print

    The partition number is 1 and we need to refer to the partition with this number.

    Now, to grow the partition enter the command:

    (parted) unit GB
    (parted)resizepart 1 400

    So first we set the unit to GB and then the second command says get the partition 1 and move its end all the way to 400GB. So the end of the partition moves further away.

  2. The partition has grown, but the filesystem is not aware of it. If you mount it and see its size, it will still be the same. To grow the filesystem, this is the final step.
    $mount /dev/sdb1 /mnt
    $xfs_growfs -d /dev/sdb1

    The second command literally grows the filesystem and the -d flag tells it to go all the way to the end of the partition.

That’s it! Now if you see the filesystem information it will reflect the increase in its size.

Most of the steps are similar for other filesystems like ext4, ext3, ufs, etc. The only noticeable exception is that of zfs and you can learn more about that here.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

CentOS Install OpenJDK

When it’s necessary to build your apps or do some programming on Java, it’s always important to have all the necessary...

Moodle [Part 9] – Hướng dẫn các thao tác cơ bản cho người dùng học viên trên Moodle

Tiếp tục series hướng dẫn sử dụng Moodle. Trong bài viết này, Onet sẽ hướng dẫn bạn các thao...

Working with Debian Firewalls (UFW)

Uncomplicated Firewall (UFW) is a frontend for Iptables, the software we commonly use to manage netfilter which is a filtering...
Bài Viết

Bài Viết Mới Cập Nhật

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh

Mua proxy Onet uy tín tại

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?