Linux Notes 5.0

Source: Internet
Author: User
Tags file copy lowercase readable uuid

Command
Hexdump Viewing binary files
-n the number of bytes before the output file is formatted
-C Output Specification 16 binary and ASCII code
LSBLK Viewing block devices
Fdisk creating an MBR partition
Gdisk creating a GPT partition
Parted advanced partitioning operations
Partprobe synchronous memory and hard disk partition table information (CENTOS7)
PARTX Synchronizing partition information (CENTOS6)
Mkfs Creating a file system
MKE2FS creating file systems for the EXT series
Bkid viewing block device tag information (Uuid,label)
E2label Manage Ext File System tags
Uuidgen Generating UUID
Findfs Find Partitions
TUNE2FS setting ext File system parameters
DUMPE2FS viewing ext file system block grouping information
FSCK detects and repairs file systems
E2fsck for Ext file system detection and Repair
Xfs_repair detection and repair for XFS file systems
Mount Mount
Umount Uninstall
Mkswap Creating a Swap partition
DF View information such as file system space consumption
Du view usage space (size of file and directory disk)
DD Copy and transform files
Mdadm managing raid
PVS Displays physical volume information
Pvdisplay more detailed physical volume information
Pvcreate Creating PV
Pvmove Moving physical volumes (can automatically select other members under the same volume group)
Pvremove Deleting physical volumes
VGs Displaying volume group information
Vgdisplay
Vgcreate
Vgextend Extended Volume Group
Vgreduce Shrinking a volume group
Vgremove
Vgexport Exporting a volume group
Vgimport Importing a volume group
LVS Display Logical Volume information
Lvdisplay
Lvcreate
Lvextend
Lvreduce
Lvremove

Disk storage and file management
All documents:
function type file: Open (), read (), write (), close () (System function called by operation on the file)
Device type file: (/dev/)
Block Device (b): block, Access Unit "block", (1k,2k,4k) Typical: Disk
Character device (c): Char, Access unit "character", typical:/dev/zore,/dev/null
Device files: Linked to a device driver to communicate with the corresponding hardware device
Device number: Main device number (for device type), secondary device number (device number under the same type)
Create device file: Mkmod/path/name b|c Main Number

Hard Disk interface type
Parallel:
IDE:133MB/S (RARE)
SCSI:640MB/S (RARE)
Serial:
sata:6gbps, approx. 750mb/s (commonly used in home PCs)
sas:6gbps (more for server)
usb:480mb/s
Rpm:rotations per minute (rpm per minute)

HDD Type:
Mechanical HDD (HDD): Hard disk drive, traditional HDD.
SSD: Solid state drives, hard drives made of solid state electronic storage chip arrays
Difference:
1, performance: SSD in shock and drop, transmission rate, power consumption, weight, noise significantly better than HDD,SSD transmission rate performance is

Twice times the HDD
2. Price: HDD is superior to SSD in price, capacity and service life.
Present situation:
Currently SSD does not completely replace HDD (hard disk price, data priceless: HDD has an absolute advantage in the recoverability of data)

Device file naming
Device file name for disk device:/DEV/SD
Different disk identities: A-Z
Different partitions on the same device: 1, 2, ... (Primary and extended partition 1-4, representing logical partitions from 5 onwards)

Hard disk storage Terminology
Head: Head
Track: Tracks
Sector: Sector (one sector 512bytes)
Cylinder: Cylinder surface
CHS (disk three-dimensional):
With 24bit-bit addressing, the first 10bit represents cylinder, the middle 8bit represents head, and the last 6bit represents sector
Maximum addressing space: 8g=[(1024*255) byte/1024/1024]g
CHS can only represent a maximum of 8G, and it will have to use the LBA method
LBA (Logical Block Addressing):
Describe hard disk structure using ZBR (Zoned Bit recording, location record disk sector structure)
The number of sectors stored in each track is different, the outer ring is many, the inner ring is small
LBA (Logical Block addressing) with 48bit bit addressing
Maximum addressing space 128PB

The use of hard disk three major strides:
1. Partitioning
2. Create File System: Format
3. Mount: Assign directory Name
Note: The hard disk does not use the above operation directly, can save data, but the total number of binary

