Linux扩展根文件系统
Posted dingdingfish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux扩展根文件系统相关的知识,希望对你有一定的参考价值。
有一个虚机模板,剩余空间不多了。于是在导入时指定了更大的根盘空间:100GB。
启动以后,可以看到盘确实变大了,但是接下来要扩展VG,LV和文件系统。
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_bigdatalite-lv_root
52G 39G 11G 79% /
tmpfs 15G 1.2G 14G 9% /dev/shm
/dev/sda1 477M 204M 245M 46% /boot
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 38.6G 0 part
│ ├─vg_bigdatalite-lv_root (dm-0) 249:0 0 52.5G 0 lvm /
│ └─vg_bigdatalite-lv_swap (dm-1) 249:1 0 5.1G 0 lvm [SWAP]
└─sda3 8:3 0 19.5G 0 part
└─vg_bigdatalite-lv_root (dm-0) 249:0 0 52.5G 0 lvm /
可以看到新的sda有100G空间,所以第一步是利用其空闲空间建立新分区sda4。
# fdisk /dev/sda
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
Selected partition 4
First cylinder (7649-13054, default 7649):
Using default value 7649
Last cylinder, +cylinders or +size{K,M,G} (7649-13054, default 13054):
Using default value 13054
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
需要将分区的类型改为LVM:
# fdisk /dev/sda
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): t
Partition number (1-4): 4
Hex code (type L to list codes): 8e
Changed system type of partition 4 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
重启虚机。
看到我们的sda盘是这样的:
# fdisk -l
...
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 5100 40446976 8e Linux LVM
/dev/sda3 5100 7648 20472560 8e Linux LVM
/dev/sda4 7649 13054 43423695 8e Linux LVM
...
首先建立PV:
# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created
然后利用这个PV,扩展VG:
# vgextend /dev/vg_bigdatalite /dev/sda4
Volume group "vg_bigdatalite" successfully extended
# vgdisplay "vg_bigdatalite"
--- Volume group ---
VG Name vg_bigdatalite
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 99.50 GiB
PE Size 4.00 MiB
Total PE 25472
Alloc PE / Size 14738 / 57.57 GiB
Free PE / Size 10734 / 41.93 GiB
VG UUID OfvY4R-ZO5L-r6Rb-TwMF-qQBu-CEtK-vXdc33
# vgdisplay "vg_bigdatalite" | grep "Free"
Free PE / Size 10734 / 41.93 GiB
可以看到VG有剩余10734 个PE。
于是扩展LV:
# lvextend -l+10734 /dev/vg_bigdatalite/lv_root
Size of logical volume vg_bigdatalite/lv_root changed from 52.49 GiB (13438 extents) to 94.42 GiB (24172 extents).
Logical volume lv_root successfully resized.
# lvdisplay /dev/vg_bigdatalite/lv_root
--- Logical volume ---
LV Path /dev/vg_bigdatalite/lv_root
LV Name lv_root
VG Name vg_bigdatalite
LV UUID 8vebCn-nb0A-GtfY-fgZd-ET2E-hR0J-JKKh8a
LV Write Access read/write
LV Creation host, time bigdatalite.localdomain, 2015-10-02 10:11:20 -0400
LV Status available
# open 1
LV Size 94.42 GiB
Current LE 24172
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 249:0
扩展文件系统:
# resize2fs /dev/vg_bigdatalite/lv_root
resize2fs 1.43-WIP (20-Jun-2013)
Filesystem at /dev/vg_bigdatalite/lv_root is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 6
The filesystem on /dev/vg_bigdatalite/lv_root is now 24752128 blocks long.
成功了:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_bigdatalite-lv_root
93G 39G 51G 44% /
tmpfs 15G 1.2G 14G 9% /dev/shm
/dev/sda1 477M 204M 245M 46% /boot
参考
- https://kb.vmware.com/s/article/1006371
- https://www.howtoforge.com/logical-volume-manager-how-can-i-extend-a-volume-group
之前的笔记
补充一个最常用的扩充文件系统的场景:
- extend disk in VMware Workstation(e.g. 2G)
- boot VM, use fdisk /dev/sda to create a new primary partiton
- reboot VM, then
[root@TTB ~]# fdisk -l|grep sda4
/dev/sda4 2872 3133 2104515 83 Linux
[root@TTB ~]# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created
[root@TTB ~]# vgextend VolGroup /dev/sda4
Volume group "VolGroup" successfully extended
[root@TTB ~]# lvextend /dev/VolGroup/lv_root /dev/sda4
Size of logical volume VolGroup/lv_root changed from 19.50 GiB (4991 extents) to 21.50 GiB (5504 extents).
Logical volume lv_root successfully resized
[root@TTB ~]# resize2fs /dev/VolGroup/lv_root
resize2fs 1.43-WIP (20-Jun-2013)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/VolGroup/lv_root is now 5636096 blocks long.
以上是关于Linux扩展根文件系统的主要内容,如果未能解决你的问题,请参考以下文章
Android 逆向Linux 文件权限 ( Linux 权限简介 | 系统权限 | 用户权限 | 匿名用户权限 | 读 | 写 | 执行 | 更改组 | 更改用户 | 粘滞 )(代码片段