对sdb磁盘分区
parted分区
[root@liuyunshen ~]# parted /dev/sdb GNU Parted 3.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mktable gpt (parted) parted(help) align-check TYPE N check partition N for TYPE(min|opt) alignment help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table) mkpart PART-TYPE [FS-TYPE] START END make a partition name NUMBER NAME name partition NUMBER as NAME print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition quit exit program rescue START END rescue a lost partition near START and END rm NUMBER delete partition NUMBER select DEVICE choose the device to edit disk_set FLAG STATE change the FLAG on selected device disk_toggle [FLAG] toggle the state of FLAG on selected device set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU Parted (parted) mkpart (开始分区) Partition name? []? primary File system type? [ext2]? ext4 Start? 0 End? 5G Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? Ignore (parted) p(查看分区) Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 17.4kB 5000MB 5000MB primary (parted) mkpart(第二个分区) Partition name? []? primary File system type? [ext2]? ext4 Start? 5G End? 15G (parted) p (查看所有分区) Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 17.4kB 5000MB 5000MB primary 2 5001MB 15.0GB 9999MB primary (parted) mkpart Partition name? []? primary File system type? [ext2]? ext4 Start? 15G End? 100% (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 17.4kB 5000MB 5000MB primary 2 5001MB 15.0GB 9999MB primary 3 15.0GB 21.5GB 6474MB primary (parted) quit Information: You may need to update /etc/fstab.
查看sdb磁盘分区情况
[root@liuyunshen ~]# parted /dev/sdb print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 17.4kB 5000MB 5000MB primary 2 5001MB 15.0GB 9999MB primary 3 15.0GB 21.5GB 6474MB primary
创建逻辑卷
创建逻辑分区
[root@liuyunshen ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. [root@liuyunshen ~]# vgcreate liuysvg /dev/sdb1 Volume group "liuysvg" successfully created [root@liuyunshen ~]# lvcreate liuysvo -L 196M liuysvg Volume group "liuysvo" not found Cannot process volume group liuysvo [root@liuyunshen ~]# lvcreate -n liuysvo -L 196M liuysvg Logical volume "liuysvo" created.
注意问题
问题一
[root@liuyunshen ~]# pvcreate /dev/sdb1 Can't open /dev/sdb1 exclusively. Mounted filesystem?
解决方法
* 查看是否被挂载 [root@liuyunshen ~]# mount | grep sdb * 解决方法 [root@liuyunshen ~]# dmsetup remove_all
问题二
[root@liuyunshen ~]# pvcreate /dev/sdb1 Can't initialize physical volume "/dev/sdb1" of volume group "liuysvg" without -ff
解决方法
* 原来创建了相应的物理磁盘,所以覆盖掉 [root@liuyunshen ~]# pvcreate -ff /dev/sdb1 Really INITIALIZE physical volume "/dev/sdb1" of volume group "liuysvg" [y/n]? y WARNING: Forcing physical volume creation on /dev/sdb1 of volume group "liuysvg" Physical volume "/dev/sdb1" successfully created.
问题三
[root@liuyunshen ~]# partprobe /dev/sdb Error: Error informing the kernel about modifications to partition /dev/sdb4 -- Device or resource busy. This means Linux won't know about any changes you made to /dev/sdb4 until you reboot -- so you shouldn't mount it or use it in any way before rebooting. Error: Failed to add partition 4 (Device or resource busy)
重启
[root@liuyunshen ~]# reboot
分区格式化
[root@liuyunshen ~]# mkfs.ext4 /dev/liuysvg/liuysvo mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 50200 inodes, 200704 blocks 10035 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=33816576 25 block groups 8192 blocks per group, 8192 fragments per group 2008 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done
添加一个swap分区(开机自动挂载)
[root@liuyunshen ~]# mkswap /dev/sdb7 Setting up swapspace version 1, size = 524280 KiB no label, UUID=6fbbd563-d6b9-42f0-af00-7acbee3b1e1c [root@liuyunshen ~]# vim /etc/fstab [root@liuyunshen ~]# tail -1 /etc/fstab UUID=6fbbd563-d6b9-42f0-af00-7acbee3b1e1c swap swap defaults 0 0 [root@liuyunshen ~]# swapon -a [root@liuyunshen ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 250620 -1 /dev/sdb7 partition 524280 0 -2
挂载分区并查看
法一
[root@liuyunshen ~]# mkdir /liuyvo [root@liuyunshen ~]# mount /dev/liuysvg/liuysvo /liuyvo/ [root@liuyunshen ~]# df -h /liuyvo/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/liuysvg-liuysvo 186M 1.6M 171M 1% /liuyvo
法二(开机自动挂载)
[root@liuyunshen ~]# blkid /dev/mapper/liuysvg-liuysvo /dev/mapper/liuysvg-liuysvo: UUID="fdb2a2d8-5da8-4d7e-bedc-30362432f3b4" TYPE="ext4" [root@liuyunshen ~]# vim /etc/fstab [root@liuyunshen ~]# tail -1 /etc/fstab UUID=fdb2a2d8-5da8-4d7e-bedc-30362432f3b4 /liuyvo ext4 defaults 0 0 [root@liuyunshen ~]# mount -a [root@liuyunshen ~]# df /dev/mapper/liuysvg-liuysvo Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/liuysvg-liuysvo 190264 1550 174665 1% /liuyvo
扩展逻辑分区
一般分区
查看现有的分区
[root@liuyunshen ~]# lvscan ACTIVE '/dev/liuysvg/liuysvo' [196.00 MiB] inherit ACTIVE '/dev/cl/swap' [2.00 GiB] inherit ACTIVE '/dev/cl/root' [46.99 GiB] inherit
扩展卷组
[root@liuyunshen ~]# vgextend liuysvg /dev/sdb5 Physical volume "/dev/sdb5" successfully created. Volume group "liuysvg" successfully extended
扩展逻辑卷
[root@liuyunshen ~]# lvextend -L 300MiB /dev/liuysvg/liuysvo Size of logical volume liuysvg/liuysvo changed from 196.00 MiB (49 extents) to 300.00 MiB (75 extents). Logical volume liuysvg/liuysvo successfully resized.
更新逻辑卷大小
[root@liuyunshen ~]# resize2fs /dev/liuysvg/liuysvo resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/liuysvg/liuysvo is mounted on /liuyvo; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 3 The filesystem on /dev/liuysvg/liuysvo is now 307200 blocks long.
物理扩展单元创建
创建16M的物理扩展单元
[root@liuyunshen ~]# vgcreate -s 16MiB datastore /dev/sdb6 Physical volume "/dev/sdb6" successfully created. Volume group "datastore" successfully created
创建50个物理扩展单元的逻辑卷
[root@liuyunshen ~]# lvcreate -l 50 -n database datastore Logical volume "database" created.
格式化逻辑卷
[root@liuyunshen ~]# mkfs.ext4 /dev/datastore/database mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 51296 inodes, 204800 blocks 10240 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=209715200 7 block groups 32768 blocks per group, 32768 fragments per group 7328 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done
创建挂载目录并开机自动挂载
[root@liuyunshen ~]# mkdir /mnt/database [root@liuyunshen ~]# blkid /dev/mapper/datastore-database Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/datastore-database: UUID="ff420212-4a52-4dad-ac65-fec50d153b22" TYPE="ext4" [root@liuyunshen ~]# vim /etc/fstab [root@liuyunshen ~]# tail -1 /etc/fstab UUID=ff420212-4a52-4dad-ac65-fec50d153b22 /mnt/database ext4 defaults 0 0 [root@liuyunshen ~]# mount -a [root@liuyunshen ~]# df /mnt/database/ Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/datastore-database 789904 1608 730952 1% /mnt/database