一、检测并确认新硬盘 fdisk -l 命令
[root@localhost ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00058c62
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 5222 41430016 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
二、规划硬盘中的分区 fdisk 命令
(1)、开机,查看新硬盘是否添加
[root@localhost ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00058c62
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 5222 41430016 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
(2)使用fdisk进行分区
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x556afa4d.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
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)
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x556afa4d
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 【回车键】
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (655-2610, default 655): 【回车键】
Using default value 655
Last cylinder, +cylinders or +size{K,M,G} (655-2610, default 2610): +5G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 4
First cylinder (1309-2610, default 1309): 【回车键】
Using default value 1309
Last cylinder, +cylinders or +size{K,M,G} (1309-2610, default 2610): 【回车键】
Using default value 2610
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1309-2610, default 1309): 【回车键】
Using default value 1309
Last cylinder, +cylinders or +size{K,M,G} (1309-2610, default 2610): +1G
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1441-2610, default 1441): 【回车键】
Using default value 1441
Last cylinder, +cylinders or +size{K,M,G} (1441-2610, default 2610): 【回车键】
Using default value 2610
Command (m for help): t
Partition number (1-6): 5
Hex code (type L to list codes): 82
Changed system type of partition 5 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x556afa4d
Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
/dev/sdb2 655 1308 5253255 83 Linux
/dev/sdb4 1309 2610 10458315 5 Extended
/dev/sdb5 1309 1440 1060258+ 82 Linux swap / Solaris
/dev/sdb6 1441 2610 9397993+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
三、大小超过2T的区别规划 parted 命令
1、示例
(1)开机,查看新硬盘是否添加
[root@localhost ~]# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 1049kB 525MB 524MB primary ext4 启动
2 525MB 42.9GB 42.4GB primary lvm
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1 32.3kB 5379MB 5379MB primary
2 5379MB 10.8GB 5379MB primary
4 10.8GB 21.5GB 10.7GB extended
5 10.8GB 11.8GB 1086MB logical
6 11.8GB 21.5GB 9624MB logical
错误: /dev/sdc: unrecognised disk label
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/VolGroup-lv_root: 40.3GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Number Start End Size File system 标志
1 0.00B 40.3GB 40.3GB ext4
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/VolGroup-lv_swap: 2080MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Number Start End Size File system 标志
1 0.00B 2080MB 2080MB linux-swap(v1)
警告: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
错误: 无效的分区表 - /dev/sr0 出现递归分区。
忽略/Ignore/放弃/Cancel? I
Model: NECVMWar VMware IDE CDR10 (scsi)
Disk /dev/sr0: 4468MB
Sector size (logical/physical): 2048B/2048B
Partition Table: msdos
Number Start End Size Type File system 标志
[root@localhost ~]# parted /dev/sdb
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) help
align-check TYPE N check partition N for TYPE(min|opt)
alignment
check NUMBER do a simple check on the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system on partition
NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system
move NUMBER START END move partition NUMBER
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
resize NUMBER START END resize partition NUMBER and its file
system
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
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) mklabel
新的磁盘标签类型? 【按俩此tab键】
aix amiga bsd dvh gpt loop mac msdos pc98 sun
新的磁盘标签类型? gpt
警告: 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
分区名称? []? part1
文件系统类型? [ext2]? ext4
起始点? 1
结束点? 5G
(parted) mkpart
分区名称? []? part2
文件系统类型? [ext2]? ext4
起始点? 5G
结束点? 10G
(parted) mkpart
分区名称? []? part3
文件系统类型? [ext2]? ext4
起始点? 10G
结束点? -1
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1 1049kB 5000MB 4999MB part1
2 5000MB 10.0GB 5001MB part2
3 10.0GB 21.5GB 11.5GB part3
(parted) quit
信息: You may need to update /etc/fstab.
[root@localhost ~]# ls -l /dev/sdb*
brw-rw----. 1 root disk 8, 16 3月 15 03:36 /dev/sdb
brw-rw----. 1 root disk 8, 17 3月 15 03:36 /dev/sdb1
brw-rw----. 1 root disk 8, 18 3月 15 03:36 /dev/sdb2
brw-rw----. 1 root disk 8, 19 3月 15 03:36 /dev/sdb3
[root@localhost ~]# ls -l /dev/sdb*
brw-rw----. 1 root disk 8, 16 3月 15 03:36 /dev/sdb
brw-rw----. 1 root disk 8, 17 3月 15 03:36 /dev/sdb1
brw-rw----. 1 root disk 8, 18 3月 15 03:36 /dev/sdb2
brw-rw----. 1 root disk 8, 19 3月 15 03:36 /dev/sdb3
[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
305216 inodes, 1220352 blocks
61017 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1249902592
38 block groups
32768 blocks per group, 32768 fragments per group
8032 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkdir /sdb1
[root@localhost ~]# mount /dev/sdb1 /sdb1
[root@localhost ~]# cd /sdb1
[root@localhost sdb1]# echo ceshiwenjian > test.txt
[root@localhost sdb1]# cd
[root@localhost ~]# umount sdb1
umount: sdb1: not found
[root@localhost ~]# umount /sdb1
[root@localhost ~]# parted /dev/sdb
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1 1049kB 5000MB 4999MB ext4 part1
2 5000MB 10.0GB 5001MB part2
3 10.0GB 21.5GB 11.5GB part3
(parted) rm 1
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
2 5000MB 10.0GB 5001MB part2
3 10.0GB 21.5GB 11.5GB part3
(parted) rescue
起始点? 1
结束点? 5G
信息: A ext4 primary partition was found at 1049kB -> 5000MB. Do you want to add it to
the partition table?
是/Yes/否/No/放弃/Cancel? Y
(parted) P
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1 1049kB 5000MB 4999MB ext4
2 5000MB 10.0GB 5001MB part2
3 10.0GB 21.5GB 11.5GB part3
(parted) q
信息: You may need to update /etc/fstab.
[root@localhost ~]# mount /dev/sdb1 /sdb1
[root@localhost ~]# cat /sdb1/test.txt 【测试文件已被找回】
ceshiwenjian
实验补充:
1、quit与w命令用反,导致分区失败
2、使用mkparst命令规划分区后会出现之前的sdb2~6的丢失,所以这时需要重新做硬盘划分