1、parted分区
##选择操作磁盘sdb
root@linux:~# parted /dev/sdb
GNU Parted 3.2Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
##将MBR磁盘格式化为GPT
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y
##划分一个主分区
(parted) mkpart primary ext4Start? 0%
End? 100%
##查看分区信息
(parted) printModel: VMware Virtual disk (scsi)
Disk /dev/sdb: 68.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 68.7GB 68.7GB ext4 primary
##退出分区设置
(parted) quit
Information: You may need to update /etc/fstab.
##查看当前dev信息
root@linux:~# fdisk -l
Disk /dev/sdb: 64 GiB, 68719476736 bytes, 134217728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: B3E88DAD-6E34-48FB-81EF-C8BF42B07EFB
Device Start End Sectors Size Type
/dev/sdb1 2048 134215679 134213632 64G Linux filesystem
Disk /dev/sda: 16 GiB, 17179869184 bytes, 33554432 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0001bca6
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 32552959 32550912 15.5G 83 Linux
/dev/sda2 32552960 33552383 999424 488M 82 Linux swap / Solaris
2、分区格式化
root@fu-linux:~# mkfs
Usage:
mkfs [options] [-t <type>] [fs-options] <device> [<size>]
Options:
-t, --type=<type> filesystem type; when unspecified, ext2 is used
fs-options parameters for the real filesystem builder
<device> path to the device to be used
<size> number of blocks to be used on the device
-V, --verbose explain what is being done;
specifying -V more than once will cause a dry-run
-V, --version display version information and exit;
-V as --version must be the only option
-h, --help display this help text and exit
For more information see mkfs(8).
root@fu-linux:~# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 16776704 4k blocks and 4194304 inodes
Filesystem UUID: 8af2f7c4-5608-40ee-8331-a691d904bcf3
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
root@linux:~#
3、删除分区
root@linux:~# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 68.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
2 17.4kB 1049kB 1031kB primary
1 1049kB 68.7GB 68.7GB
(parted) rm 1
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 68.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
2 17.4kB 1049kB 1031kB primary
(parted) rm 2
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 68.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) quit
Information: You may need to update /etc/fstab.
4、附加:
parted指令:强大的硬盘分区工具
【语 法】parted [选项] [参数]
【功能介绍】parted指令是由GNU组织开发的一款功能强的磁盘分区和分区大小调整工具。它可以创建分区、删除分区、调整分区大小、移动和拷贝分区(支持ext2、ext3、linux-swap、fat、fat32和reiserfs分区)。
【选项说明】
选 项 | 功 能 |
-h | 显示帮助信息 |
-i | 交互式模式 |
-s | 脚本模式,不提示用户 |
-v | 显示版本号 |
【参数说明】
参数 | 功 能 |
设备 | 指定要分区的硬盘所对应的设备文件 |
命令 | 要执行的parted命令。忽略此参数时, parted指令进入自己的提示符。 check(对指定分区执行简单的检查); cp(将原设备上的原分区的文 help(显示命令帮助); mkfs(在分区上创建指定的文件系统); mklabel(为分区创建新卷标);mkpart(创建分区); mkpartfs(创建分区及分区上的文件系统); move(移动分区); name(设置分区的名称); print(显示分区列表); quit(退出parted); resize(调整分区大小); rm(删除指定分区); select(选择要操作的硬盘); set(改变分区的状态标志) |
【经验技巧】parted指令目前不支持对"ext3"文件系统调整大小,可以使用resize2fs指令代替。
【示例335】进入交互式模式。具体步骤如下:
parted指令不带"命令"参数时自动进入交互式模式。在命令行中输入下面的命令:
- [root@hn ~]# parted /dev/sda #进入交互式模式
输出信息如下:
- GNU Parted 1.8.1
- Using /dev/sda
- Welcome to GNU Parted! Type 'help' to view a list of commands.
- (parted)
说明:交互式模式下,需要在提示符"(parted) "下输入所有的分区操作命令。
【示例336】显示分区表。具体步骤如下:
使用parted指令的"print"命令显示中的硬盘的分区表。在命令行中输入下面的命令:
- [root@hn ~]# parted /dev/sda print#显示硬盘分区表
输出信息如下:
- ......省略部分输出内容......
- Number Start End Size Type File system Flags
- 1 32.3kB 10.5GB 10.5GB primary ext3 boot
- 2 10.5GB 11.5GB 1045MB primary linux-swap
- 3 11.5GB 11.6GB 107MB primary ext3
- Information: Don't forget to update /etc/fstab, if necessary.
【示例337】创建分区。
(1)使用parted指令的"mkpart"目录创建新的硬盘分区。在命令行中输入下面的命令:
- [root@hn ~]# parted /dev/sdb mkpart primary ext3 100M 200M #创建分区
说明:本例中,在硬盘"/dev/sdb"上创建了一个空间为100M的主分区。
输出信息如下:
- Information: Don't forget to update /etc/fstab, if necessary.
(2)使用parted指令的"print"命令显示中的硬盘的分区表。在命令行中输入下面的命令:
- [root@hn ~]# parted /dev/sdb print #显示分区表
输出信息如下:
- ......省略部分输出内容......
- Number Start End Size Type File system Flags
- 1 100MB 200MB 100MB primary
- Information: Don't forget to update /etc/fstab, if necessary.