五.parted使用示例
# parted /dev/sdb //对系统中的第2块SCSI/SAS/SATA接口硬盘进行分区操作
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart //创建分区,由于是新硬盘所以给出错误提示
错误: /dev/sdb: unrecognised disk label //无法识别的磁盘标签
(parted) mktable msdos //对新硬盘创建一个新的msdos类型的空磁盘盘分区表
(parted) mkpart //创建新分区
分区类型? primary/主分区/extended/扩展分区? p //输入p表示创建主分区
文件系统类型? [ext2]? Ext4 //默认是ext2,直接回车或输入文件系统类型
起始点? 0 //输入0表示从磁盘开始处创建
结束点? -1s //表示硬盘最后一个扇区,就是硬盘的最末尾处,数字为负数表示从磁盘末尾开始计算
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放弃/Cancel? i //输入忽略
(parted) print //显示当前分区表
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 512B 8590MB 8590MB primary
(parted) rm //删除已经存在的分区
分区编号? 1 //指定要删除的分区编号
(parted) p //显示当前分区表,分区已经被删除
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
(parted) mkpart //创建新分区
分区类型? primary/主分区/extended/扩展分区? p //输入p表示创建主分区
文件系统类型? [ext2]? ext4 //默认是ext2,直接回车或输入文件系统类型
起始点? 0 //输入0表示从磁盘开始处创建
结束点? 500 //输入500,表示次分区大小为500M
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放弃/Cancel? i
(parted) mkpart //对所磁盘剩余空间创建扩展分区
分区类型? primary/主分区/extended/扩展分区? e
起始点? 500
结束点? -1s
(parted) p //显示当前分区表
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 512B 500MB 500MB primary
2 500MB 8590MB 8090MB extended lba
(parted) unit s print //设置单位为扇区,重新显示当前分区表
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 16777216s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 1s 976562s 976562s primary
2 976896s 16777215s 15800320s extended lba
(parted) mkpart //创建500M的新分区
分区类型? primary/主分区/logical/逻辑分区? L //输入l表示创建逻辑分区
文件系统类型? [ext2]? ext4
起始点? 500M //由于此时已经设置了单位为扇区(s),所以此时使用后缀m表示MB,否则表示第500个扇区
结束点? 1000m
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放弃/Cancel? i
(parted) mkpart //创建500M的新的分区
分区类型? primary/主分区/logical/逻辑分区? l
文件系统类型? [ext2]? ext4
起始点? 1000m
结束点? 1500m
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 16777216s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 1s 976562s 976562s primary
2 976896s 16777215s 15800320s extended lba
5 976897s 1953125s 976229s logical
6 1953792s 2930687s 976896s logical
(parted) unit mb //重新将单位设置为MB
(parted) p //显示当前分区表
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 0.00MB 500MB 500MB primary
2 500MB 8590MB 8090MB extended lba
5 500MB 1000MB 500MB logical
6 1000MB 1501MB 500MB logical
(parted) mkpart //创建一个400M类型为FAT32的逻辑分区
分区类型? primary/主分区/logical/逻辑分区? l
文件系统类型? [ext2]? fat32
起始点? 1500
结束点? 1900
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放弃/Cancel? i
(parted) mkpart //创建一个256M类型为swap的逻辑分区
分区类型? primary/主分区/logical/逻辑分区? l
文件系统类型? [ext2]? linux-swap
起始点? 1900
结束点? 2156
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 0.00MB 500MB 500MB primary
2 500MB 8590MB 8090MB extended lba
5 500MB 1000MB 500MB logical
6 1000MB 1501MB 500MB logical
7 1501MB 1900MB 399MB logical lba
8 1900MB 2156MB 256MB logical
(parted) set //将6号分区的lvm标志设置为on
分区编号? 6
Flag to Invert? lvm
新状态? [开]/on/关/off? on
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 0.00MB 500MB 500MB primary
2 500MB 8590MB 8090MB extended lba
5 500MB 1000MB 500MB logical
6 1000MB 1501MB 500MB logical lvm
7 1501MB 1900MB 399MB logical lba
8 1900MB 2156MB 256MB logical
(parted) quit //退出parted交互模式
信息: You may need to update /etc/fstab.
# parted /dev/sdb print //直接在命令模式下显示/dev/sdb的分区表
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 512B 500MB 500MB primary
2 500MB 8590MB 8090MB extended lba
5 500MB 1000MB 500MB logical
6 1000MB 1501MB 500MB logical lvm
7 1501MB 1900MB 399MB logical lba
8 1900MB 2156MB 256MB logical
# parted -l //直接在命令模式下显示所有设备的分区表
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 1049kB 106MB 105MB primary ext4 启动
2 106MB 2727MB 2621MB primary ext4
3 2727MB 6607MB 3880MB primary ext4
4 6607MB 10.7GB 4130MB extended
5 6608MB 8705MB 2097MB logical ext4
6 8706MB 9755MB 1049MB logical ext4
7 9756MB 10.7GB 981MB logical linux-swap(v1)
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 512B 500MB 500MB primary
2 500MB 8590MB 8090MB extended lba
5 500MB 1000MB 500MB logical
6 1000MB 1501MB 500MB logical lvm
7 1501MB 1900MB 399MB logical lba
8 1900MB 2156MB 256MB logical