Partition
Objective:
Optimizing I/O performance
To implement quota limits for disk space
Improved repair speed
Isolating systems and programs
Install multiple OS
Using different file systems
Partitioning method:
MBR, GPT
Two ways to match the corresponding hardware program:
Early motherboard built-in BIOS with MBR
Built-in UEFI mate GPT for newer boards

MBR (master boot record, Master boot recording):
Use 32-bit to indicate sector number, partition not more than 2T
By cylinder Division (cylinder=512 255, about 8MB), dividing the size of the integer multiples of 8MB, CENTOS6 began to press the sector

Divided
0 Track 0 Sector store partition information:
Total size: 512bytes
Boot loader (boot mount): 446bytes
Partition table: 64bytes (one partition is represented by 16byte)
55AA (partition End ID): 2bytes
Partition structure:
3 primary partitions + one extended partition (contains n logical partitions)
Note: Partition table information for logical partitions in an extended partition does not exist in the primary partition table, but is present in the logical partition's own small space
Backup partition Table information:
DD IF=/DEV/SDA of=/data/mbr_bak Bs=1 count=512 (local backup)
Scp/data/mbr_bak IP Address:/data (local backup to network server)
Clone partition Table information:
DD IF=/DEV/SDA of=/dev/sdb Bs=1 count=512 (clone SDA hard disk partition table information to SDB)
Attention:
1, SDB>=SDA
2. Only the primary partition table can be cloned

Gpt
A GUID (Globals unique Identifiers, globally unique identifier) partition table supports 128 partitions, using

64-bit, support 8Z (512byte/block) 64Z (4096byte/block)
Use UUID (universally unique Identifier, Universal unique identifier) to represent the disk and partition GPT partition table, automatic backup in head and tail two parts, and CRC check Bit

Managing partitions
List block Devices:
Lsblk
To create a partition:
Fdisk: Creating an MBR partition
Gdisk: Creating a GPT partition
Parted: Advanced partitioning operations
Partprobe: Synchronizing memory and hard disk partition table information

parted command
Operation takes effect in real time, use carefully
PARTED/DEV/SDA Mklabel Gpt|msdos Creating a partition type
Mkpart Primary 1 200 (default m) create primary partition
RM Area Code Delete partition
-l list partition information

Fdisk and Gdisk commands
FDISK manages MBR partitions, Gdisk manages GPT partitions (two command usage is basically the same)
Fdisk-l Viewing partition information
FDISK/DEV/SDA Managing Partitions
P: Partition list
T: Change the partition type
N: Create new Partition (P (primary) master, E (Extended), L (logical) logic)
D: Delete partition
V: Verify Partition
U: Conversion Unit
W: Save exit
Q: Do not save exit

Synchronizing partitioned Tables
Fdisk-l View the partition table information on the hard disk
LSBLK is looking at the partition table information in memory
Cat/proc/partitions viewing partition table information in the kernel
After modifying the partition table, the hard disk and memory, the partition table information in the kernel will be different, synchronous operation is required at this time
Partprobe (CENTOS5|7)
Partx-a/DEV/SDA used when SDA adds a partition
partx-d--nr Area code/DEV/SDA used when SDA deletes a partition

Creating a file system
What is a file system:
The method and data structure used by the operating system to explicitly store files on a device or partition, that is, the method of organizing files on the storage device. The software structure that manages and stores the file information in the operating system becomes a file management system, referred to as file system
Function:
Responsible for creating files, depositing, reading, modifying, dumping files, controlling file access, security control, log, compression, encryption, etc.
Supported file systems:
/lib/modules/ uname -r /kernel/fs folder to store supported file systems

File System classification:
Classification by operating system:
Linux:
Ext (Extended file system, extended filesystem) 2,3,4 (mainstream), XFS (SGI), Btrfs (Oracle), ReiserFS, JFS (AIX), swap
Disc:
iso9660
Windows:
FAT32 (4G or more files not supported), ExFAT (U-disk), NTFS
Unix:
FFS (FAST), UFS (Unix), JFS2
Network File system: (Across network access, equivalent to shared folders)
Nfs,cifs
Clustered file System: (cluster, multiple servers can access one storage device at a time)
GFS2,OCFS2 (Oracle)
Distributed File System:
Fastdfs,ceph, Moosefs, MogileFS, Glusterfs, Lustre
RAW: (No file system, pursuit of high performance, but not easy to manage)
Unprocessed or unformatted file system

