Перейти к содержанию

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:

  1. 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)

  2. Unmount new filesystem from temprorary directory.

  3. Mount new filesystem to the /home or do next point.

  4. 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 (use blkid, grep and cut -d' ' -f2).
    Don't forget about another required information in that row: mounted directory, filesystem, mount options, dump flag, fscheck flag.

  5. 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:

  1. Create a new PV from new partition.

  2. Extend the VG

  3. Extend LV

  4. Show to filesystem a new size of LV by resize2fs command

    Warning

    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:

echo 'DEVICE /dev/hd*[0-9] /dev/sd*[0,9]' > /etc/mdadm.conf
Next command add to mdadm.conf information about current RAID:
mdadm --detail --scan >> /etc/mdadm.conf
Information about RAID status can be displayed with dmadm --detail in state section: clean, degraded, spare rebuilding.

Linux software RAID creation check-list:

  1. Create a partitions on the disks leaved some free space.

  2. Create new mddevice by mdadm with --create key.

  3. Check information about just created RAID by mdadm --detail /dev/$MD_NAME

  4. Save current config by comamnds listed above.

  5. Create file system or LVM physycal volumes.

  6. Edit /etc/fstab.

  7. If need to add disks: prepare it and add by mdadm --add command