I. LVM logical volume Management
1. Definition
Logically combine multiple physical partitions/disks into a larger whole, and divide different logical partitions. The size of logical partitions can be expanded and reduced as needed.
2. LVM Concept
PV: physical volume
VG: volume group (which can contain 65534 PES)
LV: logical volume that truly stores data
PV physical volume ---> VG volume group ---> LV logical volume ---> Format ---> mount the File System
3. LVM management commands
Function physical volume group logical volume
Scan pvscanvgscanlvscan
Create (create) pvcreatevgcreatelvcreate
Display (Display) pvdisplayvgdisplaylvdisplay
Remove (remove) pvremovevgremovelvremove
Extend (extended) vgextendlvextend
Reduce vgreducelvreduce
4. Usage
Pvcreate device name...
Vgcreate volume group name physical volume...
Lvcreate-l size-N logical volume name volume group name
Lvextend-L + size/dev/volume group name/logical volume name (move the PE of VG to LV)
Resize2fs/dev/volume group name/logical volume name
Vgcreate-s specifies the PE size
Lvcreate-l pe count
Ii. Soft Raid disk array Management
1. Raid Definition
Low-cost redundant disk array. using hardware/software technology, multiple small/low-speed disks are integrated into a large disk, which not only can store data, but also can provide certain protection for data.
2. Raid level
Raid0: The Strip mode is composed of two or more disks. The same document is distributed across different disks, and parallel writing improves efficiency.
Raid1: The image mode is composed of two or more disks. A file is written to different disks. The data on each disk is the same, which provides fault tolerance and improves Read efficiency.
Raid1 + 0/raid0 + 1: integrates the advantages of raid0 and raid1. Parallel access improves efficiency. Image writing improves reliability
RAID5: combine the benefits of raid0 and raid1 while avoiding their shortcomings. Consists of more than three disks of the same size, providing Redundancy
3. Raid implementation
Hard raid: high performance. Dedicated RAID card configuration is required.
Soft Raid: It is simulated by software in Linux, and the efficiency is poor.
4. Create a soft RAID
Mdadm-C array name [Option] member Disk
-C create
-L specify the raid level
-N: number of specified member Disks
-X number of redundant Disks
-V: Detailed Execution Process Information
5. simulate a fault
Mdadm array name [Option] member Disk
-F mark a member disk as a fault
-R: Remove a member disk.
-A: Add a member disk.
6. View raid Arrays
-D: display details
-E. View super fast information.
-S: scanning the running Array
7. enable/disable raid Arrays
Mdadm-s disabled
Mdadm-A Enabled
8./proc/mdstat record the status of the running Array
9./etc/mdadm. conf stores the fixed settings of the raid array.
Exercise 1: Create a volume group
1) prepare three 10 Gb free partitions and change the type ID to 8E (LVM)
2) create a volume group named myvg using two of the partitions to view the volume group information.
A) Check the physical volumes first.
B) convert two idle partitions into physical volumes.
C) Check the physical volumes and view the details of one of them.
D) first check which volume groups are available
E) merge two physical volumes into a volume group myvg
F) check which volume groups are available and view the detailed information of the volume group myvg.
######################################## #################################
[[Email protected] ~] # Fdisk-l
[[Email protected] ~] # Fdisk/dev/SDB
Command (M for help): n
Command action
E extended
P primary partition (1-4)
P
Partition Number (1-4): 1
First cylinder (1-10443, default 1 ):
Using default value 1
Last cylinder or + size or + sizem or + sizek (1-10443, default 10443): + 10g
Command (M for help): n
Command action
E extended
P primary partition (1-4)
P
Partition Number (1-4): 2
First cylinder (1218-10443, default 1218 ):
Using default value 1218
Last cylinder or + size or + sizem or + sizek (1218-10443, default 10443): + 10g
Command (M for help): n
Command action
E extended
P primary partition (1-4)
P
Partition Number (1-4): 3
First cylinder (2435-10443, default 2435 ):
Using default value 2435
Last cylinder or + size or + sizem or + sizek (2435-10443, default 10443): + 10g
Command (M for help): p
Command (M for help): T
Partition Number (1-4): 1
HEX Code (type L to list codes): 8E
Changed system type of partition 1 to 8E (Linux LVM)
Command (M for help): T
Partition Number (1-4): 2
HEX Code (type L to list codes): 8E
Changed system type of partition 2 to 8E (Linux LVM)
Command (M for help): T
Partition Number (1-4): 3
HEX Code (type L to list codes): 8E
Changed system type of partition 3 to 8E (Linux LVM)
Command (M for help): p
Command (M for help): W
[[Email protected] ~] #
[[Email protected] ~] # Pvcreate/dev/sdb1
[[Email protected] ~] # Pvcreate/dev/sdb2
[[Email protected] ~] # Pvcreate/dev/sdb3
[[Email protected] ~] # Pvcreate/dev/sdb1
[[Email protected] ~] # Pvcreate/dev/sdb2
[[Email protected] ~] # Pvcreate/dev/sdb3
[[Email protected] ~] # Vgcreate myvg/dev/SDB [1-2]
[[Email protected] ~] # Pvscan
[[Email protected] ~] # Pvscan/dev/sdb1
[[Email protected] ~] # Vgscan
######################################## ###################################
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/54/wKioL1PnZPaQHjE9AAQ5n9Rf7W0395.jpg "style =" float: none; "Title =" sogou 20140804250519.png "alt =" wkiol1pnzpaqhje9aaq5n9rf7w0395.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/54/wKiom1PnY96RMX8OAAMlP6GQ1wk021.jpg "style =" float: none; "Title =" sogou 20140804250540.png "alt =" wkiom1pny96rmx8oaamlp6gq1wk021.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/54/wKioL1PnZPiwnBfUAAQorbKm6JU404.jpg "style =" float: none; "Title =" sogou 20140804250616.png "alt =" wkiol1pnzpiwnbfuaaqorbkm6ju404.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/54/wKiom1PnY-CTrmBFAAXqzAT8AkU809.jpg "style =" float: none; "Title =" sogou 20140804251217.png "alt =" wKiom1PnY-CTrmBFAAXqzAT8AkU809.jpg "/>
Exercise 2: Create/use/extend logical volumes
1) divide a 16 GB logical volume named lvmbox to view the logical volume information
2) format the logical volume as an ext3 file system and mount it to the/mbox directory.
3) enter the/mbox directory to test read/write operations.
4) Extend the logical volume from 16 GB to 24 GB to ensure the size of DF recognition is accurate
A) first expand the volume group (add a 10 Gb physical volume) and then expand the logical volume
B) resize2fs identifies the size of the New File System
5) create a logical volume lvtest with a size of MB
######################################## ###################################
[[Email protected] ~] # Lvcreate-L 16g-N lvmbox myvg
[[Email protected] ~] # Lvscan
[[Email protected] ~] # Mkfs. ext3/dev/myvg/lvmbix
[R [email protected] ~] # Mkdir/mbox
[[Email protected] ~] # Mount/dev/myvg/lvmbox/mbox
[[Email protected] ~] # Mount
[[Email protected] ~] # Cd/mbox
[[Email protected] mbox] # Touch test.txt
[[Email protected] mbox] # ls
Lost + found test.txt
[[Email protected] mbox] # cd
[[Email protected] ~] # Pvcreate/dev/sdb3
Writing physical volume data to disk "/dev/sdb3"
Physical Volume "/dev/sdb3" successfully created
[[Email protected] ~] # Vgextend myvg/dev/sdb3
[[Email protected] ~] #
[[Email protected] ~] # Lvextend-L 24g/dev/myvg/lvmbox
Extending logical volume lvmbox to 24.00 GB
Logical volume lvmbox successfully resized
[[Email protected] ~] # DF-H
[[Email protected] ~] # Resize2fs/dev/myvg/lvmbox
[[Email protected] ~] # DF-H
[[Email protected] ~] # Lvcreate-l 250-N lvswap myvg
Rounding up size to full physical extent 252.00 MB
Logical volume "lvswap" created
[[Email protected] ~] # Lvscan
Active '/dev/myvg/lvmbox' [24.00 GB] inherit
Active '/dev/myvg/lvswap' [252.00 MB] inherit
[[Email protected] ~] #
######################################## ###################################
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/54/wKioL1PnZaryAuBpAATcl74UmT4842.jpg "style =" float: none; "Title =" sogou 20140804254.png "alt =" wkiol1pnzaryaubpaatcl74umt4842.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/54/wKiom1PnZJLQBz1KAAXJe1WHRrs638.jpg "style =" float: none; "Title =" sogou 20140804252236.png "alt =" wkiom1pnzjlqbz1kaaxje1whrrs638.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/54/wKioL1PnZayghOHTAAU7B7rFPXw669.jpg "style =" float: none; "Title =" sogou 20140804252512.png "alt =" wkiol1pnzayghohtaau7b7rfpxw669.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/54/wKiom1PnZJSRxB0XAAF4zbDtboQ927.jpg "style =" float: none; "Title =" sogou 20140804252716.png "alt =" wkiom1pnzjsrxb0xaaf4zbdtboq927.jpg "/>
Exercise 3: comprehensive logical volume Application
1) Delete the volume group myvg created in the previous exercise
2) use two physical volumes to form a vgnsd volume group and the other physical volume to form a vgdata volume group.
3) create a 20 GB logical volume lvhome from the volume group vgnsd
4) create a 4G logical volume lvswap from the volume group vgdata
5) migrate the/home directory to the logical volume lvhome
6) Extend the logical volume lvswap to the swap space
7) configure automatic mounting for steps 5th and 6, and verify after restart
######################################## ###################################
[[Email protected] ~] # Umount/dev/myvg/lvmbox
[[Email protected] ~] # Lvremove/dev/myvg/lvmbox
Do you really want to remove active logical volume lvmbox? [Y/n]: Y
Logical volume "lvmbox" successfully removed
You have mail in/var/spool/mail/root
[[Email protected] ~] # Vgremove/dev/myvg
Do you really want to remove volume group "myvg" containing 1 logical volumes? [Y/n]: Y
Do you really want to remove active logical volume lvswap? [Y/n]: Y
Logical volume "lvswap" successfully removed
Volume group "myvg" successfully removed
[[Email protected] ~] # Vgscan
Reading all physical volumes. This may take a while...
No volume groups found
[[Email protected] ~] # Lvscan
No volume groups found
[[Email protected] ~] # Vgcreate vgnsd/dev/SDB [1-2]
Volume group "vgnsd" successfully created
[[Email protected] ~] # Vgcreate vgdata/dev/sdb3
Volume group "vgdata" successfully created
[[Email protected] ~] # Lvcreate-L 4G-N lvswap vgdata
Logical volume "lvswap" created
[[Email protected] ~] # Lvscan
Active '/dev/vgdata/lvswap' [4.00 GB] inherit
[[Email protected] ~] # LV create-l 4772-N lvhome vgnsd
Logical volume "lvhome" created
[[Email protected] ~] # Lvscan
Active '/dev/vgdata/lvswap' [4.00 GB] inherit
Active '/dev/vgnsd/lvhome' [18.64 GB] inherit
[[Email protected] ~] # Mkdir/opt/home
[[Email protected] ~] # Cp-RPF/home/*/opt/home
[[Email protected] ~] # Mkfs. ext3/dev/vgnsd/lvhome
[[Email protected] ~] # Mount/dev/vgnsd/lvhome/home
[[Email protected] ~] # Cp-RPF/opt/home/*/home
[[Email protected] ~] # Mkswap/dev/vgdata/lvswap
Setting up swapspace version 1, size = 4294963 KB
[[Email protected] ~] # Swapon/dev/vgdata/lvswap
[[Email protected] ~] # Free-m
[[Email protected] ~] # Vim/etc/fstab
/Dev/vgnsd/lvhome/home ext3 defaults 0 0
/Dev/vgdata/lvswap swap defaults 0 0
[[Email protected] ~] # Mount
[[Email protected] ~] # DF-H
[[Email protected] ~] # Free-m
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/54/wKiom1PnZMzjQcwJAAVDqypghVg095.jpg "style =" float: none; "Title =" soudog 20140804184007.png "alt =" wkiom1pnzmzjqcwjaavdqypghvg095.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/54/wKioL1PnZebQ2ykUAAMqR0btmdI068.jpg "style =" float: none; "Title =" soudog 20140804184254.png "alt =" wkiol1pnzebq2ykuaamqr0btmdi068.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/54/wKiom1PnZM2TOhudAAGDOxQ1A3w540.jpg "style =" float: none; "Title =" soudog 20140804184632.png "alt =" wkiom1pnzm2tohudaagdoxq1a3w540.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/54/wKioL1PnZefRi-anAAJu7hYs8_0436.jpg "style =" float: none; "Title =" sogou 20140804184910.png "alt =" wKioL1PnZefRi-anAAJu7hYs8_0436.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/54/wKiom1PnZM7wigHBAAJTXYOsTFg636.jpg "style =" float: none; "Title =" soudog 20140804185052.png "alt =" wkiom1pnzm7wigg1_ajtxyostfg636.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/54/wKioL1PnZeiwcDWgAAUFIjy-lH8361.jpg "style =" float: none; "Title =" sogou 20140804185150.png "alt =" wKioL1PnZeiwcDWgAAUFIjy-lH8361.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/54/wKiom1PnZNDSaTDbAALhur5BiLo772.jpg "style =" float: none; "Title =" soudog 20140804194217.png "alt =" wkiom1pnzndsatdbaalhur5bilo772.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/54/wKioL1PnZerCNAHaAAQ0JtzPLvg570.jpg "style =" float: none; "Title =" soudog 20140804195053.png "alt =" wkiol1pnzercnahaaaq0jtzplvg570.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/54/wKioL1PnZerjFzZ5AAGcIV6DF44836.jpg "style =" float: none; "Title =" soudog 20140804195635.png "alt =" wkiol1pnzerjfzz5aagciv6df44836.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/54/wKiom1PnZNLAHeEOAAEHu1mLFQE359.jpg "style =" float: none; "Title =" soudog 20140804195911.png "alt =" wkiom1pnznlaheeoaaehu1mlfqe359.jpg "/>