On Time Support Journal (log) feature classification:
Log function: First read the operation of the file from memory, and then pass the operation to the file. Ensures file system security and does not damage files being modified due to power-down
journaled file system: ext3,4, XFS, ...
Non-Datejust: ext2, VFAT

Part of the file system:
Modules in the kernel: Ext4, XFS, VFAT
User-space management tools: MKFS.EXT4, MKFS.XFS, Mkfs.vfat
Virtual file system for Linux: VFS
To view the currently supported file systems: Cat/proc/filesystems

Report:
The difference between buffer and cache
Cache caching: Caching of Read-in data for read caching facilitates the next visit
Buffer buffering: Buffering of written data for write buffering, and so on system idle writing files

Features of the file system
Single node:
XFS (supports extra-large capacity), Ext4, Btrfs
Network/Multi-node:
GFS2 (allows multiple servers to be accessed concurrently, using the cluster environment)

Creating a file system
MKFS command:
mkfs.ext4|xfs|./dev/device (equipment)
Mkfs-t ext4|xfs| ...
-L "label (label, TAG)": Set volume label

MKE2FS Command (EXT Series file system dedicated management tool):
-T ext2,3,4
-B 1024|2048|4096: Setting the minimum storage cell size
-L "LABEL"
-j: Equivalent to-t ext3
-I #: Create an inode for each number of bytes in the data space, which should not be less than the size of the block
-N #: Specify how many inode to create in a partition
-L: The amount of disk space occupied by an Inode record, 128--4096
-M #: Reserved space for administrators as a percentage of total space (default 5%)
-o Feature: Enable specified features
-O ^ function: Turn off specified function

File System Tags
Role:
Another way to point to a device (device-independent)
Blkid command:
Viewing block device Property information
-U uuid: Find the corresponding device based on the specified UUID
-L Label: finds the corresponding device according to the specified label
E2label command:
Manage the label of the EXT series file system
E2label DEVICE LABEL
Findfs command:
Find partitions
Findfs label=: Search by volume label
Findfs uuid=: Finding on UUID condition

TUNE2FS command:
Reset the value of the EXT series file system adjustable parameters (only for Ext file system)
-L: View specified file system Super block information (super blocks)
-L LABEL: Modify volume label
-M #: Percentage of space reserved for administrators
-j: Upgrade ext2 to Ext3
-O: File System Properties enabled or disabled (^)
-O: Adjust default mount options for the file system (^)
-U uuid: Modify the UUID number (used with UUID generated by the Uuidgen command)
Don't change the UUID easily because the device is usually indicated with a UUID when writing a configuration file
DUMPE2FS command:
View Block grouping information
-H: View Super block information, do not display grouping information

File system detection and Repair
Often occurs after a crash or abnormal shutdown
Mount file system labeled "No clean"
Note: Do not fix in Mount State (DF command to view mount status)
fsck command:
Fsck. Fs_type|-t fs_type: Specify the file system (the system will automatically detect, usually do not need to be specified by the person)
-P: Automatic repair
-R: Interactive Repair
-Y: Auto Answer Yes
-F (Force): Forced repair (sometimes corruption may occur even if clean is displayed)
E2fsck: Similar to fsck,fsck in the fix is called e2fsck
When the file system is XFS, use XFSrepair to fix
XFS File System Administration command: XFS
... (tab to see all options)

Mount
What is mounted: (Mount)
Establish an association between an additional file system and an existing directory on the root file system, allowing this directory to access the file system as a different file
mount point: Directory
What is uninstall: (Umount)
The process of releasing this association relationship
You can use the device name when uninstalling, or use a mount point
The device that the process is in use cannot be uninstalled
Attention:
1, Mount point under the original file will be hidden after the mount is completed (unlike hidden files), so the mount point directory is best empty
2, two file systems (devices) cannot be mounted to the same directory (mount point), a file system can be mounted to multiple directories

Mount File System
Mount Command:
Show all devices that are currently mounted by viewing the/etc/mtab/file first
Specify the mounted device:
1, Equipment files: example/DEV/SD ...
2, Volume Label:-L LABEL
3. Uuid:-u UUID
4. pseudo File system name
Specify the mount point:
Dir: Pre-existing, recommended use of empty directory
Options:
-T: Indicates the file system of the mounted device (usually not added, the system can be automatically detected)
-R (ReadOnly): Read-only Mount
-W (Read and write): Read-write Mount
-N: Not updated/etc/mtab,mount not visible (play hidden mount action)
-A: Automatically mounts all devices that support automatic mounts (defined in the/etc/fstab file with auto function in the Mount option)
-b,--bind: Bind directory to another directory
To view all mounted devices tracked by the kernel: cat/proc/mounts

