RHCSA的使用fdisk 、gdisk管理分区
用fdisk管理分区fdisk命令工具默认将磁盘划分为mbr格式的分区命令fdisk设备名fdisk命令以交互方式进行操作的在菜单中选择相应功能键即可[rootlocalhost ~]# fdisk /dev/sda#对sda进行分区Command (m for help):#进入fdisk交互界面进行分区Command (m for help): m#输入m可查看帮助信息Help:DOS (MBR)a toggle a bootable flagb edit nested BSD disklabelc toggle the dos compatibility flagGenericd delete a partitionF list free unpartitioned spacel list known partition typesn add a new partitionp print the partition tablet change a partition typev verify the partition tablei print information about a partitionMiscm print this menuu change display/entry unitsx extra functionality (experts only)ScriptI load disk layout from sfdisk script fileO dump disk layout to sfdisk script fileSave Exitw write table to disk and exitq quit without saving changesCreate a new labelg create a new empty GPT partition tableG create a new empty SGI (IRIX) partition tableo create a new empty DOS partition tables create a new empty Sun partition tableCommand (m for help): n#输入n创建新分区Partition typep primary (0 primary, 0 extended, 4 free)#输入p创建主分区e extended (container for logical partitions)#输入e创建扩展分区Select (default p): p#输入p创建主分区Partition number (1-4, default 1): 1#选择主分区号输入1表示第一个主分区First sector (2048-10485759, default 2048):#直接按回车从当前第2048个扇区开始分区Last sector, sectors or size{K,M,G,T,P} (2048-10485759, default 10485759): 300M#设置第一个分区为300MCreated a new partition 1 of type Linux and of size 300 MiB.#一个主分区创建完成大小为300MCommand (m for help): p#输入p查看分区信息Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectorsUnits: sectors of 1 * 512 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x5bb0744fDevice Boot Start End Sectors Size Id Type/dev/sda1 2048 616447 614400 300M 83 LinuxDevice Boot Start End Sectors Size Id Type/dev/sda1 2048 616447 614400 300M 83 Linux/dev/sda2 616448 10485759 9869312 4.7G 0 Empty#有两个分区其中新添加的sda2有误需要删除Command (m for help): d#输入d删除分区Partition number (1,2, default 2): 2#输入2选择需要删除的是第二个分区Partition 2 has been deleted.Command (m for help): pDisk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectorsUnits: sectors of 1 * 512 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x5bb0744fDevice Boot Start End Sectors Size Id Type/dev/sda1 2048 616447 614400 300M 83 Linux#查看现有分区有误的sda2已删除#创建一个扩展分区Command (m for help): n#输入n创建新分区Partition typep primary (1 primary, 0 extended, 3 free)e extended (container for logical partitions)Select (default p): e#输入e创建扩展分区Partition number (2-4, default 2): 2#选择分区号输入2表示第二个分区First sector (616448-10485759, default 616448):#直接按回车从当前第616448个扇区开始分区Last sector, sectors or size{K,M,G,T,P} (616448-10485759, default 10485759): 500M#添加一个500M的分区Created a new partition 2 of type Extended and of size 500 MiB.Command (m for help): pDisk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectorsUnits: sectors of 1 * 512 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x5bb0744fDevice Boot Start End Sectors Size Id Type/dev/sda1 2048 616447 614400 300M 83 Linux/dev/sda2 616448 1640447 1024000 500M 5 Extended#输入p查看新增一个500M的扩展分区Command (m for help): w#所有分区设置完成后输入w保存即可退出fdisk交互界面The partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.使用gdisk管理分区gdisk命令工具默认将磁盘划分为GPT格式的分区[rootlocalhost ~]# gdisk /dev/sda#进入gdisk交互界面GPT fdisk (gdisk) version 1.0.3Partition table scan:MBR: MBR onlyBSD: not presentAPM: not presentGPT: not presentCommand (? for help): ?#输入?可查看帮助信息bback up GPT data to a filecchange a partitions nameddelete a partitionishow detailed information on a partitionllist known partition typesnadd a new partitionocreate a new empty GUID partition table (GPT)pprint the partition tableqquit without saving changesrrecovery and transformation options (experts only)ssort partitionstchange a partitions type codevverify diskwwrite table to disk and exitxextra functionality (experts only)?print this menu#gdisk创建新分区默认GPT格式Command (? for help): n#输入n创建新分区Partition number (1-128, default 1):#输入分区编号默认为1因为是/dev/sda硬盘的第一块分区First sector (34-10485726, default 2048) or {-}size{KMGTP}: #输入扇区的开始位置选择默认即可也可手动指定Last sector (2048-10485726, default 10485726) or {-}size{KMGTP}: 300M#输入扇区的结束位置一般都是指定磁盘大小这里输入300M表示新分区大小为300MCurrent type is Linux filesystemHex code or GUID (L to show codes, Enter 8300):#默认即可分区完成后可以修改Changed type of partition to Linux filesystemCommand (? for help): p#输入p查看分区情况Disk /dev/sda: 10485760 sectors, 5.0 GiBModel: VMware Virtual SSector size (logical/physical): 512/512 bytesDisk identifier (GUID): 61FA16FB-FAD8-4873-A857-BD387FE0A592Partition table holds up to 128 entriesMain partition table begins at sector 2 and ends at sector 33First usable sector is 34, last usable sector is 10485726Partitions will be aligned on 2048-sector boundariesTotal free space is 9871293 sectors (4.7 GiB)Number Start (sector) End (sector) Size Code Name1 2048 616447 300.0 MiB 8300 Linux filesystemCommand (? for help): w#输入w保存分区并退出gdisk交互界面Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!Do you want to proceed? (Y/N): yOK; writing new GUID partition table (GPT) to /dev/sda.The operation has completed successfully.