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 1045 7875584 8e Linux LVM
[root@CNGI-SIP6-BUPT ~]# fdisk /dev/sda
Command (m for help): m
Command (m for help): n //创建分区
Command action
e extended
p primary partition (1-4)
p //创建主分区
Partition number (1-4): 3 //创建id号为3的分区
First cylinder (2611-5221, default 2611): 2611 //指定开始位置
Last cylinder or +size or +sizeM or +sizeK (2611-5221, default 5221): 5221 //结束位置
Command (m for help): t //改变分区系统id
Partition number (1-4): 3 //指定分区号
Hex code (type L to list codes): 8e //指定要改成的id号,8e代表LVM。
Command (m for help): w
我们现在还不能用这个分区 , 因为我们没格式化。这时要重启系统就能够在 dev 下面看到 sda3 ,如果不重启不能进行下面操作。
重启后,在此查看fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1044 8281507+ 8e Linux LVM
/dev/sda3 1045 2088 8385930 8e Linux LVM
可以看到/dev/sda3已支持LVM。
输入【reboot】 重启Linux,必须reboot,否则/dev/sda4无法格式化。
这时在/dev/目录下,才能看到了新的分区比如/dev/sda4
【mkfs.ext2 /dev/sda4】格式化
在根目录下创建disk4目录
【mount /dev/sda4 /disk4/】将分区mount到/disk4/上
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 1045 7875584 8e Linux LVM /dev/sda3 1045 3916 23066662 83 Linux
当然,这时候用ls /dev是看不到sd3的。因为还没格式化。
sudo mkfs -t ext3 /dev/sda3 现在也是报错的。 Could not stat /dev/sdb3之类的。
既然上次已经提示了要reboot,那就roboot一下吧。
[sss@localhost ~]$partprobe
还是出现同样的警告。难道还是不行?
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
管他呢,执行一下格式化吧。
[sss@localhost ~]$sudo mkfs -t ext3 /dev/sda3
居然OK了!这不吓唬人吗?
[sss@localhost ~]$ ll /dev/sda3
brw-rw----. 1 root disk 8, 3 Jan 6 10:33 /dev/sda3
嘿嘿,已经有了哦
然而,看看磁盘空间呢?怎么还是这几个分区呢
[sss@localhost ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_vm-lv_root 6.7G 6.5G 83M 99% /
tmpfs 495M 80K 495M 1% /dev/shm
/dev/sda1 485M 326M 134M 71% /boot
sudo fdisk -l也可以发现,还是只有一个LVM的分区。
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 1045 7875584 8e Linux LVM
/dev/sda3 1045 3916 23066662 83 Linux
[sss@localhost ~]$ sudo pvcreate /dev/sda3
dev_is_mpath: failed to get device for 8:3
Physical volume "/dev/sda3" successfully created
这里有一个failed,以为出问题了呢,结果下面又success,玩我呢?不管他了。因为一查,都是这样的提示,没有问题。
/dev/mapper/vg_vm-lv_root这个应该就是LVM的组名,这里显示的不是sda2.
来扩充这个组吧。
[sss@localhost ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_vm-lv_root 6.7G 6.5G 83M 99% /
tmpfs 495M 80K 495M 1% /dev/shm
/dev/sda1 485M 326M 134M 71% /boot
[sss@localhost ~]$ sudo vgextend /dev/mapper/vg_vm-lv_root /dev/sda3
Volume group name vg_vm/lv_root has invalid characters
[sss@localhost ~]$ sudo vgextend /dev/mapper/vg_vm /dev/sda3
Volume group "vg_vm" successfully extended
原来这个组名,是-之前的字符串——这要是没有文章看着对比分析,谁知道啊?
[sss@localhost ~]$ sudo vgdisplay
--- Volume group ---
VG Name vg_vm
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 29.50 GiB
PE Size 4.00 MiB
Total PE 7553
Alloc PE / Size 1922 / 7.51 GiB Free PE / Size 5631 / 22.00 GiB
VG UUID 8GwL0o-DTdc-Lmkc-gCCC-RBvv-yOQp-wMgpeq
[sss@localhost ~]$ sudo lvextend -L +22G /dev/vg_vm/lv_root /dev/sda3
Extending logical volume lv_root to 28.71 GiB
Insufficient free space: 5632 extents needed, but only 5631 available 估计是这其中用了一部分。22G没那么准了。那么就21.0G吧
[sss@localhost ~]$ sudo lvextend -L +21.9G /dev/vg_vm/lv_root /dev/sda3
Rounding size to boundary between physical extents: 21.90 GiB
Extending logical volume lv_root to 28.61 GiB
Logical volume lv_root successfully resized
不知为何报错。但是这只是一个检查命令,继续往前吧。
[sss@localhost ~]$ sudo resize2fs /dev/vg_vm/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_vm/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_vm/lv_root to 7500800 (4k) blocks.
The filesystem on /dev/vg_vm/lv_root is now 7500800 blocks long.