-O (option): Mount the file system options, multiple options separated by commas
Async: Asynchronous mode (write file is written to buffer first, write to disk when idle)
Sync: Synchronous mode, when memory changes, write hard disk simultaneously
Atime/noatime: Access timestamp for directories and files (default noatime)
Diratime/nodiratime: Access timestamp for directory
Auto/noauto: Whether auto mount is supported, that is, whether the-a option is supported
Exec/noexec: Whether to support running applications on the file system
Dev/nodev: Whether to support the use of device files on this file system
Suid/nosuid: Whether Suid and Sgid permissions are supported
Remount: Re-mount (can be mounted again when the process is in use)
RO: Read-only
RW: Read and Write
User/nouser: Whether to allow the normal user to mount the device, the use of the/etc/fstab
ACL: Enable the ACL feature on this file system
Loop: Using a loop device (used to mount a file system using a file as a device)
CENTOS6: The default is only 8 loop devices, more than the limit need to build a loop device (Mknod) also need to modify permissions, batch increase

Add loop device: Kernel Last added max_loop= specified value in the/boot/grub/grub.conf file
CENTOS7: Unlimited
To create a file associated with a loop device by using the Losetup command
Defaults (default): equivalent to Rw,suid,dev,exec,auto,nouser,async

Unloading
The device that the process is in use cannot be uninstalled
Check the Mount condition first:
Findmnt Mount_point|device
Then view the process that is accessing the specified file system:
Lsof Mount_point
Fuser-v Mount_point
Terminates all processes that are accessing the specified file system: (use cautiously)
fuser-km Mount_point
Last Uninstall:
Umount Device|mount_point

File-mounted configuration file
Role:
Mount command mounted file system cannot be saved after a system restart
To permanently save the Mount configuration, you need to write it into the/etc/fstab file
Use the Mount-a command to mount all file systems in the/etc/fstab, activate with the command when a new configuration is added to the file, and activate with the Mount-o rmount command when there are configuration modifications in the file
Defined:
/etc/fstab each row defines a file system to mount
Six major items:
1, device identification: UUID, LABEL, device name
2, Mount point
3. File system type
4. Mount option: Defaults 、...、
5, Backup frequency: 0 (not backup), 1 (daily Backup), 2 (Backup every other day), but need to use the Backup tool with
6, self-test sequence: 0 (not self-test), 1 (first self-test, generally only rootfs use), 2, ... The self-test sequence executes sequentially
Attention:
1. When mounting a device with file emulation, the device identifier cannot be used with UUID, file path, mount option with loop
2, mount the CD-ROM, device identification with the device name, the file system type is iso9660

Experiment 1:
Migrate/home to new partition
1, Backup/home/ *
2, create a new disk partition (Fdisk|gdisk)
3, create file System (MKFS)
4, Create a temporary Mount folder/mnt/home and Mount (Mkdir,mount)
5 to prevent users from accessing the Modify/home file, switch to single-user mode (init 1, this mode is not networked)
This step is not recommended, to notify the user of the migration time, Make sure no users are migrated at/home-access
6, migrate files under/home to/mnt/home (CP-AV)
7, Check for Migration results (LS/HOME/MNT/HOME-L)
8, delete/home files, free space (RM-RF/ home/ * )
9, write the new partition to/etc/fstab (VIM, example: Uid=xxx/home ext4 default 0 0)
10, unmount the temporary mount point and Delete (UMOUNT,RM)
11, If you switch to single-user mode, you will have to cut the mode back (init 5) When you are finished migrating

