fdisk usage under linux

The fdisk function under Linux is extremely powerful. It can be used to divide the most complex partitions. The following is a brief introduction to its usage:

For IDE hard disks, each disk has a device name: corresponding to the four IDE interfaces of the motherboard, the device names are: /dev/hda, /dev/hdb, /dev/hdc, /dev/hdd, etc.

If there is an IDE Raid card, the order is: /dev/hde,/dev/hdf,/dev/hdg,/dev/hdh. For SCSI hard disks, the device names are /dev/sda,/dev/sdb...etc.

The command line usage of fdisk is: fdisk hard disk device name

After entering fdisk, first type 'm' to display all fdisk menus.

Type 'p' again to display the current partition table status.

Type 'n' to add a partition, then you will be prompted to select the partition type (basic or extended), and then select the partition number (1-4). Note: Each hard disk can be divided into four primary partitions at most (including basic partitions and extended partitions), of which: basic partitions can be divided into four at most, extended partitions can be divided into at most one, but multiple logical partitions can be divided into extended partitions ( At most a few I haven't tried, in short a lot). After selecting the partition type and partition number you want to create, you will be prompted to enter the starting cylinder, starting from 1; and then enter the ending cylinder. At this time, you can enter the actual number of cylinders, or you can use the method of "+ partition size". Input, such as: +1024M means add 1024M after the starting cylinder. The device names of the primary partition are: /dev/hda1,/dev/hda2,/dev/hda3,/dev/hda4, and the device names of the logical partition are: /dev/hda5,/dev/hda6,/dev/hda7 ...etc.

Type 'd' to delete the partition and enter the partition number to delete it. Note that when deleting an extended partition, all logical partitions will be deleted at the same time.

Type 't' to change the partition flag (this is the best part of fdisk in Linux!), the default flag of the newly created partition is 83 (Linux Ext2), you can change it to 82 (Linux swap area), or ' b'(FAT32), 'f'(FAT32 Extend, only limited to extended partition), '86'(NTFS). . . Dozens of types, etc. In this way, friends who use multiple operating systems can use Linux's fdisk to divide all the partitions you want!

Type 'a' to toggle the partition activation switch. Please note: the selected partition will change between active and inactive each time you type, but you must ensure that only one partition is active at the end. At this time, the 'p' command is used, and there will be a '*' sign on the activated partition.

In addition to the above commands, there are several others, but they are not commonly used.

Finally, type 'w' and the changes you made to the partition are written to the hard disk; type 'q' to discard all changes.

Flexible application of fdisk can also repair some damaged partition tables, provided that you must accurately remember the starting and ending cylinders of each original partition.

Add another method to format the hard disk: To format the
partition into Linux Ext2 format, use: mkext2fs /dev/hda? To
format the partition into FAT32 format, use: mkfs.vfat /dev/hda?  
Attachment 2:
Instruction : fdisk

Purpose: To observe the physical usage of the hard disk and to divide the hard disk.

Instructions:

      1. Enter fdisk -l /dev/sda on the console to observe the physical usage of the hard disk.

      2. Enter fdisk /dev/sda on the console to enter the split hard disk mode.

        1. Enter m to display a list of all commands.

        2. Enter p to display the hard disk partition status.

        3. Enter a to set the hard disk boot area.

        4. Enter n to set up a new hard disk partition.

         4.1. 输入 e 硬盘为[延伸]分割区(extend)。

         4.2. 输入 p 硬盘为[主要]分割区(primary)。

        5. 输入 t 改变硬盘分割区属性。

        6. 输入 d 删除硬盘分割区属性。

        7. 输入 q 结束不存入硬盘分割区属性。

        8. 输入 w 结束并写入硬盘分割区属性

eg:

格式化与分区

  hd--IDE设备 sd--SCSI设备

  fdisk -l /dev/sda 查看第一块硬盘分区情况

  fdisk /dev/sdb 给第二块硬盘分区

  command acton (m for help):m #显示命令列表

  a-设置可引导标志;b-设置卷标; d-删除一个分区; n-新建分区

  p-显示分区信息; v-校验分区表;q-不存盘退出;w-存盘退出;t-改变分区类型

  command acton (m for help):n 新建分区

  command action

  e extended #扩展分区

  p primary partition (1-4) #主分区

  p #创建主分区

  partition number (1-4):1 #创建第一个主分区

  first cylinder (1-522,default 1):1 #起始柱面(第一个分区始终为1)

  last cylinder or +size or +sizeM or +siezK(1-522,default 522): 10 #截止柱面(若522则整个硬盘分给了一个区)此分区大小是系统按照柱面大小自动计算出来的

  command acton (m for help):n

  command action

  e extended

  p primary partition (1-4)

  p

  partition number (1-4):2 #创建第二个主分区

  first cylinder (11-522,default 11):11

  last cylinder ...(11-522,default 522): +100M #自定义分区大小

  command acton (m for help):n

  command action

  e extended

  p primary partition (1-4)

  e #创建扩展分区,注意一个磁盘只能创建一个扩展区

  partition number (1-4):3

  first cylinder (28-522,default 28):28

  last cylinder ...(28-522,default 522):522 #将剩余空间全部分给扩展分区

  扩展分区是不能直接使用的,必须在其上创建逻辑分区!

  command acton (m for help):n

  command action

  l logical (5 or over) #逻辑分区

  p primary partition (1-4)

  l

  first sylinder (28-255,default 28):28 #在扩展分区里建逻辑分区

  last cylinder ...(28-522,default 522):522 #柱面用尽,等于说只建一个逻辑分区

  command acton (m for help):w #保存退出

  转换分区类型:

  command acton (m for help):t #转换分区类型

  partition number (1-4):2 #选择第二个主分区

  hex code (type L to list codes):82 #按L可列出分区类型所对应的编码

    可以使用 “partprobe” 命令,重新探测磁盘中分区清空,     #partprobe  /dev/sdb

  格式化与挂载: (挂载目录可以自行创建也可指定存在的空目录)

  mksf.ext3 /dev/sdb1 把第二块硬盘的第一个主分区格式化为ext3

  mkswap /dev/sdb2 初始化swap区,此区不可格式化。

  mount /dev/sdb1 /mnt/d #将第一个分区挂载到d这个目录

  重启后自动挂载:vi /etc/fstab

  添加:/dev/sdb1 /mnt/d ext3 default 0 0

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325762577&siteId=291194637