# Chapter 6

**Thin provisioning** is a method of optimizing the utilization of available storage by allocating storage space only as it is needed.

**Thick provisioning**, also known as fixed or allocated provisioning, involves allocating the full amount of required storage space at the time of provisioning.

To get an overview of currently existing devices:

```
lsblk
/dev/sdx     - SCSI and SATA disks
/dev/vdx     - KVM virtual machines
/dev/nvmexny - is used for NVME devices
```

Naming convention:

```
/dev/sda2 - second partition on the first hard disk
/dev/sdb1 - first partition on te second hard disk
/dev/nvme0n1p1 - first partition on the first hard disk
/dev/nvme0n3p2 - second partition on the third hard disk
```

## MBR vs GPT

### MBR:

* 512 bytes to store boot information
* 64 bytes to store partitions
* Place for 4 partitions only with max size of 2 TiB
* To use more partitions, extended and logical partitions must be used

### GPT

* More space to store partitions
* used to overcome MBR limitations
* 128 partitions maximum

## Creating partitions

Common tools:

```
fdisk - creates MBT and GPT partitions 
gdisk - creates GPT by default
parted- can be scripted easily
```

Aliases:

```
linux - standard linux
swap  - linux swap
uefi  - uefi boot
lvm   - logical volume manager
```

Əgər yeni partition yaradarkən fdisk içində `n` əmrindən sonra bu üç yazı çıxırsa bu o deməkdir ki, MBR partition table olunub həmin disk. Çünki 4 free yer var cəmi, extended partition seçimi var və 128 partitionun yaradılması biraz inanılmazdır.

```
[root@localhost ali]# fdisk /dev/nvme0n1

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
All space for primary partitions is in use
```

MBR-dan istifadə edən zaman əgər 3 primary partition varsa bu zaman dördüncünü mütləq extended partition yaratmaq lazımdır ki, LVM-lərdən istifadə edə bilinsin.

## Filesystems

### Comparison of popular filesystems

#### XFS is the default filesystem

* fast and scalable
* uses CoW(copy on write) to guarantee data integrity
* size can be increased, not decreased

#### Ext4 was default in RHEL6 and still used

* backward compatible to Ext2
* uses journal to guarantee data integrity
* size can be increased decreased

#### vfat offers multi-OS support

* used for shared devices

#### btrfs is a new and advanced filesystem

### Creating filesystems

```
[root@localhost ali]# mkfs.[Tab][Tab]
mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.fat     mkfs.minix   mkfs.msdos   mkfs.vfat    mkfs.xfs 
```

### mounting filesystems:

```
# Mount command shows all mounted filesystems, including administrative kernel mounts
mount

# This command mounts vdb1 filesystem into /mnt folder:
mount /dev/vdb1 /mnt

# You should unmount filesystem before disconnecting a device
umount

# lsof command will tell you about open files in mount
lsof /mnt

# findmnt command shows which filesystem is mounted where in the directory structure
findmnt
```

#### Example 1 - using fdisk:

1\) Created partition

```
[root@localhost ali]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0          11:0    1 12.8G  0 rom  /run/media/ali/Rocky-8-9-x86_64-dvd
nvme0n1     259:0    0   50G  0 disk 
├─nvme0n1p1 259:1    0    1G  0 part /boot
└─nvme0n1p2 259:2    0   49G  0 part 
  ├─rl-root 253:0    0 45.1G  0 lvm  /
  └─rl-swap 253:1    0  3.9G  0 lvm  [SWAP]
nvme0n2     259:3    0   20G  0 disk 
[root@localhost ali]# fdisk /dev/nvme0n2

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
```

2\) Created filesystem on this partition:

```
[root@localhost ali]# mkfs.xfs /dev/nvme0n2p1
```

3\) Mounted the filesystem:

As you can see on the last line, mountpoint of /dev/nvme0n2p1 is /mnt

```
[root@localhost ali]# mount /dev/nvme0n2p1 /mnt
[root@localhost ali]# 
[root@localhost ali]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0          11:0    1 12.8G  0 rom  /run/media/ali/Rocky-8-9-x86_64-dvd
nvme0n1     259:0    0   50G  0 disk 
├─nvme0n1p1 259:1    0    1G  0 part /boot
└─nvme0n1p2 259:2    0   49G  0 part 
  ├─rl-root 253:0    0 45.1G  0 lvm  /
  └─rl-swap 253:1    0  3.9G  0 lvm  [SWAP]
nvme0n2     259:3    0   20G  0 disk 
└─nvme0n2p1 259:4    0    2G  0 part /mnt
```

