Storage Administration
Storage Administration
Topics to be covered:
-Disk Management:
-Partitioning
-File system
-Mounting
-fstab file
-Swap management:
-LVM
-Extending/Reduce LVM
-LVM Snapshot
partition is a fix amount of disk space with start and end from the total HD
that will be mounted to Directory to be accessed. To see this space we can
use the following command
[root@server ~]#df -h
[root@server ~]#lsblk command.
Note: there is a common problem that making the partitions with the same
size, can lead to miss utilization of disk space.
Disk partitioning:
1. We need to decide either we use MBR or GPT system (note) if you
changed from GPT to MBR or Vise versa your data will be lost.
2. Use one of the following tools fdisk (MBR System) or gdisk (GPT) or
parted or gparted.
3. To see your disk and partitions via kernel we use the following
command
[root@server ~]# cat /proc/partitions
Note: if you added disk online it will not be seen via kernel until you reboot.
[root@server ~]#fdisk -l /dev/sda
After creating partition we have to create on it file system (FS) using the
command.
To check the file system and its feature dumpe2fs /dev/sdb1 (works only
with ext2/ext3/ext4 file system)
Note: for each file system have special use with mkfs, dumpe2fs, fsck,
badblocks, e2fsck commands.
Each file system has its own purpose and features that it support (max file
size, support quota, ACL, Compression, Archiving, journaling and snapshot).
In RHEL 6 we used ext4 as default file system, but in RHEL 7 we used xfs as
default file system. In the next versions of RHEL7 they used brtfs. There are
a lot of FS used in linux like GFS (Active/Active) Cluster, vFAT (windows)
and Gluster FS (DFS).
We have to create directory to be mounted and have mount point for example
/dev/sda1 ====> /test.
[root@server ~]#mount /dev/partiton_name /test
Note: we can use a lot of options -o like remount, rw, ro, quote,acl in mount
command.
[root@server ~]#umount /test ==> To disconnect the device from the mount
point.
[root@server ~]#umount -f /dev/partiton_name
If we restarted our machine we will lost our mount point because it is not
saved in a file, so we need to save our mount point to be accessed
permanently.
fstab file, This file is very critical file if something wrong with this file we
cannot boot our system normally:
2. Label mounting:
[root@server ~]#e2label /dev/sdb2 newest ==> we named our device by
label
[root@server ~]#blkid ==> to check our label
[root@server ~]#mount LABEL=newest /newest ==> to make
temporary mount.
[root@server ~]#vim /etc/fstab ==> to make it permanent mount.
3. UUID Mounting:
We can generate for the device UUID and it is unique for each device on
the system via command uuitgen /dev/sdb1 and mount the device with
its UUID in /etc/fstab.
Note: After editing in the /etc/fstab we have to test our file by using mount
command (mount -a) if it fail so there is something wrong in /etc/fstab ,but if
it is success so no action on screen.
Note: there is tools that can we use for xfs files system like xfs_admin -L
labelname /dev/sdb1 and mount -L labelname /newest.
Swap:
Swap space allows processes to use more memory than actually exists on the
system. If the amount of memory requested by the process running on the
system exceeds the amount of available RAM, the Linux kernel can swap
some of the pages of memory being used by sleeping or idle processes to disk
to make room for the additional memory needed by running processes or new
processes.
LVM provides:
1. Online Growth of File System without Data loss.
2. One or more physical volume (hard disk/ partition/RAID array, or SAN
device) are assigned to a volume group (VG).
3. Can be used to make multiple volumes.
4. Volume can span multiple disks.
5. Advanced option such as snapshot which allows you to make backup of
files even if they are open.
6. Support 15 partition and 256 logical volume.
7. If you have failing disk, you can easily replace it with new disk.
8. We can reduce the size of the volume.
LVM Make abstraction of the storage, first we create physical volumes (PV)
from this physical volumes we create a very large Storage pool, and from this
pool we can assign multiple numbers of logical volumes.
From the physical volume we have physical extents (PE), it is blocks of the
data of the storage that sometimes called chunks, default PE 4MB and can be
ranged from 1 MB to 64 MB.
LVM Implementation:
1. Create disks or partitions using fdisk
2. Change the partition tag to Linux lvm code 8e
3. Create PV
4. Test it with pvs or pvdisplay
5. Create VG give it name and test it using vgs or vgdisplay
6. Create the Logical volume and test it by lvs or lvdispaly
Lvcreate options:
-l ==> no of extends
-l 100%FREE ==> to take all free space.
-l 30%vg ==> to take 30% of the volume group
Note: both devices are pointing to /dev/dm-* where dm is the device mapper
and * means no. of devices based on the Virtual file System (VFS).
It will create device file in /dev/vg0/lv0 or /dev/mapper/vg0-lv0, now we can
use /dev/vg0/lv0 as block device.
VFS Device:
-RAID
-LVM
-LUKs
-Multipathing
Note: we can partition the logical volume and we can create the hard disk
devices into the volume group.
Resize a file system sounds easy, but you need to be very aware of what you
are doing otherwise you will end up with big mess and it will be very difficult
to fix.
To extend the file system, you can’t begin with the file system itself, you
need available disk space on LV, and to have that you need possibly space in
VG as well.
To make file system bigger, you need to start all the way from PV
1- You need to create new PV
2- You need to assign the new PV to the VG
3- You can grow the LV
4- You can extend the FS as well
Note: whenever you change an active PV, LV, or VG, unmount the volume
first.
Note: lvextend don’t extend a file system in LV automatically
Or
[root@server ~]#lvextend -r -L +1G /dev/vg0/lv1 ==> to have one step
Or
[root@server ~]#lvextend -l +100%FREE -r /dev/vg-1/lv-1
Also we have to reduce operation, which mean we need to make file system
smaller, can you imagine what happen if you take the wrong order here.
For example start with reduce the logical volume without reducing the file
system first, it will mean the fs will be bigger than the logical volume that is
below it and fsck will see the problem and going probably to mess up all your
data.
Note: xfs file system did not support reduction of the file system
Note: to reduce the size of the file system it must be unmounted first
Note: it can cause an error coz /dev/sda3 have data, So we need to move data
from physical volume to another volume.
===========================================================
Tasks:
1. Use fdisk -l to locate information about the partition sizes.
2. Use fdisk to add a new logical partition that is 2GB in size.
3. Did the kernel feel the changes? Display the content of /proc/partitions file?
What did you notice? How to overcome that?
4. Make a new ext4 file system on the new logical partition you just created.
Bonus: Try creating the ext4 filesystem with 2k blocks and one inode per
every 4k (two blocks) of filesystem.