I. test environment software tool for logical volume management in linux: vmware System platform: linux9.0 hardware configuration: two independent hard disks 2: Test steps: 1. install the second hard disk in linux; 2. partition the second hard disk. 3. convert the partition type to the linuxlvm type. 4. create a physical volume. 5. create a volume group. 6.
I. logical volume management in linux
Test Environment
Software tools: vmware
System platform: linux9.0
Hardware configuration: two independent hard disks
==================
II. test procedure:
1. install the second hard disk in linux;
2. partition the second hard disk;
3. convert the partition type to the linux lvm type;
4. create a physical volume;
5. create a volume group;
6. create a logical volume;
7. format the logical volume, mount the logical volume, and read the mount point;
8. dynamically append or reduce the size of the logical volume to verify data integrity and security;
9. lvm management operations;
==================
III. test process
1. partition the second hard disk and convert its type to linuxlvm
[Root @ www root] # fdisk/dev/sdb // partitions sdb;
Command (m for help): p // Print the partition table without any partitions
Disk/dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks IdSystem
Command (m for help): n // Create a partition;
Command action
E extended
P primary partition (1-4)
P // select the primary partition;
Partition number (1-4): 1
First cylinder (1-522, default 1 ):
Using default value 1
Last cylinder or + size or + sizeM or + sizeK (1-522, default 522): + 200 M // you can specify the partition size;
// Follow the same method to create the Second and Third Partitions. then, check the partition table to confirm that there are no errors;
Command (m for help): p
Disk/dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks IdSystem
/Dev/sdb1 1 25 200781 83 Linux
/Dev/sdb2 26 50 200812 + 83 Linux
/Dev/sdb3 51 75 200812 + 83 Linux
Command (m for help): t // you can change the partition type;
Partition number (1-4): 1 // enter the number of the Partition to be changed;
Hex code (type L to list codes): L // view the partition type code table;
0 Empty 1c Hidden Win95 FA 70 DiskSecure Mult bb Boot Wizard hid
1 FAT12 1e Hidden Win95 FA 75 PC/IX beSolaris boot
2 XENIX root 24 nec dos 80 Old Minix c1DRDOS/sec (FAT-
3 XENIX usr 39 Plan 9 81 Minix/oldLin c4 DRDOS/sec (FAT-
4 FAT16
Hex code (type L to list codes): 8e // select 8e, that is, linux lvm type;
Changed system type of partition 1 to 8e (Linux LVM)
// Set other partitions in the same way. The final result is as follows;
Command (m for help): p
Disk/dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks IdSystem
/Dev/sdb1 1 25 200781 8e Linux LVM
/Dev/sdb2 26 50 200812 + 8e Linux LVM
/Dev/sdb3 51 75 200812 + 8e Linux LVM
Command (m for help): w // Save the partition table;
The partition table has beenaltered!
Calling ioctl () to re-read partitiontable.
Syncing disks.
[Root @ www root] # reboot // restart the computer;
2. create physical volumes, Volume groups, and logical volumes, and scan and view volume information;
[Root @ www root] # pvcreate/dev/sdb1/dev/sdb2/dev/sdb3 // initialize the partition as a physical volume;
Pvcreate -- physical volume "/dev/sdb1" successfully created
Pvcreate -- physical volume "/dev/sdb2" successfully created
Pvcreate -- physical volume "/dev/sdb3" successfully created
[Root @ www root] # pvscan // scan the physical volume. The information shows that the physical volume does not belong to any volume group;
Pvscan -- reading all physical volumes (this may take a while ...)
Pvscan -- inactive PV "/dev/sdb1" is inno VG [196.08 MB]
Pvscan -- inactive PV "/dev/sdb2" is inno VG [196.11 MB]
Pvscan -- inactive PV "/dev/sdb3" is inno VG [196.11 MB]
Pvscan -- total: 3 [588.29 MB]/in use: 0 [0]/in no VG: 3 [588.29 MB]
[Root @ www root] # vgscan // scan the volume Group to create the lvmtab file and lvmtab. d Directory
Vgscan -- reading all physical volumes (this may take a while ...)
Vgscan -- "/etc/lvmtab" and "/etc/lvmtab. d" successfully created
Vgscan -- WARNING: This program does notdo a VGDA backup of your volume group
[Root @ www root] # vgcreate hdqh/dev/sdb1/dev/sdb2/dev/sdb3 // Create a volume group hdqh;
Vgcreate -- INFO: using default physicalextent size 4 MB
Vgcreate -- INFO: maximum logical volumesize is 255.99 Gigabyte
Vgcreate -- doing automatic backup ofvolume group "hdqh"
Vgcreate -- volume group "hdqh" successfully created and activated
[Root @ www root] # vgscan // scan again. an active volume group hdqh appears;
Vgscan -- reading all physical volumes (this may take a while ...)
Vgscan -- found active volume group "hdqh"
Vgscan -- "/etc/lvmtab" and "/etc/lvmtab. d" successfully created
Vgscan -- WARNING: This program does notdo a VGDA backup of your volume group
[Root @ www root] # pvscan // view the physical volume again, which belongs to the volume group hdqh;
Pvscan -- reading all physical volumes (this may take a while ...)
Pvscan -- active pv "/dev/sdb1" of VG "hdqh" [188 MB/188 MB free]
Pvscan -- active pv "/dev/sdb2" of VG "hdqh" [188 MB/188 MB free]
Pvscan -- active pv "/dev/sdb3" of VG "hdqh" [188 MB/188 MB free]
Pvscan -- total: 3 [588.29 MB]/in use: 3 [588.29 MB]/in no VG: 0 [0]
[Email = root @ www] root @ www [/email]
Root] #LvsCan // scan the logical volume. no logical volume information is found;
Lvscan -- no logical volumes found
[Root @ www root] # lvcreate-n data-L 200 hdqh // create a logical volume data in the volume group hdqh, where-n indicates name and-L indicates size;
Lvcreate -- doing automatic backup of "hdqh"
Lvcreate -- logical volume "/dev/hdqh/data" successfully created
[Root @ www root] # lvscan // scan the logical volume again to find the/dev/hdqh/data logical volume;
Lvscan -- ACTIVE "/dev/hdqh/data" [200 MB]
Lvscan -- 1 logical volumes with 200 MBtotal in 1 volume group
Lvscan -- 1 active logical volumes
3. format the logical volume, mount the logical volume, and access its Mount point;
[Root @ www root] # mkfs-t ext3/dev/hdqh/data // format the logical volume data using the ext3 file system;
Mke2fs 1.32 (09-Nov-2002)
Filesystem label =
OS type: Linux
Block size = 1024 (log = 0)
Fragment size = 1024 (log = 0)
76912 inodes, 307200 blocks
15360 blocks (5.00%) reserved for thesuper user
First data block = 1
38 block groups
8192 blocks per group, 8192 fragmentsper group
2024 inodes per group
Superblock backups stored on blocks:
8193,245 77, 40961,573 45, 221185
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 25 mounts or
180 days, whichever comes first. Usetune2fs-c or-I to override.
[Root @ www root] # mkdir/mnt/lvm // Create a mount point;
[Root @ www root] # mount/dev/hdqh/data/mnt/lvm // mount the logical volume data to the mount point;
[Root @ www root] # cd/mnt/lvm
[Root @ www lvm] # ls // The following are access operations and uninstallation;
Lost + found
[Root @ www lvm] # touch aa
[Root @ www lvm] # cp/etc/passwd ./
[Root @ www lvm] # ll
Total usage 14
-Rw-r -- 1 root 0 May 25 17: 04aa
Drwx ------ 2 root 12288 May 25 17: 03 lost + found
-Rw-r -- 1 root 1430 May 25 17: 04 passwd
[Root @ www lvm] # cd
[Root @ www root] # umount/mnt/lvm
4. lv, vg, and pv Management
---- Logical volume management
// Append a m space to the logical volume and verify the previous data;
[Root @ www root] # umount/mnt/lvm // ensure that the logical volume is not mounted and used;
[Root @ www root] # e2fsadm-L + 100/dev/hdqh/data // or use the command lvextent. the function is the same;
E2fsck 1.32 (09-Nov-2002)
Pass 1: Checking inodes, blocks, andsizes
Pass 2: Checking directory structure
Pass 3: Checking directoryconnectivity
Pass 4: Checking reference counts
Pass 5: Checking group summaryinformation
/Dev/hdqh/data: 13/63488 files (0.0% non-contiguous), 12144/253952 blocks
Lvextend -- extending logical volume "/dev/hdqh/data" to 400 MB
Lvextend -- doing automatic backup ofvolume group "hdqh"
Lvextend -- logical volume "/dev/hdqh/data" successfully extended
Resize2fs 1.32 (09-Nov-2002)
Begin pass 1 (max = 19)
Extending the inode tableXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 2 (max = 1)
Relocating blocksXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 31)
Scanning inode tableXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 5 (max = 23)
Moving inode tableXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on/dev/hdqh/data is now409600 blocks long.
E2fsadm -- ext2fs in logical volume/dev/hdqh/data successfully extended to 400 MB
[Root @ www root] # mount/dev/hdqh/data/mnt/lvm // mount the logical volume and view the content in it;
[Root @ www root] # ll/mnt/lvm
Total usage 14
-Rw-r -- 1 root 0 May 25 17: 04aa
Drwx ------ 2 root 12288 May 25 17: 03 lost + found
-Rw-r -- 1 root 1430 May 25 17: 04 passwd
[Root @ www root] # umount/mnt/lvm
// Subtract 50 m space from the logical volume and verify the previous data in it;
[Root @ www root] # e2fsadm-L-50/dev/hdqh/data
E2fsadm -- rounding size up to physicalextent boundary
E2fsck 1.32 (09-Nov-2002)
Pass 1: Checking inodes, blocks, andsizes
Pass 2: Checking directory structure
Pass 3: Checking directoryconnectivity
Pass 4: Checking reference counts
Pass 5: Checking group summaryinformation
/Dev/hdqh/data: 13/102400 files (0.0% non-contiguous), 17057/409600 blocks
Resize2fs 1.32 (09-Nov-2002)
Begin pass 3 (max = 50)
Scanning inode tableXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on/dev/hdqh/data is now356352 blocks long.
Lvreduce -- WARNING: reducing activelogical volume to 348 MB
Lvreduce -- this may destroy your data (filesystem etc .)
Lvreduce -- doing automatic backup ofvolume group "hdqh"
Lvreduce -- logical volume "/dev/hdqh/data" successfully reduced
E2fsadm -- ext2fs in logical volume/dev/hdqh/data successfully reduced to 348 MB
[Root @ www root] # mount/dev/hdqh/data/mnt/lvm
[Root @ www root] # ll/mnt/lvm
Total usage 14
-Rw-r -- 1 root 0 May 25 17: 04aa
Drwx ------ 2 root 12288 May 25 17: 03 lost + found
-Rw-r -- 1 root 1430 May 25 17: 04 passwd
[Root @ www root] # umount/mnt/lvm
[Root @ www root] # lvremove/dev/hdqh/data // remove the logical volume from the volume Group;
Lvremove -- do you really want to remove "/dev/hdqh/data "? [Y/n]: y
Lvremove -- doing automatic backup ofvolume group "hdqh"
Lvremove -- logical volume "/dev/hdqh/data" successfully removed
[Root @ www root] # lvscan // scan the logical volume again;
Lvscan -- no logical volumes found
---- Physical volume and volume Group management
// Remove the physical volume sdb2 from the volume group hdqh; but move the data to other physical volumes before the removal;
[Root @ www root] # pvmove/dev/sdb2 // move data in sdb2 to other TSL volumes;
Pvmove -- moving physical extents inactive volume group "hdqh"
Pvmove -- WARNING: if you lose powerduring the move you may need
To restore your LVM metadata frombackup!
Pvmove -- do you want to continue? [Y/n] y // confirm your operation;
/Dev/hdqh/group:/dev/hdqh/data: 08128576,081 1 8576
/Dev/hdqh/group:/dev/hdqh/data: 081216768,081 1 16768
/Dev/hdqh/group:/dev/hdqh/data: 081224960,081 1 24960
........................
/Dev/hdqh/group:/dev/hdqh/data: 0812369024,081 1 369024
/Dev/hdqh/group:/dev/hdqh/data: 0812377216,081 1 377216
/Dev/hdqh/group:/dev/hdqh/data: 0812385408,081 1 385408
Pvmove -- doing automatic backup ofvolume group "hdqh"
Pvmove -- 47 extents of physical volume "/dev/sdb2" successfully moved
[Root @ www root] # vgreduce hdqh/dev/hdqh/sdb2 // remove physical volumes from the volume group hdqh sdb2
[Root @ www root] # vgextent hdqh/dev/hdqh/sdb2 // add the physical volume to the volume group hdqh
[Root @ www root] # vgchange-a n/dev/hdqh
[Root @ www root] # vgremove/dev/hdqh