it is also able to seen in `mount` command:

```
[root@localhost ali]# mount | grep '^/'
/dev/mapper/rl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/nvme0n1p1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sr0 on /run/media/ali/Rocky-8-9-x86_64-dvd type iso9660 (ro,nosuid,nodev,relatime,nojoliet,check=s,map=n,blocksize=2048,uid=1000,gid=1000,dmode=500,fmode=400,uhelper=udisks2)
/dev/nvme0n2p1 on /mnt type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
```

it can also able to seen in `findmnt` command:

```
[root@localhost ali]# findmnt
TARGET                                  SOURCE              FSTYPE              OPTIONS
/                                       /dev/mapper/rl-root xfs                 rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota
<-SNIPPED->
└─/mnt                                  /dev/nvme0n2p1      xfs                 rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota
```

to unmount device:

```
[root@localhost ali]# lsof /mnt
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
[root@localhost ali]# umount /mnt
```

Əgər `wrong fs type` erroru gəlirsə deməli ya filesystem yaratmaq yadımnan çıxıb ya da extended içindəki logical partitionu mount etmək yerinə extended partitionu mount etməyə çalışıram.

#### Example 2 - using gdisk:

```
gdisk /dev/nvme0n2

Partition number (1-128, default 1): 1
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: +2G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to 'Linux LVM'

Command (? for help): p
Disk /dev/nvme0n2: 41943040 sectors, 20.0 GiB
Model: VMware Virtual NVMe Disk
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): C2535E9B-8E81-47F1-8349-81F3BB14DD79
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 37748669 sectors (18.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         4196351   2.0 GiB     8E00  Linux LVM

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/nvme0n2.
The operation has completed successfully.
```

## /etc/fstab

Mountları reboot persistent etmək üçün mountları fstab-a yazmaq lazımdır

```
/dev/sdb1    /data    ext4    defaults 0,0
```

```
systemd-fstab-generator
systemctl deamon-reload
```

`/etc/fstab`da edilən hər hansı səhvə görə sistem normal boot edilməyə bilər. fstab-ın syntaxını doğrulamaq üçün aşağıdakı komandaları icra etmək lazımdır:

```
mount -a            # mount olunmamış filesystemləri mount edir
findmnt --verify    # fstabda error və warning olmamasına baxır
```

Əgər OS açılmasa, grub boot menuda kernel sətri axırındakı aşağıdakı sətirləri silmək lazımdır ki, errorları görək:

```
rhgb quiet
```

reboot etdikdə 1min30san görsədəcək error olan job complete olmağı üçün. Gözlədikdən sonra shell gələcək.

fstab-dakı yazdığımız şeylər systemd mount-a tərcümə edilir OS tərəfindən. fstab-dan yaradılmış fayllara aşağıdakı qovluqda baxmaq mümkündür:

```
ls /run/systemd/generator
cat /run/systemd/generator/boot.mount
```

Hər hansı mounta bu komanda ilə də baxmaq mümkündür

```
systemctl cat tmp.mount
```

### systemctl ilə mountun aktivləşdirilməsi

```
# mount komandasında tmp adı keçən sətirləri ekrana yazdıraq

[root@localhost ali]# mount | grep tmp
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=1830940k,nr_inodes=457735,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=372084k,mode=700,uid=1000,gid=1000)

# systemctl vasitəsilə tmp.mount-u aktivləşdirək

[root@localhost ali]# systemctl enable --now tmp.mount
Created symlink /etc/systemd/system/local-fs.target.wants/tmp.mount → /usr/lib/systemd/system/tmp.mount.

# son sətirdə aktivləşdirdiyimiz mountun əlavə edildiyini görürük:

[root@localhost ali]# mount | grep tmp
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=1830940k,nr_inodes=457735,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=372084k,mode=700,uid=1000,gid=1000)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,seclabel)


# fstab systemctlə çevrildiyi üçün /tmp mountunu fstabda görmək mümkün deyil çünki
# heç vaxt burda yazılmamışdı

[root@localhost ali]# grep tmp /etc/fstab


# tmp.mountun statusuna systemctl əmri vasitəsilə baxırıq:

[root@localhost ali]# systemctl status tmp.mount
● tmp.mount - Temporary Directory (/tmp)
   Loaded: loaded (/usr/lib/systemd/system/tmp.mount; enabled; vendor preset: disabled)
   Active: active (mounted) since Wed 2024-06-26 10:40:07 +0330; 52s ago
    Where: /tmp
     What: tmpfs
     Docs: man:hier(7)
           https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
    Tasks: 0 (limit: 22886)
   Memory: 4.0K
   CGroup: /system.slice/tmp.mount

Jun 26 10:40:07 localhost.localdomain systemd[1]: Mounting Temporary Directory (/tmp)...
Jun 26 10:40:07 localhost.localdomain systemd[1]: Mounted Temporary Directory (/tmp).
```

