24 Nov 2014
fdisk作用:查看磁盘情况、管理磁盘分区
语法:
fdisk -l [磁盘名称]fdisk 磁盘名称fdisk工具箱用法:”fdisk 磁盘名称”进入fdisk工具
fdisk工具箱选项:
进入fdisk工具箱
# 进入fdisk工具箱 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 0xd6b2d026. 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').
新建主分区sdb1
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1305, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +5G
打印目前分区情况
Command (m for help): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0xd6b2d026 Device Boot Start End Blocks Id System /dev/sdb1 1 654 5253223+ 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
parted作用:
与fdisk的不同点:
语法: parted dev_name [command [参数]]
交互模式常用选项(由help命令可列出):
select DEVICE_NAME 选择需要操作的disk(select /dev/sdb);mkpart PARTATION_TYPE [FORMART] START END 分区命令(mkpart primary ext4 0GB 2GB);print 显示磁盘分区信息;rm NUMBER 按照分区号码删除分区(rm 5),number可以用print看出;quit 退出parted工具。# 查看磁盘情况 # parted -l # parted dev_name print # parted dev_name unit mb print # parted dev_name unit gb print parted /dev/sdb unit gb print Model: ATA CentOS6-1 SSD (scsi) Disk /dev/sdb: 5.37GB Sector size (logical/physical): 512B/4096B Partition Table: msdos Number Start End Size Type File system Flags # 修改分区表为gpt(慎用,无法复原) parted /dev/sdb mklabel 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 Information: You may need to update /etc/fstab. parted /dev/sdb print | grep Partition Partition Table: gpt # 创建分区 # 语法:parted dev_name part_type fs_type start end # dev_name,设备名称,如果未制定,则使用找到的第一个设备 # part_type,分区类型,"primary", "logical", or "extended" # fs_type,分区格式 # "fat16","fat32", "ext2", "HFS", "linux-swap", "NTFS", # "reiserfs",or "ufs" parted /dev/sdb mkpart primary ext4 0GB 1GB Information: You may need to update /etc/fstab. parted /dev/sdb mkpart primary xfs 1GB 2GB Information: You may need to update /etc/fstab. parted /dev/sdb unit mb print Model: ATA CentOS6-1 SSD (scsi) Disk /dev/sdb: 5369MB Sector size (logical/physical): 512B/4096B Partition Table: gpt Number Start End Size File system Name Flags 1 1.05MB 1000MB 999MB primary 2 1000MB 2000MB 999MB primaryPS:
超过2T的硬盘如果不希望容量浪费(MBR最大识别2T),只能将磁盘转化成GPT格式;
传统系统盘是BIOS+MBR,如果希望GPT做系统盘,linux下需要UEFI替代BIOS,采用UEFI+GPT的方式;
MBR分区表占64字节,采用主+扩展<=4,而GPT只有16字节,类似于扩展分区,真正起作用的分区表在512字节之后,因此对GPT分区表来说是没有4个主分区的限制。