lvm partition
Test environment centos 6.5
Borrow the picture as follows
1. The
traditional file system of LVM principle , for example, this disk is only 300G, then the file system built on this 300G can only use 300G at most, but with the LVM function, the disk that we build the file system is not built on the physical disk It is based on a logical volume called LV. This volume is a logical concept, not a physical disk. The space may be larger than a physical disk or may be smaller than a physical disk. And the space of this LV logical volume can be expanded and reduced, which provides better support for the upper file system.
Several concepts that need to be understood:
PV (Physical Volume): The meaning of physical space actually refers to a partition (such as / dev / sdb1) or a disk (such as / dev / sdb)
VG (Volume Group): equivalent to a Pool, pool
LV (Logical Volume) composed of multiple PVs : used to build a file system space, this space comes from VG, the size is arbitrary, and can be expanded. (For example, the directory / dev / mapper / rhel-root is actually a file system mount point. This point is carried on an LV. The size of the file system is the size of the LV.)
Second, the actual operation
1. Use fdisk -l to check the status of the disk. You can see that I have two unpartitioned disks, namely / dev / sdb / dev / sdc. Let's test with a disk / dev / sdb first.
[root@test_iptables ~]# fdisk -l Disk /dev/sdb: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 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: 0x00000000 Disk /dev/sda: 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: 0x0005b552 Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 2350 18566144 83 Linux /dev/sda3 2350 2611 2097152 82 Linux swap / Solaris Disk /dev/sdc: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 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: 0x00000000
2. Partition / dev / sdb
(1) Standard partition first
[root@test_iptables ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x34c351e7. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-130, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): Using default value 130 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
(2) View the name of the existing volume group using vgdisplay
[root@test_iptables ~]# vgdisplay
No volume groups found
(3) Start lvm processing
Create Physical Volume (PV)
[root@test_iptables ~]# pvcreate /dev/sdb1 dev_is_mpath: failed to get device for 8:17 Physical volume "/dev/sdb1" successfully created
Create Volume Group (VG)
[root@test_iptables ~]# vgcreate vg01 /dev/sdb1 Volume group "vg01" successfully created
View the created physical volumes and volume groups
Create a logical volume named date with a size of 1000M on volume group vg01
[root@test_iptables ~]# lvcreate -L 1000M -n data vg01 Logical volume "data" created
3. Format the partition
[root@test_iptables ~]# mkfs.ext4 /dev/vg01/data 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 64000 inodes, 256000 blocks 12800 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=264241152 8 block groups 32768 blocks per group, 32768 fragments per group 8000 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 33 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
4. Mount the partition
[root@test_iptables ~]# mkdir /u01 [root@test_iptables ~]# mount /dev/vg01/data /u01/ [root@test_iptables ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 9.2G 7.4G 56% / tmpfs 931M 72K 931M 1% /dev/shm /dev/sda1 291M 39M 238M 14% /boot /dev/mapper/vg01-data 985M 18M 918M 2% /u01
5. Set auto-mount at boot
[root@test_iptables ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed Sep 11 09:19:25 2019 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=fe5d2642-dc89-45a2-963a-2a5e0f7e5a3a / ext4 defaults 1 1 UUID=e356222c-cde8-4f30-a38c-3fcf905b65c8 /boot ext4 defaults 1 2 UUID=4d5bbee9-6557-4b6b-a275-4c43b14dce9d swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/vg01/data /u01 ext4 defaults 0 0
At this point, a lvm partition is set up
3. PV expansion
1. First standard partition
root@test_iptables ~]# fdisk /dev/sdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x114bf00d. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-130, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): Using default value 130 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
2. Create a physical volume
[root@test_iptables ~]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created
3. VG expansion
Add a new physical volume to the volume group
[root@test_iptables ~]# vgextend vg01 /dev/sdc1 Volume group "vg01" successfully extended
Expand the logical volume and resize2fs to load the logical volume
[root@test_iptables ~]# lvextend -l +100%FREE /dev/vg01/data Extending logical volume data to 1.98 GiB Logical volume data successfully resized [root@test_iptables ~]# resize2fs /dev/vg01/data resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg01/data is mounted on /u01; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/vg01/data to 520192 (4k) blocks. The filesystem on /dev/vg01/data is now 520192 blocks long.
So far, the above is the entire process, successfully expanded to 2G.