Swap partitions and files
function:
When the system is out of memory, take the hard drive to simulate memory (occasionally used, if you frequently use the instructions memory needs to be upgraded)
Hard disk requirements: High-performance hard disk, the same hard disk heretics better than inner path
Free command: View system memory and swap
Create swap partition
created with physical partition:
1, create partition
2, mkswap Create file System
3, add entry in/etc/fsabe file
UUID Swap swap Default,[pri=value (value)] (Set priority value, higher priority) 0 0
4, swapon-a activate swap space
created with file:
1, create file (dd If=/dev/zore of=/swapfile bs=1024m count=2)
2, Mkswap/swapfile
3, vim/etc/fstab
/swapfile swap swap default 0 0
4, swapon-a
Note:
The swap partition created by the physical partition has better performance than the swap partition created by the file
Swap command options:
-A: Activate all swap partitions
-P (priority): Specify precedence
-S: View all active swaps
Swapoff: Disable swap partition

Moving Media
Before you visit, be sure to mount
Before removal, be sure to uninstall
Mount points are usually under/media or/mnt
Disc:
Auto-start mount in graphical environment, otherwise it must be manually mounted
Mount/dev/cdrom/mnt
Eject command to unmount or eject a disc
-T: Bouncing into a disc
To create an ISO image file:
Cp/dev/cdrom/path/centos#.iso
DD If=/dev/cdrom Of=/path/centos#.iso
Packaging folders to make ISO files:
Mkisofs-r-o/path/xxx.iso/path
Mkdvdios script, Usage: mkdvdiso.sh source (sources, can be multiple)/path/dvdiso
To burn a disc:
Wodim-v-eject Centos.iso
Usb:
To see if the USB device recognizes:
Lsusb
Detected by kernel as SCSI device (/DEV/SD ... )
Automatically mounted in a graphical environment, otherwise it must be mounted manually
MOUNT/DEV/SD ... /mnt
Note: When the file is copied to U disk, because the system default async mode, so that the display copy of the data is still in buffer, more than a few times sync command to synchronize the data into the U disk, to prevent file copy failure

Common tools
Df:
View information such as file system space consumption
-H: In 1000 units
-T: Show file system type
-H: Displayed in human readable units
-I: Show node number
-P: Output in POSIX-compatible format (automatically aligns the format when there are too long filenames)

Du
Viewing directory space Occupancy information
-H: Display k,m,g in human readable units (default unit k)
-S: Total directory size
--max-depth=#: Specify maximum Depth #

DD:
Copy and Transform files
Usage: dd if= of= bs= count= skip= seek= conv=
if= of= bs= count= copy files and convert and format the contents of the original file
if from file input (read ) (/dev/zore/All-zero character device)
of output (write) to file
BS specifies block size
count specifies number of blocks written
Skip skips how many blocks of the input file
seek skips the number of blocks before the output file
Conv Convert file
Transform parameters with specified parameters:
ASCII: convert EBCDIC to ASCII
EBCDIC: convert ASCII to EBCDIC
LCase: Uppercase characters convert to lowercase characters
UCase: lowercase characters converted to uppercase characters
Nocreat: Do not create output file
NoError: Error does not stop
Notrunc: Output file is not truncated
Sync: input block is not sufficient for empty characters
Fdatasync: Write directly to disk without writing to buffer

Raid
What is raid:
redundant Arrays of inexpensive Disks (inexpensive redundant array of disks)
multiple disks synthesize an "array" to provide better performance, redundancy, or both provide a
effect:
Improved IO capability: Parallel disk read and write
improves durability: Disk redundancy for
implementation:
Hard raid:
Add-On: Adapter available via expansion card
Internal: Motherboard integrated RAID controller
configuration in BIOS before installing OS
Soft raid:
Software RAID: implementation of
Level via OS: different ways to work together with multiple disks
RAID-0: Stripe (Strip) storage, read/write performance improvement, no fault tolerance (minimum two HDD) (Disk utilization 100%)
RAID-1: Image (mirror) storage, read ability, write ability drop, fault tolerance (2) (50%)
raid-3:0 based on multiple data disk XOR operation, the value is stored on the Special Check Disk (3) (n-1/n)
Raid-5:3, Checksum is also striped storage, read and write performance improved, fault-tolerant, allow up to 1 disk damage (3) (n-1/n)
Raid-6:5 on the basis of a check, read and write ability to improve, fault-tolerant, allow up to 2 disk damage (4) (n-2/n)
RAID-10: First do 221 groups of 1, and then set 1 to do 0, read and write ascension, there is fault tolerance, each group of images can only be broken One Piece (4) (when 6 hard disk, a piece of damage, the system failure rate of 1/5) (Performance Best!!!)
RAID-01: First do 0, then the two groups of 0 Composite 1, read and write ascension, there is fault tolerance, there can only be a set of mirror damage (4) (when 6 hard disk, a piece of damage, system failure rate 3/5)
RAID-50: Do 5 in the first 0, good performance, high cost
JBOD (Just a Bunch of Disks): Just combine multiple disk space into a single large continuous space to use, performance does not improve
RAID-7: Self-contained operating system and management tools, can run independently, theoretically highest performance RAID mode
Common level:
0,1,5,10,50,jbod