## Persistent naming attributes

```
blkid         # shows all devices with their naming attributes
tune2fs -L    # is used to set a label on an EXT filesystem
xfs_admin -L  # is used to set a label on an XFS filesystem
mkfs.* -L     # is used to set a label while creating a filesystem
```

### XFS UUID clone error

Nəyə görə UUİD-ləri istifadə edirik?

Əgər 2 partition yaratmışıqsa, məs. /dev/sda5 və /dev/sda6. /etc/fstab içində /dev/sda5-i silsək, əvvəlki /dev/sda6 adını dəyişib /dev/sda5 olacaq çünki ordered numberlə nizamlanır adlar.

Bunun qarşısına keçməkçün fstab-da UUİD vermək lazımdır.

UUID-lərə bu komanda ilə baxmaq mümkündür:

```
lsblk --fs
```

UUİD vermək qaydası:

```
# bu bizə sda5-in UUID-sini verir
blkid | grep sda5 | awk '{ print $2 }' >> /etc/fstab 
```

Sonra isə həmin UUID-ni `/etc/fstab` içində yazırıq:

```
UUID="blablabla"    /qovluq    ext4    defaults    0 0
```

XFS filesystem clone edildikdə UUID-si də clone olunur. Bu səbəbdən clone edilmiş filesystemə yeni UUID təyin etmək üçün:

```
xfs_admin -U generate /dev/sdb1
```

## parted

```
[root@localhost ali]# parted /dev/nvme0n2 unit GiB print
Model: NVMe Device (nvme)
Disk /dev/nvme0n2: 20.0GiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start    End      Size     Type     File system  Flags
 1      0.00GiB  2.00GiB  2.00GiB  primary  xfs
```

Parted vasitəsilə disk-in partition table-nı GPT-yə çevirmək üçün:

{% hint style="danger" %}
Əgər diskdə data varsa bu əmrlər həmin dataları siləcək
{% endhint %}

```
parted /dev/nvme0n2 mklabel gpt
```

MBR-a çevirmək üçün:

```
parted /dev/nvme0n2 mklabel msdos
```

### diskə partition table verilməsi və partition yaradılması

Bu komanda `/dev/nvme0n2` diskini GPT-yə çevirir, `userdata` adlı partition yaradır, filesystemi `xfs` edir, və ölçünü 1000MB təyin edir:

&#x20;

```
parted /dev/nvme0n2 mklabel gpt mkpart usersdata xfs 2048s 1000MB
```

Bu komanda `/dev/nvme0n2` diskini MBR-a çevirir, primary partition yaradır, filesystemi xfs edir, və ölçünü 1000MB edir:

```
parted /dev/nvme0n2 mklabel msdos mkpart primary xfs 2048s 1000MB
```

Həmin komanda interaktiv formada da icra edilə bilər:

```
[root@localhost ali]# parted /dev/nvme0n2
GNU Parted 3.2
Using /dev/nvme0n2
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)                                                                  
(parted) mklabel msdos                                                    
Warning: The existing disk label on /dev/nvme0n2 will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes                                                               
(parted)                                                                  
(parted) mkpart                                                           
Partition type?  primary/extended? primary                                
File system type?  [ext2]? xfs                                            
Start? 2048s                                                              
End? 3GiB
(parted)                                                                  
(parted) print                                                            
Model: NVMe Device (nvme)
Disk /dev/nvme0n2: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  3221MB  3220MB  primary  xfs          lba

(parted) quit                                                             
Information: You may need to update /etc/fstab.

[root@localhost ali]#                                                     
[root@localhost ali]# udevadm settle
```

Bu komanda sistemin yeni partitionu detect edib həmin partitionu `/dev` qovluğunda yaratmasını gözləyir:

```
udevadm settle
```

## SWAP partition


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alicenab.gitbook.io/linux/redhat/redhat-administration-2-rh134/chapter-6.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
