How to install xfs and create xfs file system on Debian/Ubuntu Linux
<p>原文:https://www.cyberciti.biz/faq/how-to-install-xfs-and-create-xfs-file-system-on-debianubuntu-linux/</p><p> </p>
<p>recently switched to a Ubuntu/Debian Linux server from a CentOS/RHEL 7.x.</p>
<p>How do I<span style="background-color: rgba(255, 255, 0, 1)"> install xfs (mkfs.xfs command)</span> on a Debian/Ubuntu Linux server?</p>
<p>How do <span style="background-color: rgba(255, 255, 0, 1)">I create and manage file XFS file system</span> on a Ubuntu or Debian Linux LTS server?</p>
<p> </p>
<p>XFS<span style="background-color: rgba(255, 255, 0, 1)"> was created at Silicon Graphics, Inc</span> and currently<span style="background-color: rgba(255, 255, 0, 1)"> supported by Red Hat</span>. However, XFS is <span style="background-color: rgba(255, 255, 0, 1)">not the default file system for Debian or Ubuntu Linux</span> based system. XFS feature <span style="background-color: rgba(255, 255, 0, 1)">includes scalable and high-performance design</span>. This guide shows you <span style="background-color: rgba(255, 255, 0, 1)">how to install XFS and create an XFS file system on Debian or Ubuntu</span> Linux based system using the command line.</p>
<div class="my_postbox">
<table class="postbox" cellspacing="0">
<tbody>
<tr><th colspan="2">Tutorial requirements</th></tr>
<tr>
<td>Operating system</td>
<td>Debian/Ubuntu Linux</td>
</tr>
<tr class="even">
<td>Root privileges required</td>
<td>Yes</td>
</tr>
<tr>
<td>Difficulty</td>
<td>Easy (rss)</td>
</tr>
<tr class="even">
<td>Estimated completion time</td>
<td>10m</td>
</tr>
<tr>
<td colspan="2"><center>Contents</center>
<ul>
<li>» Installation</li>
<li>» Load Linux kernel module</li>
<li>» Create xfs filesystem</li>
<li>» Update /etc/fstab</li>
<li>» Check/repair an XFS filesystem</li>
<li></li>
</ul>
</td>
</tr>
</tbody>
</table>
<h2>Install xfs on Debian Linux</h2>
<p>Open the terminal app to <span style="background-color: rgba(255, 255, 0, 1)">update system</span> and then install xfs packages:<br><code>$ sudo apt-get update<br>$ sudo apt-get upgrade</code><br>Use the apt command/apt-get command to<span style="background-color: rgba(255, 255, 0, 1)"> install xfs</span>:<br><code>$ sudo apt-get install xfsprogs</code><br>Sample outputs</p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="code">
<pre class="ini">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
Get:1 http://cdn-aws.deb.debian.org/debian buster/main amd64 libreadline5 amd64 5.2+dfsg-3+b13
Get:2 http://cdn-aws.deb.debian.org/debian buster/main amd64 xfsprogs amd64 4.20.0-1
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</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h3>Load xfs kernel module/driver</h3>
<p>Now<span style="background-color: rgba(255, 255, 0, 1)"> xfs related utilities are installed</span>. However, it <span style="background-color: rgba(255, 255, 0, 1)">would be best if you loaded xfs Linux kernel driver/module too.</span> In other words, type the following one time command:<br><code>$ sudo modprobe -v xfs</code></p>
<p>Sample outputs:</p>
<pre>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 </pre>
<p><span style="background-color: rgba(255, 255, 0, 1)">Verify that xfs loaded</span> either using<span style="background-color: rgba(255, 255, 255, 1)"> the <span style="background-color: rgba(255, 255, 255, 1)">grep command</span> or lsmod command:</span><br><code>$ grep xfs /proc/filesystems<br>$ lsmod | grep xfs<br>$ modinfo xfs</code><br><img sizes="(max-width: 599px) 85vw, 599px" srcset="https://www.cyberciti.biz/media/new/faq/2017/09/Install-xfs-and-create-xfs-file-system-on-Debian-or-Ubuntu-Linux-verification.png 599w, https://www.cyberciti.biz/media/new/faq/2017/09/Install-xfs-and-create-xfs-file-system-on-Debian-or-Ubuntu-Linux-verification-300x294.png 300w" alt="Install xfs and create xfs file system on Debian or Ubuntu Linux verification" width="599" height="587" class="aligncenter size-full wp-image-148839 lazyload" data-src="https://www.cyberciti.biz/media/new/faq/2017/09/Install-xfs-and-create-xfs-file-system-on-Debian-or-Ubuntu-Linux-verification.png"><br>See Linux Add or Remove a Linux Kernel Modules / Drivers for more info.</p>
<h3>How to<span style="background-color: rgba(255, 255, 0, 1)"> list available disks</span> on a Debian or Ubuntu Linux</h3>
<p>You need to use the fdisk command and then press key:<br><code>sudo fdisk -l</code><br>My disks:</p>
<pre>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 EndSectors Size Id Type
/dev/xvda1 * 2048 83886046 8388399940G 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
</pre>
<p class="alert">WARNING: <span style="background-color: rgba(255, 255, 0, 1)">Be careful with disks names</span>. <span style="background-color: rgba(255, 255, 0, 1)">Verify twice before formatting or creating new partitions</span>. <span style="background-color: rgba(255, 255, 0, 1)">A wrong SSD/HDD name would result in data loss, and your /dev/DISK names might be different</span>.</p>
<h2>How to<span style="background-color: rgba(255, 255, 0, 1)"> create an xfs file system</span></h2>
<p>The syntax is:<br><code>mkfs.xfs /dev/device<br>mkfs.xfs /dev/device</code><br>This is optional but we can<span style="background-color: rgba(255, 255, 0, 1)"> create partition</span> using the fdisk command/cfdisk command/partx command/sfdisk command:<br><code># fdisk /dev/sdb</code><br>OR<br><code># cfdisk /dev/sdb</code><br>I<span style="background-color: rgba(255, 255, 0, 1)"> created a partition</span> named /dev/sdb1. To <span style="background-color: rgba(255, 255, 0, 1)">create an XFS file system</span>, use the mkfs.xfs /dev/sdb1 command:<br><code># mkfs.xfs /dev/sdb1</code><br>Sample outputs:</p>
<p>
<img sizes="(max-width: 599px) 85vw, 599px" srcset="https://www.cyberciti.biz/media/new/faq/2017/09/mkfs.xfs_.outputs.jpg 599w, https://www.cyberciti.biz/media/new/faq/2017/09/mkfs.xfs_.outputs-300x82.jpg 300w" alt="Fig.01: mkfs.xfs in action" width="599" height="164" class="size-full wp-image-146438 lazyload" data-src="https://www.cyberciti.biz/media/new/faq/2017/09/mkfs.xfs_.outputs.jpg">Fig.01: mkfs.xfs in action<br>In this example, I am going to format the whole /dev/xvdf device:<br><code>$ sudo mkfs.xfs /dev/xvdf</code><br>Outputs:</p>
<p> </p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="code">
<pre class="ini">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</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h2>How to <span style="background-color: rgba(255, 255, 0, 1)">mount an xfs file system</span> on Debian / Ubuntu</h2>
<p>Type the following<span style="background-color: rgba(255, 255, 0, 1)"> mount command</span>:<br><code># mkdir /data<br># mount /dev/sdb1 /data/<br># df -T</code><br>Sample outputs:</p>
<p>
<small>
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 856112012% /
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 209611760241952 209369808 1% /data
</small></p>
<h3><span style="background-color: rgba(255, 255, 0, 1)">Update /etc/fstab file to automount newly created filesystem</span> across<span style="background-color: rgba(255, 255, 0, 1)"> the system reboots</span></h3>
<p>To see /dev/sdb1 block device’s UUID (Universally Unique Identifier) run:<br><code># blkid /dev/device<br># blkid /dev/sdb1</code><br>Sample outputs:</p>
<pre>/dev/sdb1: UUID="ea8b08a4-3e9f-4482-83e9-c5f03b9f05d6" TYPE="xfs" PARTUUID="43eccd3d-9d50-4c29-a815-9fcf2986b235"</pre>
<p><span style="background-color: rgba(255, 255, 0, 1)">Edit/updated /etc/fstab file</span> using the following synta:<br><code>UUID={YOUR-UID} /data xfs defaults,errors=remount-ro 0 1</code><br>For example, the following wil<span style="background-color: rgba(255, 255, 0, 1)">l update /etc/fstab so that /dev/sda1 get mounted at boot time:</span></p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="code">
<pre class="bash">## type the following command as
## root user
echo 'UUID=ea8b08a4-3e9f-4482-83e9-c5f03b9f05d6 /data xfs defaults 1 1' >> /etc/fstab</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p>We can append text to a file named /etc/fstab when using sudo command as follows:<br><code>$ echo 'UUID=d90e3189-12cd-4d16-8fe9-cf362b5f267d /backup xfs defaults 1 1' \<br>| sudo tee -a /etc/fstab</code><br><span style="background-color: rgba(255, 255, 0, 1)">Mount new XFS filesystem and test it</span> with the help of mount command and df command:<br><code>$ sudo mount -a<br>$ sudo df -T</code><br><img sizes="(max-width: 599px) 85vw, 599px" srcset="https://www.cyberciti.biz/media/new/faq/2017/09/Installing-XFS-Creating-XFS-File-System-on-Debian.png 599w, https://www.cyberciti.biz/media/new/faq/2017/09/Installing-XFS-Creating-XFS-File-System-on-Debian-300x133.png 300w" alt="Installing XFS & Creating XFS File System on Debian" width="599" height="265" class="aligncenter size-full wp-image-148840 lazyload" data-src="https://www.cyberciti.biz/media/new/faq/2017/09/Installing-XFS-Creating-XFS-File-System-on-Debian.png"></p>
<h2>How to <span style="background-color: rgba(255, 255, 0, 1)">check and repair an XFS file system</span></h2>
<p>To<span style="background-color: rgba(255, 255, 0, 1)"> repair an XFS file system, use xfs_repair command</span> and the syntax is (do not run xfs_repair on a mounted filesystem):<br><code># xfs_repair /dev/device<br># umount /dev/sdb1<br># xfs_repair /dev/sdb1</code><br>Sample outputs:</p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="code">
<pre class="ini">Phase 1 - find and verify <span style="background-color: rgba(255, 255, 0, 1)">superblock</span>...
Phase 2 - using <span style="background-color: rgba(255, 255, 0, 1)">internal log</span>
- zero log...
- scan filesystem freespace and inode maps...
- found root inode chunk
Phase 3 - for each AG...
- <span style="background-color: rgba(255, 255, 0, 1)">scan and clear agi</span> 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</pre>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Conclusion</h2>
<p>In this guide, we explained <span style="background-color: rgba(255, 255, 0, 1)">how to install xfs and create/format second hard disk</span> 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:<br><code>$ man mkfs.xfs<br>$ man apt-get<br>$ man xfs_repair<br>$ man blkid<br>$ man fdisk</code></p>
<p> </p>
<p> </p>
</div><br><br>
来源:https://www.cnblogs.com/panpanwelcome/p/13093384.html
頁:
[1]