如何在Debian/Ubuntu Linux上安装xfs和创建xfs文件系统
如何在Debian/Ubuntu Linux服务器上安装xfs(mkfs.xfs命令)?
如何在Ubuntu或Debian Linux LTS服务器上创建和管理文件XFS文件系统?
XFS是由Silicon Graphics,Inc创建的,目前受Red Hat支持。
但是,XFS不是基于Debian或Ubuntu Linux的系统的默认文件系统。
XFS功能包括可扩展的高性能设计。
此教程介绍了如何使用命令行在基于Debian或Ubuntu Linux的系统上安装XFS并创建XFS文件系统。
在Debian Linux上安装xfs
打开终端应用程序以更新系统,然后安装xfs软件包:
$ sudo apt-get update $ sudo apt-get upgrade
使用apt命令/apt-get命令安装xfs:
$ sudo apt-get install xfsprogs
输出示例
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
加载xfs内核模块/驱动程序
现在,已安装xfs相关实用程序。
但是,最好也加载xfs Linux内核驱动程序/模块。
换句话说,执行以下一次命令:
$ sudo modprobe -v xfs
输出示例:
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
使用grep命令或lsmod命令验证是否已加载xfs:
$ grep xfs /proc/filesystems $ lsmod | grep xfs $ modinfo xfs
如何列出Debian或Ubuntu Linux上的可用磁盘
您需要使用fdisk命令,然后按[enter]键:
sudo fdisk -l
我的磁盘:
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
警告:注意磁盘名称。
在格式化或创建新分区之前,请进行两次验证。
错误的SSD/HDD名称将导致数据丢失,并且/dev/DISK名称可能不同。
如何创建XFS文件系统
语法为:
mkfs.xfs /dev/device mkfs.xfs [options] /dev/device
这是可选的,但是我们可以使用fdisk命令/cfdisk命令/partx命令/sfdisk命令创建分区:
# fdisk /dev/sdb
或者
# cfdisk /dev/sdb
我创建了一个名为/dev/sdb1的分区。
要创建XFS文件系统,请使用mkfs.xfs/dev/sdb1命令:
# mkfs.xfs /dev/sdb1
运行中的mkfs.xfs
$ sudo mkfs.xfs /dev/xvdf
输出
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
如何在Debian/Ubuntu上挂载XFS文件系统
执行以下安装命令:
# mkdir /data # mount /dev/sdb1 /data/ # df -T
输出示例:
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
更新/etc/fstab文件以在系统重新引导后自动挂载新创建的文件系统
要查看/dev/sdb1块设备UUID(通用唯一标识符),请运行:
# blkid /dev/device # blkid /dev/sdb1
输出示例:
/dev/sdb1: UUID="ea8b08a4-3e9f-4482-83e9-c5f03b9f05d6" TYPE="xfs" PARTUUID="43eccd3d-9d50-4c29-a815-9fcf2986b235"
使用以下语法来编辑/更新/etc/fstab文件:
UUID={YOUR-UID} /data xfs defaults,errors=remount-ro 0 1
例如,以下内容将更新/etc/fstab,以便在引导时挂载/dev/sda1:
## type the following command as ## root user echo 'UUID=ea8b08a4-3e9f-4482-83e9-c5f03b9f05d6 /data xfs defaults 1 1' >> /etc/fstab
使用sudo命令时,我们可以将文本追加到名为/etc/fstab的文件中,如下所示:
$ echo 'UUID=d90e3189-12cd-4d16-8fe9-cf362b5f267d /backup xfs defaults 1 1' \ | sudo tee -a /etc/fstab
挂载新的XFS文件系统,并在mount命令和df命令的帮助下对其进行测试:
$ sudo mount -a $ sudo df -T
如何检查和修复XFS文件系统
要修复XFS文件系统,请使用xfs_repair命令,语法为(不要在已安装的文件系统上运行xfs_repair):
# xfs_repair /dev/device # umount /dev/sdb1 # xfs_repair /dev/sdb1
输出示例:
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