parted 分区及LVM挂载(BASE ON SUSE Enterprise 11 SP4)
#创建gpt分区表
parted /dev/sdb mklabel gpt
#创建新分区sdb1、sdb2、sdb3
需要分区300G空间,在划分时至少需要325G空间;
parted /dev/sdb mkpart sdb1 ext3 1G 350G
parted /dev/sdb mkpart sdb2 ext3 351G 700G
parted /dev/sdb mkpart sdb3 ext3 701G 950G
#创建物理卷(可以是整个硬盘、也可以是单个分区)
linux-le62:~ # pvcreate /dev/sdb{1,2,3}
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
#创建卷组vgbels
linux-le62:~ # vgcreate vgbels /dev/sdb{1,2,3}
Volume group "vgbels" successfully created
#创建逻辑卷data、bels、mosdb
lvcreate -L 300G -n data vgbels
lvcreate -L 300G -n bels vgbels
lvcreate -L 200G -n mosdb vgbels
#格式化逻辑卷data、bels、mosdb
linux-le62:~ # mkfs.ext3 /dev/vgbels/data
linux-le62:~ # mkfs.ext3 /dev/vgbels/bels
linux-le62:~ # mkfs.ext3 /dev/vgbels/mosdb
#编辑 vim /etc/fstab,实现开机自动挂载/etc/fstab,实现开机自动挂载
在最后加入以下内容:
/dev/vgbels/data /data ext3 defaults 0 0
/dev/vgbels/bels /bels ext3 defaults 0 0
/dev/vgbels/mosdb /mosdb ext3 defaults 0 0
#挂载所有
linux-le62:~ # mount -a
#查看挂载结果
linux-le62:~ # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/system-root 9.9G 4.7G 4.7G 50% /
udev 253G 212K 253G 1% /dev
tmpfs 253G 80K 253G 1% /dev/shm
/dev/mapper/system-boot 1008M 67M 891M 7% /boot
/dev/sda1 157M 14M 144M 9% /boot/efi
/dev/mapper/system-home 350G 195M 332G 1% /home
/dev/mapper/vgbels-data 296G 191M 281G 1% /data
/dev/mapper/vgbels-bels 296G 191M 281G 1% /bels
/dev/mapper/vgbels-mosdb 197G 188M 187G 1% /mosdb
# 查看LVM相关信息
[root@devstack ~]# pvdisplay
[root@devstack ~]# vgdisplay
[root@devstack ~]# lvdisplay
# 删除LVM
删除LV
[root@devstack ~]# lvremove /dev/mapper/vgbels-data
[root@devstack ~]# lvremove /dev/mapper/vgbels-bels
[root@devstack ~]# lvremove /dev/mapper/vgbels-mosdb
删除vg
[root@devstack ~]# vgremove /dev/mapper/vgbels
删除pv
pvremove /etc/sdb{1,2,3}
#########################交互式Parted实操########################
1、首先类似fdisk一样,先选择要分区的硬盘,此处为/dev/hdd:
[root@10.10.90.97 ~]# parted /dev/hdd
GNU Parted 1.8.1
Using /dev/hdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
2、选择了/dev/hdd作为我们操作的磁盘,接下来需要创建一个分区表(在parted中可以使用help命令打印帮助信息):
(parted) mklabel
Warning: The existing disk label on /dev/hdd will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No?(警告用户磁盘上的数据将会被销毁,询问是否继续,我们这里是新的磁盘,输入yes后回车) yes
New disk label type? [msdos]? (默认为msdos形式的分区,我们要正确分区大于2TB的磁盘,应该使用gpt方式的分区表,输入gpt后回车)gpt
3、创建好分区表以后,接下来就可以进行分区操作了,执行mkpart命令,分别输入分区名称,文件系统和分区 的起止位置
(parted) mkpart
Partition name? []? dp1
File system type? [ext2]? ext3
Start? 0
End? 500GB
4、分好区后可以使用print命令打印分区信息,下面是一个print的样例
(parted) print
Model: VBOX HARDDISK (ide)
Disk /dev/hdd: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 500GB 500GB dp1
5、如果分区错了,可以使用rm命令删除分区,比如我们要删除上面的分区,然后打印删除后的结果
(parted)rm 1 #rm后面使用分区的号码
(parted) print
Model: VBOX HARDDISK (ide)
Disk /dev/hdd: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
6、按照上面的方法把整个硬盘都分好区,下面是一个分完后的样例
(parted) mkpart
Partition name? []? dp1
File system type? [ext2]? ext3
Start? 0
End? 500GB
(parted) mkpart
Partition name? []? dp2
File system type? [ext2]? ext3
Start? 500GB
End? 2199GB
(parted) print
Model: VBOX HARDDISK (ide)
Disk /dev/hdd: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 500GB 500GB dp1
2 500GB 2199GB 1699GB dp2