Create XFS filesystem on Centos

Server : Test1


Step 1:
------------
Create two logical volumes with size 2Gb & 512MB respectively.

[root@sara2 ~]# lvcreate -n xfsdata -L 2G vgsrv -->xfs filesystem
  Logical volume "xfsdata" created
[root@sara2 ~]# lvcreate -n xfsjournal -L 512M vgsrv -->external journal setup
  Logical volume "xfsjournal" created

[root@sara2 ~]# yum install xfsprogs

Create a new xfs filesystem with external journal.

[root@sara2 ~]# mkfs -t xfs -l logdev=/dev/vgsrv/xfsjournal /dev/vgsrv/xfsdata
meta-data=/dev/vgsrv/xfsdata     isize=256    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =/dev/vgsrv/xfsjournal  bsize=4096   blocks=131072, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0


Create a directory and mount it.


mkdir /xfs
/dev/vgsrv/xfsdata   /xfs  xfs logdev=/dev/vgsrv/xfsjournal 1 2 -->/etc/fstab
mount /xfs

Growing an XFS filesystem[on fly]:
--------------------------------------------------------


-We can grow xfs filesystem while its mounted, In fact we cant grow xfs with unmount.
[root@sara2 ~]# df -h /xfs
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vgsrv-xfsdata
                      2.0G   33M  2.0G   2% /xfs

[root@sara2 ~]# lvextend -L 4G /dev/vgsrv/xfsdata
  Size of logical volume vgsrv/xfsdata changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).
  Logical volume xfsdata successfully resized

[root@sara2 ~]# xfs_growfs /xfs
meta-data=/dev/mapper/vgsrv-xfsdata isize=256    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =external               bsize=4096   blocks=131072, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
xfs_growfs: log growth not supported yet
data blocks changed from 524288 to 1048576

[root@sara2 ~]# df -h /xfs
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vgsrv-xfsdata
                      4.0G   33M  4.0G   1% /xfs


Xfs maintenance:
-----------------

Create some fragmented files to perform xfs maintenance,

for FILE in file{0..3}; do dd if=/dev/zero  of=/xfs/${FILE} bs=4M count=100 & done

Examine the fragmentation of that files and run the Xfs defragment tool to defragment all your mounted xfs filesystem,

[root@sara2 ~]# filefrag /xfs/file*
/xfs/file0: 2 extents found
/xfs/file1: 4 extents found
/xfs/file2: 4 extents found
/xfs/file3: 3 extents found
[root@sara2 ~]# xfs_fsr -v
Found 1 mounted, writable, XFS filesystems
xfs_fsr -m /etc/mtab -t 7200 -f /var/tmp/.fsrlast_xfs ...
START: pass=0 ino=0 /dev/mapper/vgsrv-xfsdata /xfs
/xfs start inode=0
ino=132
extents before:4 after:1 DONE ino=132
ino=134
extents before:4 after:1 DONE ino=134
ino=133
extents before:3 after:2      ino=133
ino=131
extents before:2 after:1 DONE ino=131
/xfs start inode=0
ino=133
extents before:2 after:1 DONE ino=133
/xfs start inode=0
/xfs start inode=0
/xfs start inode=0
/xfs start inode=0
/xfs start inode=0
/xfs start inode=0
/xfs start inode=0
/xfs start inode=0
Completed all 10 passes
[root@sara2 ~]# filefrag /xfs/file*
/xfs/file0: 1 extent found
/xfs/file1: 1 extent found
/xfs/file2: 1 extent found
/xfs/file3: 1 extent found
[root@sara2 ~]#

Before running xfs tool, most files were spread out over multiple extents and after they are just one extent.

Repairing xfs filesystem,

umount /xfs
xfs_repair -n -l /dev/vgsrv/xfsjournal /dev/vgsrv/xfsdata
xfs_repair -l /dev/vgsrv/xfsjournal /dev/vgsrv/xfsdata
mount /xfs

Backup & Restore,

-perform level 0[full] backup of /xfs filesystem and pipe the backup through xz compression tool into a file.

[root@sara2 ~]# yum -y install xfsdump

[root@sara2 ~]# xfsdump -L full -M dumpfile -l 0 - /xfs | xz > /xfs.xz

[root@sara2 ~]# xfsdump -I
file system 0:
    fs id:        2c82df1e-36f0-4770-a9b7-796fb9d6c78d
    session 0:
        mount point:    sara2.test.com:/xfs
        device:        sara2.test.com:/dev/mapper/vgsrv-xfsdata
        time:        Wed Apr  8 16:12:10 2015
        session label:    "full"
        session id:    db7f134c-7111-4fdb-978d-a3a9e16f4a79
        level:        0
        resumed:    NO
        subtree:    NO
        streams:    1
        stream 0:
            pathname:    stdio
            start:        ino 0 offset 0
            end:        ino 0 offset 0
            interrupted:    YES
            media files:    0
xfsdump: Dump Status: SUCCESS

Restore:
xzcat /xfs.xz | xfsrestore - /xfs

Comments

Popular posts from this blog

Using a Linux server to route packets between two private networks

PHP Fatal error: Class 'JFactory' not found

KVM & Qemu