Soft raid (not common in production, mostly hard raid)
Mdadm command:
provide a management interface for soft RAID
Add redundancy to free disks
combine with MD in kernel (multi (check) devices)
The RAID device can be named/dev/md{0,1,...}
Command usage:
Mode:
-C: Create
-A: Assemble
-F: Monitor
Admin mode:
-F: flag specifies disk as corrupted
-A: Add Disk
-r: Remove disk
Create raid:
Mdadm -c/dev/md#-A yes-l#-C #-N #-X #/dev/device ...
-C: Create Mode
-A: Automatically create a device file for a target RAID device
-L: Indicates the level to be created
-C (chunk): Indicates the block size, Unit K (default)
-N: Indicates the number of devices that created the raid
- X: Indicates the number of standby devices
-D: Displays details of the raid
Cat/proc/mdstat: observing the MD status
-G: Extended raid, adding new members (with-a use), and then synchronizing the member file system when added:
RESIZE2FS/ dev/md# (EXT series)
Xfs_growfs/path/mount_point (XFS series)

Experiment 2
Create raid-5:
1, create partition, the same size (hard disk directly use, partition to use T to change type to FD)
2. Mdadm command Creation (mdadm-c/dev/md0-a yes-l5-c 32-n 3-x 1/dev/sd ... )
3, mkfs.ext4/dev/md0
4, Vim/etc/fstab
5, mdadm-ds/dev/md0 >/etc/mdadm.conf (generate config file)
Test:
Mdadm-s/dev/md0 Stop device (first umount)
MDADM-AS/DEV/MD0 activating the device
Mdadm-r/dev/md0 forced start
Simulated damage:
Mdadm/dev/md0-f/dev/sd# Mark Damage
Mdadm/dev/md0-r/dev/sd# Delete
Mdadm/dev/md0-a/dev/sd# Add

Create raid-10
Suppose a,b,c,d four hard drives
Method 1:
Mdadm-c/dev/md0-a Yes-l1-n2/dev/sd{a,b}
Mdadm-c/dev/md1-a Yes-l1-n2/dev/sd{c,d}
Mdadm-c/dev/md2-a yes-l0-n2/dev/md{0,1}
Method 2:
Mdadm-c/dev/md0-a Yes-l10-n4/dev/sd{a,b,c,d}

Delete raid
1. un-mount (guaranteed no access)
2. Delete the corresponding configuration in/etc/fstab
3, Rm-f/etc/mdadm.conf
4. View the partition that made up the raid (-D)
5. Stop device (-s)
6. Delete the partition that made up the raid
7. Delete the raid residue information on disk (Mdadm--zero-supperblock/dev/partition)

Lvm
What is LVM:
Logical Volume Manager, logical Volume Manager
A layer of abstraction that allows for easy operation of the volume, including resizing the file system
Behavior:
Allows the file system to be re-organized between multiple physical devices
Designate a device as a physical volume (physical volume is defined with a fixed-size physical region (physical extend,pe))
Create a volume group with one or more physical volumes
Create a logical volume on a physical volume (made up of PE)
You can create a file system on a logical volume
Advantage:
Easy to expand space
Principle:
1, pvcreate implementation: block devices--physical volumes (ordinary hard disk into a physical volume)
2, Vgcreate implementation: Physical volumes---volume group (combining physical volumes into one volume group)
3. Lvcreate implementation: Volume group-to-logical volumes (divides the volume group into logical partitions)
Essence:
The logical volume created is actually pointing to/dev/dm-#的软连接
Dm:device Mapper (device mapping)
LVM changes the file system's capacity:
Managed by exchanging PE, transferring PE from LV to other devices to reduce LV capacity and adding PE to V in other devices

To increase capacity (by expanding or shrinking the operation of the PE)

