linux磁盘管理 LVM
今天要处理一个分区不够用的问题,所以特意需要处理LVM,把所有分区组合起来一个使用。
先说分区管理:
(…是省略的内容)
[root@localhost ~]# fdisk -l
Disk /dev/sda: 146.8 GB, 146815733760 bytes
….
Disk /dev/sdb: 146.8 GB, 146815733760 bytes
255 heads, 63 sectors/track, 17849 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 244 1959898+ 83 Linux
/dev/sdb2 245 17849 141412162+ 83 Linux
[root@localhost ~]# fdisk /dev/sdb
…
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): L
…
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap)
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): 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.
Syncing disks.
[root@localhost ~]# partprobe
这个不需要重启生效的,刚看过的技巧,运行 partprobe,让内核重新读取信息
引用
[root@localhost ~]# fdisk -l
Disk /dev/sda: 146.8 GB, 146815733760 bytes
…
Disk /dev/sdb: 146.8 GB, 146815733760 bytes
255 heads, 63 sectors/track, 17849 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 244 1959898+ 82 Linux swap
/dev/sdb2 245 17849 141412162+ 8e Linux LVM
建立分区就没有问题了,下面列举一下LVM创建时的一些命令参考:
#创建pv,也就是把每个要组合的分区都变成pv
pvcreate /dev/sda2 /dev/sda4 /dev/sdb2
#创建组合,把需要组合的分区都合并成一个vg
vgcreate aslibra /dev/sda2 /dev/sda4 /dev/sdb2
#列举现有vg
vgdisplay
#可以看到有250G,下面可以直接把它分到一个lv
lvcreate -L 251G -n lv1 aslibra
#可以看看结果
lvdisplay
#格式化该lv
mkfs.ext3 /dev/aslibra/lv1
#挂载到文件系统
mount /dev/aslibra/lv1 /cache
交换分区的初始化:
mkswap /dev/sdb1
swapon /dev/sdb1
cat /proc/swaps