Device does not contain a recognized partition table 使用磁盘标识符 0x2285b981 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):m # 显示菜单 命令操作 a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition # 删除一个分区 g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu # 显示菜单 n add a new partition # 创建一个新的分区 o create a new empty DOS partition table p print the partition table # 显示分区列表 q quit without saving changes # 不保存退出 s create a new empty Sun disklabel t change a partition's system id # 更改分区类型 u change display/entry units v verify the partition table w write table to disk and exit # 写入磁盘信息并退出 x extra functionality (experts only)
命令(输入 m 获取帮助):n # 新建一个分区 Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): # 回车使用默认,创建主分区 Using default response p 分区号 (1-4,默认 1): # 回车使用默认,创建分区号为1 起始 扇区 (2048-10485759,默认为 2048): # 回车使用默认起始扇区 将使用默认值 2048 Last 扇区, +扇区 or +size{K,M,G} (2048-10485759,默认为 10485759):+2G # 创建大小为 2G 分区 1 已设置为 Linux 类型,大小设为 2 GiB
设备 Boot Start End Blocks Id System /dev/sdb1 2048 4196351 2097152 83 Linux /dev/sdb2 4196352 6293503 1048576 83 Linux /dev/sdb3 6293504 10485759 2096128 83 Linux
命令(输入 m 获取帮助):w The partition table has been altered!
Calling ioctl() to re-read partition table. 正在同步磁盘。
[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size 79.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 20354 Free PE 0 Allocated PE 20354 PV UUID Gv6gjF-lcaF-1KOP-mJK1-ejyA-80fc-FUuf0f "/dev/sdc" is a new physical volume of "5.00 GiB" --- NEW Physical volume --- PV Name /dev/sdc VG Name PV Size 5.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 8x7NNq-FK15-1GLo-UeyK-6nIl-fLr2-FAs2ZH "/dev/sdb2" is a new physical volume of "1.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 1.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID XA4A2B-W52C-7EoE-lsuv-5KxJ-dLdJ-QGPv1H "/dev/sdb3" is a new physical volume of "2.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb3 VG Name PV Size 2.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 9DKGiX-RdYb-re1b-P7dq-ZtkX-OGHe-0sqeB8 "/dev/sdb1" is a new physical volume of "2.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 2.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 6ep0dc-VUtR-SdJ8-ZzG6-n1n4-ndkO-ufPXZy
[root@localhost ~]# vgdisplay # 不指定参数时,会查看所有卷组 --- Volume group --- VG Name test_volume System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 6.99 GiB PE Size 4.00 MiB Total PE 1790 Alloc PE / Size 0 / 0 Free PE / Size 1790 / 6.99 GiB VG UUID jzKmzc-IJbU-cQR8-clm3-dWIC-Nvzb-pdCFPf --- Volume group --- VG Name centos 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 79.51 GiB PE Size 4.00 MiB Total PE 20354 Alloc PE / Size 20354 / 79.51 GiB Free PE / Size 0 / 0 VG UUID Abfqd4-N3hG-BJR1-2j2a-VYFQ-cRXI-OtmJmR
[root@localhost ~]# vgdisplay test_volume # 指定查看某个卷组 --- Volume group --- VG Name test_volume System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 6.99 GiB PE Size 4.00 MiB Total PE 1790 Alloc PE / Size 0 / 0 Free PE / Size 1790 / 6.99 GiB # 剩余空间为 7G VG UUID M54Oct-igCs-FOwl-kI0S-Bf4f-sXOi-nIw5Yw
激活卷组
为了立即使用卷组而不是重新启动系统,可以使用vgchange来激活卷组:
1 2
[root@localhost ~]# vgchange -ay test_volume 0 logical volume(s) in volume group "test_volume" now active
[root@localhost ~]# pvcreate /dev/sdd Physical volume "/dev/sdd" successfully created [root@localhost ~]# vgextend test_volume /dev/sdd Volume group "test_volume" successfully extended [root@localhost ~]# vgdisplay test_volume --- Volume group --- VG Name test_volume System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 11.99 GiB PE Size 4.00 MiB Total PE 3069 Alloc PE / Size 0 / 0 Free PE / Size 3069 / 11.99 GiB # 7G + 5G VG UUID M54Oct-igCs-FOwl-kI0S-Bf4f-sXOi-nIw5Yw
[root@localhost ~]# vgreduce test_volume /dev/sdc Removed "/dev/sdc" from volume group "test_volume" [root@localhost ~]# vgdisplay test_volume --- Volume group --- VG Name test_volume System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 6.99 GiB PE Size 4.00 MiB Total PE 1790 Alloc PE / Size 0 / 0 Free PE / Size 1790 / 6.99 GiB VG UUID M54Oct-igCs-FOwl-kI0S-Bf4f-sXOi-nIw5Yw
[root@localhost ~]# vgremove test_volume Volume group "test_volume" successfully removed [root@localhost ~]# vgdisplay # 查看所有卷组, test_volume 消失 --- Volume group --- VG Name centos 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 79.51 GiB PE Size 4.00 MiB Total PE 20354 Alloc PE / Size 20354 / 79.51 GiB Free PE / Size 0 / 0 VG UUID Abfqd4-N3hG-BJR1-2j2a-VYFQ-cRXI-OtmJmR
[root@localhost ~]# mkfs.ext4 /dev/test_volume/testLV mke2fs 1.42.9 (28-Dec-2013) 文件系统标签= OS type: Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 196608 inodes, 786432 blocks 39321 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=805306368 24 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (16384 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
挂载到目录:
注意: 挂载到目录之前,请备份好目录内的文件!
1
[root@localhost ~]# mount /dev/test_volume/testLV /home/MyVolume/
配置开机自动挂载文件系统:
编辑 /etc/fstab 文件,追加文件系统信息
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@localhost ~]# vi /etc/fstab
# # /etc/fstab # Created by anaconda on Fri Feb 10 16:38:19 2017 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=5725d92e-05b1-4f52-bc62-4de75b503be0 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 /dev/test_volume/testLV /home/MyVolume/ ext4 default 1 2
删除一个逻辑卷
删除逻辑卷之前需要将其卸载后才能删除。请备份文件系统内文件!
1 2 3 4
[root@localhost ~]# umount /home/MyVolume/ [root@localhost ~]# lvremove /dev/test_volume/testLV Do you really want to remove active logical volume testLV? [y/n]: y Logical volume "testLV" successfully removed
[root@localhost ~]# vgdisplay test_volume --- Volume group --- VG Name test_volume System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 6.99 GiB PE Size 4.00 MiB Total PE 1790 Alloc PE / Size 768 / 3.00 GiB Free PE / Size 1022 / 3.99 GiB # 可用空间为 3G VG UUID WDFqaI-Qopl-fDJM-eeMl-3U20-aCpc-umR44I
[root@localhost ~]# vgextend test_volume /dev/sdb3 Volume group "test_volume" successfully extended [root@localhost ~]# vgdisplay test_volume --- Volume group --- VG Name test_volume System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 8.99 GiB PE Size 4.00 MiB Total PE 2301 Alloc PE / Size 768 / 3.00 GiB Free PE / Size 1533 / 5.99 GiB # 可用空间为 6G VG UUID WDFqaI-Qopl-fDJM-eeMl-3U20-aCpc-umR44I
查看当前逻辑卷 逻辑卷大小为 3G
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
[root@localhost ~]# lvdisplay /dev/test_volume/testLV --- Logical volume --- LV Path /dev/test_volume/testLV LV Name testLV VG Name test_volume LV UUID k3WITF-SIK1-MVhz-MdNr-exdX-5qIm-2d2IOr LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-02-11 22:17:13 +0800 LV Status available # open 0 LV Size 3.00 GiB Current LE 768 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2
扩展逻辑卷:
1 2 3
[root@localhost ~]# lvextend -L 6G /dev/test_volume/testLV Size of logical volume test_volume/testLV changed from 3.00 GiB (768 extents) to 6.00 GiB (1536 extents). Logical volume testLV successfully resized.
查看扩展后的逻辑卷 逻辑卷大小为 6G
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
[root@localhost ~]# lvdisplay /dev/test_volume/testLV --- Logical volume --- LV Path /dev/test_volume/testLV LV Name testLV VG Name test_volume LV UUID k3WITF-SIK1-MVhz-MdNr-exdX-5qIm-2d2IOr LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-02-11 22:17:13 +0800 LV Status available # open 0 LV Size 6.00 GiB Current LE 1536 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2