Management tools
PV Tools
PVS: displaying physical volume information
Pvdisplay: More detailed physical Volume information
Pvcreate: Creating PV
Pvmove: Moving physical volumes (automatically select other members under the same volume group)
Pvremove: Deleting physical volumes

VG Tool
VGS: Display Volume Group information
Vgdisplay
Vgcreate
Vgextend: Extending a volume group
Vgreduce: Shrinking a volume group
Vgremove (Remove the PV in the volume group before deleting the VG)
Vgexport: Exporting a volume group
Vgimport: Importing a volume group

LV Tool
LVs: Display Logical Volume Information
Lvdisplay
Lvcreate
-N: Specify logical Volume name
-L: Specify the size (number of blocks) followed by #% is the percentage of blocks that specify the number of remaining blocks
-L: Specify size (capacity)
Lvextend (Synchronize the file system with the RESIZE2FS command after expansion or directly with the-r option)
Specify size # (expand to) |+# (extension)
Lvreduce: Reduce the logical volume size
lvremove

Experiment 3:
LVM Management
1, create:
Create a physical Volume: Pvcreate device ... (Can create multiple simultaneously)
Create Volume Group: Vgcreate-s # (Specify PE size) volume group name Physical volume device ...
Create Logical Volume: Lvcreate-n lv0 (Specify logical volume name)-L # (%free) (Specify number of PE blocks) Volume group name
Create file system: mkfs.ext4/dev/volume Group/Logical Volume
Mount: Mount
2, Extension: (Supports disk expansion directly on Mount)
to create a new hard disk as a physical volume
to join a volume group: vgextend to expand the volume group New physical Volume
Extended Logical Volume: lvextend-r (Synchronous file System for Ext file system)-L # (add to) |+# (plus) (Specify PE size) to extend the logical volume
3, Reduce:
Reduce the logical Volume:
Uninstall: Umount
Check file completion: fsck-f or e2fsck-f
Shrink file system: RESIZE2FS (reset file system size)
Reduced Logical Volume: Lvreduce
Mount: Mount
Shrink Volume Group:
Move: Pvmove
Remove from volume Group: vgreduce
Remove Remove Pv:pvremove
4, migrate volume groups across hosts
See PV on the hard drive: Pvdisplay
If the VG in the PV distribution on different hard disk, you need to move PV to a hard disk: Pvmove
Remove the empty PV (previously moved PV): Vgreduce
View the volume group name and logical volume name before migrating to the new machine roll group name , logical volume name conflict, if the conflict requires a prior renaming:
Vgrename, Lvrename
unmount The logical volume on the volume Group: Umount
Disable volume Group: Vgchange-an
Export the volume Group: Vgexport
Remove the drive to the new machine
Identify new device: Echo '---' >/sys/class/scsi_host/host2/scan
Import Volume Group: Vgimport
Enable volume Group: Vgchange-ay
Mount: Mount

Logical Volume Snapshot
What is a snapshot:
Snapshots are special logical volumes
When a snapshot is generated, it is allocated space, but the snapshot only consumes space when the original logical volume is different, that is, when the original logical volume data is modified, the old data is copied to the snapshot, the unchanged data is not taken as a snapshot, and usually the 15%-20% of the original logical volume is required to create the snapshot (the snapshot cannot be larger You can use Lvextend to extend the snapshot size
Attention:
Snapshots and logical volumes must be in the same volume group
Snapshots are not a substitute for backup functionality, and snapshots can become corrupted when the hard disk on which the logical volume is located is corrupted
Snapshots can be used in experimental environments to restore pre-lab data, or CP databases
To create a snapshot:
Lvcreate-n Snapshot name-S (snapshot, indicates that the snapshot was created)-L size-P R (Increase read-only property to avoid misoperation on snapshot)/path/lv (specifies who to take a snapshot of)
To recover a snapshot:
Unload logical volumes and snapshots first
Merging logical volumes and snapshots:
Lvconvert--merge Snapshot
Note: Once a snapshot is merged, it will be automatically deleted
To delete a snapshot:
Unmount Snapshot First
Lvremove Snapshot
Report:
Ext and XFS Snapshot differences:
Ext file System Creating a snapshot without the-P r option will result in the inability to merge logical volumes and snapshots without affecting the XFS file system
XFS File System mount snapshot causes mount failure due to the same snapshot and corresponding logical volume UUID, with the-o nouuid option, the Ext file system does not require

Linux Notes 5.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.