Create an instance[Root @ www ~] # Fdisk/dev/sdb partition/dev/sdb
WARNING: DOS-compatible mode is deprecated. It's stronugly recommended
Switch off the mode (command 'C') and change display units
Sectors (command 'U ').
Command (m for help): nn indicates creating a new partition.
Command action
E extended indicates the extended partition.
P primary partition (1-4) indicates the primary partition
P input batch to create a primary Partition
Partition number (1-4): 1. Enter the Partition number/dev/sdb1.
First cylinder (1-2610, default 1): Press enter to start from the First cylinder
Using default value 1
Last cylinder, + cylinders or + size {K, M, G} (1-2610, default 2610): + 5G partition size is 5 Gb. You can also enter the number of cylinders.
Command (m for help): p to view the partition information of the Disk
Disk/dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x07a95eb7
Device name start cylindrical end cylindrical block size system Id type
Device Boot Start End BlocksId System
/Dev/sdb1 1 6545253223 + 83 Linux
Command (m for help): w save and exit
Thepartition table has been altered!
Callingioctl () to re-read partition table.
Syncingdisks.
Check whether partition operations are written to the system kernel[Root @ www ~] # Cat/proc/partitions
Major minor # blocks name
8, 0, 26214400, sda
8 1 512000 sda1
8 2 25701376 sda2
816 20971520 sdb
817 5253223 sdb1
When the kernel cannot read the partition table on the hard disk, run the following command to run the partx command:
[Root @ www ~] # Partx-a/dev/sdb1/dev/sdb
To create a file system, use mkfsmkfs. ext [2 | 3 | 4] and mke2fs to create a file system. Generally, use mke2fs.Mkfs-t ext2 = mkfs. ext2 = mke2fs-t ext2
Mkfs-t ext3 = mkfs. ext3 = mke2fs-t ext3
Mkfs-t ext4 = mkfs. ext4 = mke2fs-t ext4
Mke2fsMke2fs-t type Device: What type of file system is created
Mke2fs-B {1024 | 2048 | 4096} block size of the Device Partition
[Root @ www ~] # Mke2fs-text4-B 2048/dev/sdc2
Mke2fs 1.41.12 (17-May-2010)
Filesystem label =
OS type: Linux
Block size = 2048 (log = 1)
Fragment size = 2048 (log = 1)
Stride = 0 blocks, Stripe width = 0 blocks
197880 inodes, 1578386 blocks
78919 blocks (5.00%) reserved for the superuser
First data block = 0
Maximum filesystem blocks = 538968064
97 block groups
16384 blocks per group, 16384 fragments pergroup
2040 inodes per group
Superblock backups stored on blocks:
16384,49152, 81920,114 688, 147456,409 600, 442368,802 816, 1327104
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 24 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.
[Root @ www ~] # Tune2fs-l/dev/sdc2 | grep "Block size"
Block size: 2048
[Root @ www ~] # Blkid/dev/sdc2
/Dev/sdc2: UUID = "ac40a50d-ddee-44b0-a6a8-481e7b33a548" TYPE = "ext4"
The default value for mke2fs creation is ext2.
[Root @ www ~] # Mke2fs/dev/sdb1
Mke2fs 1.41.12 (17-May-2010)
Filesystem label =
OS type: Linux
Block size = 4096 (log = 2)
Fragment size = 4096 (log = 2)
Stride = 0 blocks, Stripe width = 0 blocks
328656 inodes, 1313305 blocks
65665 blocks (5.00%) reserved for the superuser
First data block = 0
Maximum filesystem blocks = 1346371584
41 block groups
32768 blocks per group, 32768 fragments pergroup
8016 inodes per group
Superblock backups stored on blocks:
32768,98304, 163840,229 376, 294912,819, 884736
Writing inode tables: done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 24 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.
Mke2fs configuration file/etc/mke2fs. conf[Defaults]
Base_features = sparse_super, filetype, resize_inode, dir_index, ext_attr ext2 File System by default
Blocksize = 4096 default block size
Inode_size = 256
Inode_ratio = 16384
Add the following features values to the default partition file system after base_features: ext3 or ext4.
[Fs_types]
Ext3 = {
Features = has_journal
}
Ext4 = {
Features = has_journal, extent, huge_file, flex_bg, uninit_bg, dir_nlink, extra_isize
Inode_size = 256
{
Tune2fs-l [DEVICE] has rich information displayed.View the block size
[Root @ www ~] # Tune2fs-l/dev/sdb1 | grep "Block size"
Block size: 4096
Run the blkid command to view the UUID and file system type.[Root @ www ~] # Blkid/dev/sdb1
/Dev/sdb1: UUID = "8595c196-9c41-4bfb-8b76-4930705e6c12" TYPE = "ext2"
Mount a File SystemMount-t type Device mount point
Mount command to view the file system mounted by the current system
[Root @ www ~] # Mount
/Dev/mapper/vg_centos-lv_root on/typeext4 (rw)
Proc on/proc type proc (rw)
Sysfs on/sys type sysfs (rw)
Devpts on/dev/pts type devpts (rw, gid = 5, mode = 620)
Tmpfs on/dev/shm type tmpfs (rw)
/Dev/sda1 on/boot type ext4 (rw)
None on/proc/sys/fs/binfmt_misc typebinfmt_misc (rw)
Sunrpc on/var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)
Nfsd on/proc/fs/nfsd type nfsd (rw)
The/etc/mtab file can also be used to view the mounting status of the current system. The result of the mount command is from this file.
[Root @ www ~] # Cat/etc/mtab
/Dev/mapper/vg_centos-lv_root/ext4 rw 0 0
Proc/proc rw 0 0
Sysfs/sys sysfs rw 0 0
Devpts/dev/pts devpts rw, gid = 5, mode = 620 00
Tmpfs/dev/shm tmpfs rw 0 0
/Dev/sda1/boot ext4 rw 0 0
None/proc/sys/fs/binfmt_misc binfmt_miscrw 0 0
Sunrpc/var/lib/nfs/rpc_pipefs rpc_pipefsrw 0 0
Nfsd/proc/fs/nfsd rw 0 0
The mount command is valid at the time of mounting. If the system restarts, the file system to be mounted will be sucked into the/etc/fstab file.
LVMLVM is a Logical volume management Logical VolumeManager. It manages disk partitions in Linux. LVM is a Logical layer built on hard disks and partitions, to improve the flexibility of disk partition management
The LVM creation sequence is PV --> VG --> LV. You do not know whether the default LVM is used when CentOS is installed by default.
Preparations before creationChange the system ID of the partition to 8e (Linux LVM)
[Root @ www ~] # Fdisk/dev/sdc
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): p
Disk/dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0xbeaf1b91
Device Boot Start End BlocksId System
/Dev/sdc1 1 6545253223 + 83 Linux
/Dev/sdc2 655 10473156772 + 8e Linux LVM
LVM creation process
Pvcreate Device
[Root @ www ~] # Pvcreate/dev/sdc2
Physical volume "/dev/sdc2" successfully created
[Root @ www ~] # Pvcreate/dev/sdb1
Physical volume "/dev/sdb1" successfully created
2. [root @ www ~] # Vgcreate testvg/dev/sdb1/dev/sdc2
Volume group "testvg" successfully created
3. [root @ www ~] # Lvcreate-L 5G-ntestlv testvg
Logical volume "testlv" created
Verify that the lv has not been created
[Root @ www ~] # Lvdisplay/dev/testvg/testlv
--- Logical volume ---
LVPath/dev/testvg/testlv
LV Nametestlv
VG Name testvg
LVUUID UiuqXG-22fG-qKoz-dFzw-oHvP-OZYY-aOII0F
LVWrite Access read/write
LVCreation host, time www.linux.com, 20:21:14 + 0800
LVStatus available
# Open 0
LVSize 5.00 GiB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 2
Create a File System
[Root @ www ~] # Mke2fs-text4/dev/testvg/testlv
Mount a File System
[Root @ www ~] # Mount-t ext4/dev/testvg/testlv/mnt
[Root @ www ~] # Mount
/Dev/mapper/vg_centos-lv_rooton/type ext4 (rw)
Procon/proc type proc (rw)
Sysfson/sys type sysfs (rw)
Devptson/dev/pts type devpts (rw, gid = 5, mode = 620)
Tmpfson/dev/shm type tmpfs (rw)
/Dev/sda1on/boot type ext4 (rw)
Noneon/proc/sys/fs/binfmt_misc type binfmt_misc (rw)
Sunrpcon/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
Nfsdon/proc/fs/nfsd type nfsd (rw)
Gvfs-fuse-daemonon/root/. gvfs type fuse. gvfs-fuse-daemon (rw, nosuid, nodev)
/Dev/sr0on/media/CentOS_6.4_Final type iso9660 (ro, nosuid, nodev, uhelper = udisks, uid = 0, gid = 0, iocharset = utf8, mode = 0400, dmode = 0500)
/Dev/mapper/testvg-testlvon/mnt type ext4 (rw)
LVM Usage Details vg
Vg volume group Expansion
Prepare a pv
[Root @ www ~] # Pvcreate/dev/sdb2
Physical volume "/dev/sdb2" successfully created
Expand the capacity of vg
Run vgextend command vgextend vgname Device
[Root @ www ~] # Vgextendtestvg/dev/sdb2
Volume group "testvg" successfully extended
[Root @ www ~] # Vgs
Couldn't find device with uuid 2QpQ6S-B9Oz-7PB1-fIKo-Lhdw-h00t-3EtX00.
VG # PV # LV # SN Attr VSizeVFree
VG 2 0 0wz-pn-8.02g 8.02g
Testvg 31 0 wz -- n-15.02g 10.02g
Vg_centos 1 2 0wz -- n-24.51g 0
2. vg volume group reduction
Move the data on the pv to another pv.
[Root @ www ~] # Pvmove/dev/sdb1
/Dev/sdb1: Moved: 0.1%
/Dev/sdb1: Moved: 64.8%
/Dev/sdb1: Moved: 100.0%
Vgreduce command to reduce vg vgreduce vgname Device
[Root @ www ~] # Vgreducetestvg/dev/sdb1
Removed "/dev/sdb1" from volume group "testvg"
3. Delete the vg volume group
[Root @ www ~] # Vgremove testvg
Volume group "testvg" successfully removed
LvLv Extension
First, check whether the volume group of the lv is in sufficient space.
1. Expand physical boundaries
[Root @ www ~] # Lvextend-L + 2G/dev/testvg/testlv
Extending logical volume testlv to 7.00 GiB
Logical volume testlv successfully resized
2. Extend logical boundaries
[Root @ www ~] # Resize2fs/dev/testvg/testlv
Resize2fs 1.41.12 (17-May-2010)
Filesystem at/dev/testvg/testlv is mountedon/mnt; on-line resizing required
Old desc_blocks = 1, new_desc_blocks = 1
Ming an on-line resize of/dev/testvg/testlv to 1835008 (4 k) blocks.
The filesystem on/dev/testvg/testlv is now1835008 blocks long.
3. Check that the lv extension is successful.
[Root @ www ~] # Df-lh
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/vg_centos-lv_root
23G 17G4. 2G 81%/
Tmpfs 935M0 935 M 0%/dev/shm
/Dev/sda1 485 M 47M414M 11%/boot
/Dev/mapper/testvg-testlv
6.9G 140M6. 5G 3%/mnt
Lv reduction
Before reducing the lv, you must uninstall it and forcibly detect the file system.
[Root @ www ~] # Umount/dev/testvg/testlv
[Root @ www ~] # Fsck-f/dev/testvg/testlvfsck is a file system detection tool. The-f parameter is added to indicate forced detection.
Fsck from util-linux-ng 2.17.2
E2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/Dev/mapper/testvg-testlv: 12/458752 files (0.0% non-contiguous), 64448/1835008 blocks
If the file system is not detected, garbled characters may occur during future use.
Reduce logical volume
Resizefs Device size
[Root @ www ~] # Resize2fs/dev/testvg/testlv 5G
Resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on/dev/testvg/testlv to 1310720 (4 k) blocks.
2. Reduce physical volumes
[Root @ www ~] # Lvreduce-L5G/dev/testvg/testlv
WARNING: switching active logical volume to 5.00 GiB
This may destroy your data (filesystem etc .)
Do you really want to reduce testlv? [Y/n]: y
Cing logical volume testlv to 5.00 GiB
Logical volume testlv successfully resized
3. Remove the lv volume
A) uninstall the lv volume mount
B) Use lvremove Device to remove the lv volume
[Root @ www ~] # Umount/mnt
[Root @ www ~] # Lvremove/dev/testvg/testlv
Do you really want toremove active logical volume testlv? [Y/n]: y
Logical volume "testlv" successfully removed
Verify
[Root @ www ~] # Lvs
Couldn't find device with uuid 2QpQ6S-B9Oz-7PB1-fIKo-Lhdw-h00t-3EtX00.
Lv vg Attr LSizePool Origin Data % Move LogCpy % Sync Convert
Lv_root vg_centos-wi-ao --- 22.57g
Lv_swap vg_centos-wi-ao --- 1.94g
Note:Lvreduce-L [+ |-] size Device indicates how much space is added or reduced on the basis of the original volume size.
Lvreduce-L size Device indicates how much space the original volume is directly extended.
The LVM cut sequence is LV --> VG --> PV.
This document: http://down.51cto.com/data/1877421