0% found this document useful (0 votes)
4 views

Inodes, Compression and Archiving

The document discusses file systems in Linux, specifically the transition from ext4 in RHEL 6 to xfs in RHEL 7, and explains the concept of inodes and their role in file management. It covers commands for viewing partitions, file systems, inode usage, and the differences between hard links and soft links. Additionally, it details compression methods (gzip, bzip2, xz), archiving with tar, and data migration using scp.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Inodes, Compression and Archiving

The document discusses file systems in Linux, specifically the transition from ext4 in RHEL 6 to xfs in RHEL 7, and explains the concept of inodes and their role in file management. It covers commands for viewing partitions, file systems, inode usage, and the differences between hard links and soft links. Additionally, it details compression methods (gzip, bzip2, xz), archiving with tar, and data migration using scp.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Files System (inodes):

It deals with how data is write to the hard disk, Linux file system in RHEL 6 was
ext4, now the file system in RHEL 7 is xfs. In windows FAT32, NTFS.

In Linux each partitions have its own partition table we called this table inode
table, this table holds information about each file and directory.

Each inode represents no. of blocks that is reserved for each file. So it is very
limited resource.

To see the Linux partition:


[root@server ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 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
Disk label type: dos
Disk identifier: 0x000f308e

Device Boot Start End Blocks Id System


/dev/sda1 2048 10487807 5242880 83 Linux
/dev/sda2 10487808 14682111 2097152 82 Linux swap / Solaris
/dev/sda3 * 14682112 125829119 55573504 83 Linux

To see file system for each partition:


[root@server ~]# blkid
/dev/sr0: UUID="2018-05-03-20-55-23-00" LABEL="CentOS 7 x86_64"
TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="e616255a-f9c9-4197-a115-2badfa0454f7" TYPE="xfs"
/dev/sda2: UUID="e6ad84ba-814b-48d5-966f-42c07bb56081" TYPE="swap"
/dev/sda3: UUID="5efb6aab-b398-45ed-9d2b-5015e5a4acce" TYPE="xfs"

To see number of inodes reserved:


[root@server ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 27786752 122879 27663873 1% /
devtmpfs 249789 400 249389 1% /dev
tmpfs 253771 1 253770 1% /dev/shm
tmpfs 253771 900 252871 1% /run
tmpfs 253771 16 253755 1% /sys/fs/cgroup
/dev/sda1 2621440 181 2621259 1% /home
tmpfs 253771 9 253762 1% /run/user/42
tmpfs 253771 1 253770 1% /run/user/0

Inode table info:


-type
-permissions
-hardlinks
-m time
-c time (ctime gets updated when the file attributes are changed, like changing the
owner, changing the permission or moving the file to another filesystem but will
also be updated when you modify a file.)
-a time
-owner
-group
-size
-inode no.
-data blocks

Note: on copy new inode created, in move the inode did not changed (in the same
partition), but move in different partition will make copy first then move with new
inode.

Note: every directory have its own partition table, each directory must have the .
and .. To see this we can use ls -ila.
We have two types of inodes hardlink or softlink.

Hard link create in the same partition, it can be used for backup:
[root@server /]# ln /root/f1 /home/iti/f20
ln: failed to create hard link ‘/home/iti/f20 ==> ‘/root/f1’: Invalid cross-device link

[root@server /]# ln /root/f1 /usr/bin/f20


[root@server /]# ls -il /root/f1 /usr/bin/f20
67928720 -rw-r--r--. 2 root root 0 Nov 8 11:10 /root/f1
67928720 -rw-r--r--. 2 root root 0 Nov 8 11:10 /usr/bin/f20
Note: the hard link cannot be used with directories

Soft link it is a shot cut:


It can be used between two different partitions
[root@server /]# ln -s /usr/bin/f20 /home/iti/ali
[root@server /]# ls -il /home/iti/ali /usr/bin/f20
3650 lrwxrwxrwx. 1 root root 12 Nov 9 23:25 /home/iti/ali ==> /usr/bin/f20
67928720 -rw-r--r--. 2 root root 0 Nov 8 11:10 /usr/bin/f20

Note: see the pointer to the original file with the permissions and type of file, soft
link can be used between directories.
[root@server /]#stat /var/log/messages ==> to see the access, modification and
Change time.

Disk format vs disk usage:


[root@server /]# df ==> blocks in kilo byte
[root@server /]# df -h ==> blocks in human readable
[root@server /]# du -ah /etc/ ==> size of each file and subdirectory in human
readable
[root@server /]# du -sh /etc/ ==> summary for the size of dir human readable

Compression:
Before we compress we have to decide some points:
-performance: time take to compress the files.
-Compression ratio: save the size of the file after backup.

In Linux system we have three types of compression: gzip, bzip2, xf

1. gzip:
[root@srv1 ~]# ls –lh
/run/log/journal/b35c19c139b74e8082e555b588764007/system.journal
-rw-r-----+ 1 root systemd-journal 8.0M Nov 15 13:28

[root@srv1 ~]# cp
/run/log/journal/b35c19c139b74e8082e555b588764007/system.journal
system.log
[root@srv1 ~]# ls -lh system.log
-rw-r-----. 1 root root 8.0M Nov 15 13:40 system.log

To compress the file via gzip tool:


[root@srv1 ~]# gzip system.log
[root@srv1 ~]# ls -lh system.log.gz
-rw-r-----. 1 root root 958K Nov 15 13:40 system.log.gz
To read the connect of the files via gzip tool:
[root@srv1 ~]# zcat system.log.gz

To uncompress the file via gzip tool:


[root@srv1 ~]# gunzip system.log.gz

It is the fastest compression tool and it is the most popular among linux
distributions.

2. Bzip2:
To compress the file via bzip2 tool:
[root@srv1 ~]# bzip2 system.log
[root@srv1 ~]# ls -lh system.log.bz2
-rw-r-----. 1 root root 752K Nov 15 13:40 system.log.bz2

To read the connect of the files via bzip2 tool:


[root@srv1 ~]# bzcat system.log.bz2

To uncompress the file via bzip2 tool:


[root@srv1 ~]# bunzip2 system.log.bz2

[root@srv1 ~]# ls -lh system.log


-rw-r-----. 1 root root 8.0M Nov 15 13:40 system.log

Note: bzip2 compress the file but it takes more time than gzip but the
compression ratio is perfect.

3. To compress the file via xz tool developed by xfs file system:


[root@srv1 ~]# xz system.log
[root@srv1 ~]# ls -lh system.log.xz
-rw-r-----. 1 root root 498K Nov 15 13:40 system.log.xz

To read the connect of the files via xz tool:


[root@srv1 ~]# xzmore system.log.xz

To uncompress the file via xz tool:


[root@srv1 ~]# unxz system.log.xz

Note: xz tool have the highest compression ration but takes more time.
Archiving:
It is used to make backup of important file, there is big difference between archive
and compression but they can integrate with each other.

Backup files: root scripts, home directory, yum configuration, ssh configuration,
logs.

If we use the option -f so it will make backup as a file, but its default to take our
backup to tape drive.

It helps you to create the same directory structure to be extracted in the other
location.

When taking the archive with absolute path, the leading / is removed from the file
name by default and the files extracted relative to the current working directory of
the tar command.

Note: the tar command did not store file SEinux contexts and ACL.

[root@srv1 ~]# tar -cvf home.tar /home ==> to backup and create the tar file
[root@srv1 ~]# ls -lh home.tar
-rw-r--r--. 1 root root 12M Nov 15 14:59 home.tar

To show the table of content of home.tar:

[root@srv1 ~]# tar -tf home.tar ==> to show file inside the home.tar

[root@srv1 ~]# tar -xf home.tar home/ali/.bashrc ==> to extract one file from the
archive.

[root@srv1 ~]# tar -xf home.tar ==> to extract all files

Note: when we extract the tar file it remains in our backup.

Integration between the Archiving and Compression:


[root@srv1 ~]# mkdir yum-config
[root@srv1 ~]# cp /etc/yum.repos.d/* /root/yum-config/.
[root@srv1 ~]# tar –czvf yum.tar.gz yum-config ==> gzip & tar
[root@srv1 ~]# ls -lh yum.tar.gz
-rw-r--r--. 1 root root 2.1K Nov 15 16:13 yum.tar.gz
[root@srv1 ~]# tar -tzf yum.tar.gz ==> to show files inside the gzip archive
[root@srv1 ~]# tar -xf yum.tar.gz ==> to extract the files

[root@srv1 ~]# tar -cJvf yum.tar.bz2 yum-config ==> xz & tar


[root@srv1 ~]# ls -lh yum.tar.xz
-rw-r--r--. 1 root root 2.1K Nov 15 16:26 yum.tar.xz
[root@srv1 ~]# tar -tJf yum.tar.xz ==> to show files inside the xz archive
[root@srv1 ~]# tar -xf yum.tar.xz ==> to extract the files

Migration of file and directories between systems:


We can use scp commands to migrate data from location to another:
Machine centos 7:
[root@srv1 ~]# ip addr show ens33 | grep -w inet
inet 192.168.10.10/24 brd 192.168.10.255 scope global noprefixroute ens33

[root@srv1 ~]# tar -cJvf home.tar.xz /home/


[root@srv1 ~]# ls -lh home.tar.xz
-rw-r--r--. 1 root root 592 Nov 15 16:53 home.tar.xz
[root@srv1 ~]# scp home.tar.xz [email protected]:/root/backup/

Machine centos8:
[root@srv1 backup]# ip addr show ens160 | grep -w inet
inet 192.168.10.25/24 brd 192.168.10.255 scope global noprefixroute ens160
To copy directory to machine centos 8, we use the option -r with scp command

Centos8 machine:

Full back up and incremental backup with rsync:


Incremental Backup:

You might also like