How to install xfs and create xfs file system on Debian/Ubuntu Linux
原文:https://www.cyberciti.biz/faq/how-to-install-xfs-and-create-xfs-file-system-on-debianubuntu-linux/
recently switched to a Ubuntu/Debian Linux server from a CentOS/RHEL 7.x.
How do I install xfs (mkfs.xfs command) on a Debian/Ubuntu Linux server?
How do I create and manage file XFS file system on a Ubuntu or Debian Linux LTS server?
XFS was created at Silicon Graphics, Inc and currently supported by Red Hat. However, XFS is not the default file system for Debian or Ubuntu Linux based system. XFS feature includes scalable and high-performance design. This guide shows you how to install XFS and create an XFS file system on Debian or Ubuntu Linux based system using the command line.
Tutorial requirements | |
---|---|
Operating system | Debian/Ubuntu Linux |
Root privileges required | Yes |
Difficulty | Easy (rss) |
Estimated completion time | 10m |
Install xfs on Debian Linux
Open the terminal app to update system and then install xfs packages:$ sudo apt-get update
$ sudo apt-get upgrade
Use the apt command/apt-get command to install xfs:$ sudo apt-get install xfsprogs
Sample outputs
Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libreadline5 Suggested packages: xfsdump acl attr quota The following NEW packages will be installed: libreadline5 xfsprogs 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 1,029 kB of archives. After this operation, 3,781 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://cdn-aws.deb.debian.org/debian buster/main amd64 libreadline5 amd64 5.2+dfsg-3+b13 [120 kB] Get:2 http://cdn-aws.deb.debian.org/debian buster/main amd64 xfsprogs amd64 4.20.0-1 [909 kB] Fetched 1,029 kB in 0s (5,183 kB/s) Selecting previously unselected package libreadline5:amd64. (Reading database ... 42720 files and directories currently installed.) Preparing to unpack .../libreadline5_5.2+dfsg-3+b13_amd64.deb ... Unpacking libreadline5:amd64 (5.2+dfsg-3+b13) ... Selecting previously unselected package xfsprogs. Preparing to unpack .../xfsprogs_4.20.0-1_amd64.deb ... Unpacking xfsprogs (4.20.0-1) ... Setting up libreadline5:amd64 (5.2+dfsg-3+b13) ... Setting up xfsprogs (4.20.0-1) ... update-initramfs: deferring update (trigger activated) Processing triggers for man-db (2.8.5-2) ... Processing triggers for libc-bin (2.28-10) ... Processing triggers for initramfs-tools (0.133+deb10u1) ... update-initramfs: Generating /boot/initrd.img-4.19.0-9-amd64 |
Load xfs kernel module/driver
Now xfs related utilities are installed. However, it would be best if you loaded xfs Linux kernel driver/module too. In other words, type the following one time command:$ sudo modprobe -v xfs
Sample outputs:
insmod /lib/modules/4.19.0-9-amd64/kernel/lib/libcrc32c.ko insmod /lib/modules/4.19.0-9-amd64/kernel/fs/xfs/xfs.ko
Verify that xfs loaded either using the grep command or lsmod command:$ grep xfs /proc/filesystems
$ lsmod | grep xfs
$ modinfo xfs
See Linux Add or Remove a Linux Kernel Modules / Drivers for more info.
How to list available disks on a Debian or Ubuntu Linux
You need to use the fdisk command and then press [enter] key:sudo fdisk -l
My disks:
Disk /dev/xvda: 40 GiB, 42949672960 bytes, 83886080 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x15e5590c Device Boot Start End Sectors Size Id Type /dev/xvda1 * 2048 83886046 83883999 40G 83 Linux Disk /dev/xvdf: 400 GiB, 429496729600 bytes, 838860800 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
WARNING: Be careful with disks names. Verify twice before formatting or creating new partitions. A wrong SSD/HDD name would result in data loss, and your /dev/DISK names might be different.
How to create an xfs file system
The syntax is:mkfs.xfs /dev/device
mkfs.xfs [options] /dev/device
This is optional but we can create partition using the fdisk command/cfdisk command/partx command/sfdisk command:# fdisk /dev/sdb
OR# cfdisk /dev/sdb
I created a partition named /dev/sdb1. To create an XFS file system, use the mkfs.xfs /dev/sdb1 command:# mkfs.xfs /dev/sdb1
Sample outputs:
Fig.01: mkfs.xfs in action
In this example, I am going to format the whole /dev/xvdf device:$ sudo mkfs.xfs /dev/xvdf
Outputs:
meta-data=/dev/xvdf isize=512 agcount=4, agsize=26214400 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=0 data = bsize=4096 blocks=104857600, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=51200, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 |
How to mount an xfs file system on Debian / Ubuntu
Type the following mount command:# mkdir /data
# mount /dev/sdb1 /data/
# df -T
Sample outputs:
Filesystem Type 1K-blocks Used Available Use% Mounted on udev devtmpfs 1885404 0 1885404 0% /dev tmpfs tmpfs 379308 6728 372580 2% /run /dev/sda1 ext4 10188088 1086400 8561120 12% / tmpfs tmpfs 1896536 0 1896536 0% /dev/shm tmpfs tmpfs 5120 0 5120 0% /run/lock tmpfs tmpfs 1896536 0 1896536 0% /sys/fs/cgroup /dev/sdb1 xfs 209611760 241952 209369808 1% /data
Update /etc/fstab file to automount newly created filesystem across the system reboots
To see /dev/sdb1 block device’s UUID (Universally Unique Identifier) run:# blkid /dev/device
# blkid /dev/sdb1
Sample outputs:
/dev/sdb1: UUID="ea8b08a4-3e9f-4482-83e9-c5f03b9f05d6" TYPE="xfs" PARTUUID="43eccd3d-9d50-4c29-a815-9fcf2986b235"
Edit/updated /etc/fstab file using the following synta:UUID={YOUR-UID} /data xfs defaults,errors=remount-ro 0 1
For example, the following will update /etc/fstab so that /dev/sda1 get mounted at boot time:
## type the following command as ## root user echo 'UUID=ea8b08a4-3e9f-4482-83e9-c5f03b9f05d6 /data xfs defaults 1 1' >> /etc/fstab |
We can append text to a file named /etc/fstab when using sudo command as follows:$ echo 'UUID=d90e3189-12cd-4d16-8fe9-cf362b5f267d /backup xfs defaults 1 1' \
| sudo tee -a /etc/fstab
Mount new XFS filesystem and test it with the help of mount command and df command:$ sudo mount -a
$ sudo df -T
How to check and repair an XFS file system
To repair an XFS file system, use xfs_repair command and the syntax is (do not run xfs_repair on a mounted filesystem):# xfs_repair /dev/device
# umount /dev/sdb1
# xfs_repair /dev/sdb1
Sample outputs:
Phase 1 - find and verify superblock... Phase 2 - using internal log - zero log... - scan filesystem freespace and inode maps... - found root inode chunk Phase 3 - for each AG... - scan and clear agi unlinked lists... - process known inodes and perform inode discovery... - agno = 0 - agno = 1 - agno = 2 - agno = 3 - process newly discovered inodes... Phase 4 - check for duplicate blocks... - setting up duplicate extent list... - check for inodes claiming duplicate blocks... - agno = 0 - agno = 1 - agno = 2 - agno = 3 Phase 5 - rebuild AG headers and trees... - reset superblock... Phase 6 - check inode connectivity... - resetting contents of realtime bitmap and summary inodes - traversing filesystem ... - traversal finished ... - moving disconnected inodes to lost+found ... Phase 7 - verify and correct link counts... done |
Conclusion
In this guide, we explained how to install xfs and create/format second hard disk with XFS on a Debian or Ubuntu Linux based servers or desktop system. For more info about above commands, read their respective man pages and see XFS wiki pages here:$ man mkfs.xfs
$ man apt-get
$ man xfs_repair
$ man blkid
$ man fdisk