LVM dynamic expansion

LVM Space Expansion

In the usual development work, often not large enough to create a disk of the virtual machine, and then write some data to a cluster which led to the disk is full. Manually edit the virtual machine's disk file size is not recognized by the system, most of the students could do nothing but re-installed OS, here I introduce based on LVMdynamic way.

LVM understand

LVMIs a logical disk volume management ( LogicalVolumeManager) short, it is Linuxa mechanism for disk partition management environment, LVMis built on the hard disk and partition a logical layer to increase the flexibility of the disk partition management. By LVM system administrator can easily manage disk partitions, such as: the plurality of disk partitions into a monolithic volume group ( volumegroup), forming a storage pool. Administrators can create freely on a volume group logical volume group ( logicalvolumes), and further create a file system on the logical volume group. Administrators by LVMsize can easily adjust the storage volume group, and may be named for disk storage, management and distribution in accordance with the group's way.

View Subdivision

The current default uses only one lvmpartition, at the beginning sdaof disk capacity 16G, but later found not enough, editing disk size 50G, but you can find it 50Gand did not work extended partition capacity.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@tony-play ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_tonyplay-lv_root
14G 3.4G 9.6G 26% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 477M 42M 410M 10% /boot

[root@tony-play ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 15.5G 0 part
├─vg_tonyplay-lv_root (dm-0) 253:0 0 13.9G 0 lvm /
└─vg_tonyplay-lv_swap (dm-1) 253:1 0 1.6G 0 lvm [SWAP]

Partition

Other disks may be a new expansion by my side to take is to increase the capacity of the current disk to achieve expansion.

Sometimes because the system equipment is busy, it will take effect after the partition needs to restart.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[the root @ Tony-Play ~] # the fdisk / dev / SDA 
the WARNING:. the DOS-compatible MODE IS deprecated It apos Strongly Recommended to
Switch OFF The MODE (Command 'C') and Change the display Units to
sectors (Command 'U').
the Command (m for Help): n-
the Command Action
E Extended
P Primary Partition (1-4)
P
the Partition Number (1-4):. 3
First Cylinder (2089-6527, default 2089): // direct the transport, with default values it
the using default value 2089
Last Cylinder, or Cylinders + size + {K, m, G} (2089-6527, default 6527): // direct the transport, will be able to use the default values
the using default value 6527
the Command (m Help for): w
at The Partition the Table has been the Altered!

# You can see the new partition sda3 has been created out of the junction, take all the remaining space will be the default values are assigned to the partition
[root @ Tony-Play ~] # lsblk
NAME MAJ: MIN RM MOUNTPOINT the TYPE SIZE RO
SR0 11: 1024M ROM. 1 0 0
SDA. 8: 0 0 0 50G Disk
├─sda1. 8: Part. 1 0 0 500M / Boot
├─sda2. 8: 15.5 g of 2 0 0 Part
│ ├─vg_tonyplay-lv_root (DM-0) 253: 0 13.9 g of LVM 0 0 /
│ └─vg_tonyplay-lv_swap (. 1-DM) 253: 1.6G. 1 0 0 LVM [the SWAP]
└─sda3. 8: Part. 3 0 0 34G

View the current file system

Current file systemext4

1
2
3
4
5
6
7
8
[root@tony-play ~]# mount
/dev/mapper/vg_tonyplay-lv_root on / type ext4 (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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

为新分区创建文件系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@tony-play ~]# sudo mkfs.ext4 /dev/sda3
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
2228224 inodes, 8912727 blocks
445636 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
272 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

查看卷组信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@tony-play ~]# vgdisplay
--- Volume group ---
VG Name vg_tonyplay // 卷组名在下面扩展中会用到
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 15.51 GiB
PE Size 4.00 MiB
Total PE 3970
Alloc PE / Size 3970 / 15.51 GiB
Free PE / Size 0 / 0
VG UUID Y9usSM-nDU5-ZAUd-Y3Te-u5Pd-uFBr-gcYHf0

创建新物理卷

1
2
[root@tony-play ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created

扩展到卷组

1
2
vgextend vg_tonyplay /dev/sda3  // 卷组名在查看卷组信息中
Volume group "vg_tonyplay" successfully extended

查看逻辑分区

/dev/vg_tonyplay/lv_root就是根分区,也是我们要扩展的分区。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@tony-play ~]# lvdisplay 
--- Logical volume ---
LV Path /dev/vg_tonyplay/lv_root // 根分区
LV Name lv_root
VG Name vg_tonyplay
LV UUID IPd7lm-Sx8g-pe7k-llNL-j1wc-mbA2-2cAdsy
LV Write Access read/write
LV Creation host, time tony-play, 2017-04-10 17:58:53 -0400
LV Status available
# open 1
LV Size 13.91 GiB
Current LE 3561
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Path /dev/vg_tonyplay/lv_swap
LV Name lv_swap
VG Name vg_tonyplay
LV UUID qX637q-iD6i-8blp-hmmS-MvLy-xZ0y-b4D0BF
LV Write Access read/write
LV Creation host, time tony-play, 2017-04-10 17:59:07 -0400
LV Status available
# open 1
LV Size 1.60 GiB
Current LE 409
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

扩展容量到逻辑分区

1
2
3
[root@tony-play ~]# lvextend /dev/vg_tonyplay/lv_root /dev/sda3
Size of logical volume vg_tonyplay/lv_root changed from 13.91 GiB (3561 extents) to 47.91 GiB (12264 extents).
Logical volume lv_root successfully resized

刷新逻辑分区容量使扩展生效

ext4resize2fsxfsxfs_growfs

1
2
3
4
5
6
[root@tony-play ~]# resize2fs /dev/vg_tonyplay/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_tonyplay/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 3
Performing an on-line resize of /dev/vg_tonyplay/lv_root to 12558336 (4k) blocks.
The filesystem on /dev/vg_tonyplay/lv_root is now 12558336 blocks long.

查看逻辑分区容量

It can be found /dev/mapper/vg_tonyplay-lv_rootalready from the beginning of the 14Gextension to 48G. ok, which shows you're done, no longer have to reinstall the system expansion through this lame way

1
2
3
4
5
6
[root@tony-play ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_tonyplay-lv_root
48G 3.4G 42G 8% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 477M 42M 410M 10% /boot

summary

At this point, lvmthe process of expansion work should be more clear, then there is a chance I will add LVMcompression, or delete operation.

Original: Big Box  LVM dynamic expansion


Guess you like

Origin www.cnblogs.com/chinatrump/p/11584600.html