Disks
When udev see some device it create particular files in /dev
. Using these files, OS can interact with devices.
Because to work with any type of disks SCSI protocol are used - all type of disks will be named like "sd{a,b,c..z}". Optical drive - sr{0,1..n}. Virtual drive - vd{a,b..z}
For work with disk, usually need to do next jobs:
-
Create partition table (MBR or GPT)
-
Create parititions. In this point have nessesery information about MBR partition table:
Info
In MBR can create max 4 primary partitions. For create logical partitions, first of all need to create extended partition.
-
Create filesystem
-
Mount file system to FHS
For example, if needs to move /home directory to another disk, need to do next:
-
Move all data from
/home
to another place.1.1. Close all processes which use target directory.
1.2. Specifically in this case, need to close GUI session and start new virtual terminal with a root session.
1.3. Ensure that there are not open files from target directory.
1.4. Check and remeber the target directory size, for a better understanding how many space are requred in the new partition.
1.5. Prepare new disk: create partition table, partitions, filesystem
1.6. Temporary mount new partition to some place if FHS. Usually this place is
/mnt
directory.1.7. Ensure that there new filesystem has been mounted
1.8. Move or copy files from target directory to the new directory.
1.9. Ensure that all files moved correctly (compare the sizes)
-
Unmount new filesystem from temprorary directory.
-
Mount new filesystem to the
/home
or do next point. -
Permanetly add information about mount point of the new disk.
4.1. Discover the information about UUID of the filesystem in the new disk.
4.2. Ensure that you have a backup of the original fstab file.
4.3. Write down recived UUID to the
/etc/fstab
(useblkid
,grep
andcut -d' ' -f2
).
Don't forget about another required information in that row: mounted directory, filesystem, mount options, dump flag, fscheck flag. -
So how OS know where to mount filesystem, just mount this filesystem by
mount /home
Info
If files was copied, not moved - change owner and group of the copied directory/files with -R
key.
Another one wondwerful software to work with disks - Gparted. It's GUI programm and it literally can copy/cut and paste partitions!
LVM
For flexible work with disks use LVM (Logical Volume Manager). LVM allow to union several disks/partitions to create common virtual space. In base of them, perhaps to create logical volumes.
LVM uses following entities in its work:
-
partitions and disks - physical volumes - PV
-
common space from PV - volume group - VG
-
partitions in VG - logical volume - LV
LVM allow to add partitions and disks to VG, and expand LV without having to stop work with disk.
To create LVM partition need to create LVM entities in next order: PV -> VG -> LV
When LV has been created, in /dev/
apear two nested directories was named as VG name and LV name - /dev/myvg/mylv
which is a soft link to a /dev/$SOME_NAME
which generated by udev.
Finally, filesystem create in the LV and should be wright in /etc/fstab
. For that purpose instead UUID use /dev/mapper/$VG_NAME-$LV_NAME
.
In case of the end of free space, you can add a new disk to LVM:
-
Create a new PV from new partition.
-
Extend the VG
-
Extend LV
-
Show to filesystem a new size of LV by
resize2fs
commandWarning
Run
resize2fs
only if LV was extended without -r key.**
LVM snapshots
Also, LVM provide snapshots of data has stored in it.
When you create a LVM snapshot, choose how much space will be use to snapshots. LVM use copy-on-write technology, they allow to copy old blocks of data to special space in disk, before new data will be write on the blocks.
So how data has no many changes, snapshot size can be less than target LV.Shapshot LV can be mounted as like ordinary partition.
For restore data from snapshot need to umount this snapshot and target LV and then merge snapshot with LV. After that, snapshot LV was delete, It remains onlyto mount the target LV partition. Creating snapshots its a good practice before updates or backups.
RAID
For improve availability information, often use RAID (redundant array of indepen det disks).
RAID can be hardware and software based.
Linux software based RAID is are virtual devices created from two or more real block device.
Linux software based RAID create and mantain with module "md" (multiply device driver) and mdadm utility.
RAID devices named like md###
, where ###
is random integer number
RAID has a few levels:
-
RAID0 (stripping) - blocks divide to the same lenght fragments and write to two or more disks sequentally in turn
-
RAID1 (mirroring) - all blocks write to two or more disks simultaneously.
-
RAID 10 (RAID 1+0) - like mirroring RAID1
Danger
Because all disks are not totally same, they are can differ for a few number of sectors, in the proccess of creation of RAID, leave some free space.
Information about RAID devices store in /etc/mdadm.conf
(in another distr can be another place, clarify this point by man
).
Next command creates list of partitions which OS will check to present of the RAID after start:
Next command add to mdadm.conf information about current RAID: Information about RAID status can be displayed withdmadm --detail
in state section: clean, degraded, spare rebuilding.
Linux software RAID creation check-list:
-
Create a partitions on the disks leaved some free space.
-
Create new mddevice by
mdadm
with--create
key. -
Check information about just created RAID by
mdadm --detail /dev/$MD_NAME
-
Save current config by comamnds listed above.
-
Create file system or LVM physycal volumes.
-
Edit
/etc/fstab.
-
If need to add disks: prepare it and add by
mdadm --add
command