FDISK partition commands in detail with Fdisk non-interactive partitioning

Source: Internet
Author: User

1. Description: How Fdisk learns

Fdisk is a command for partitioning in Linux, as detailed parameters can be man, here is the most commonly used in the actual application of the use of the process, because this is more than the simple command of the grammar function to master the actual use of a command.

The following procedure is set up in my own experimental environment, first to look at the brief process:

(1) Add a 1GB disk

(2) Fdisk detailed partitioning process

(3) Notification of changes to the Linux kernel partition information

(4) Formatting partitions

(5) Mount partition

Ok! I believe such a process down, you are really able to add a piece of hard disk, and do partition format and use, so that the meaning is really better than simply speaking the syntax parameters of FDISK is much better!

2. Demo: From adding a hard drive to being able to actually use the hard drive

(1) Add a 1GB disk

I was added directly in the virtual machine environment, the method is very simple, here is not much to say, the following is given under Linux to view the hard disk information:

[Email protected] ~]# fdisk-l/dev/sdb disk/dev/sdb:1073 MB, 1073741824bytes255 heads, Sectors/track, 130cylindersU NITs = cylinders of 16065 * =8225280 bytessector size (logical/physical): 512bytes/512 bytesi/o Size (Minimum/optima L): bytes/512 Bytesdisk identifier:0x00000000

(2) Fdisk detailed partitioning process

A detailed procedure is given below, and some important explanations have been given in the process, taking note of:

[[email protected] ~]# fdisk /dev/sdb ===> directly to the disk name can be partitioned device contains  neither a valid dospartition table, nor sun, sgi or osf  DISKLABELBUILDING A NEW DOS DISKLABEL WITH DISKIDENTIFIER 0X7F3AA9CB. Changes will remain in memory only,until you decide to write  them. After that, of course, the previouscontent won ' t be recoverable.  warning: invalid flag 0x0000 ofpartition table 4 will be  Corrected by w (rite)  warning: dos-compatible mode isdeprecated. it ' s  strongly recommended to         switch off  the mode  (command  ' C ')  andchange display units to          sectors  (command  ' u ') . command  (m for help): mcommand action   a   toggle a bootable flag  b   edit bsd  disklabel  c   toggle the dos compatibilityflag  d    delete a partition            ===> Delete a partition   l   list known partition types   = ==> view partition type corresponding numbered list   m   print this menu               ===> Print this Help menu   n   add a  New partition          ===> Create a new partition   o    create a new empty dospartition table  p   print  the partition table    ===> Print partition Table   q   quit without saving  Changes  ===> exit without saving changes   s   create a new empty  Sundisklabel  t   change a partition ' s system id    ===> Change the partition type (required for LVM)   u   change display/entry units  v    verify the partition table  w   write table  to disk and exit     ===> writes the operation to the partitioned table and exits the program   x    extra functionality  (expertsonly)  Command  (m for help):  ncommand action  e   extended  p   primary  partition  (1-4) p   ===> Create a new primary partition partition number  (1-4): 1    ===> Specify the partition number of the primary partition first cylinder  (1-130, default 1):  ===> The cylinder number usingdefault value 1last cylinder that the specified partition starts with,  +cylinders or+size{K,M,G}  (1-130, default 130): +100m===> the column number at the end of the specified partition, or specify the partition size , let Fdisk automatically determine the end of the cylinder number command  (M FOR HELP): p disk /dev/sdb: 1073 mb,  1073741824bytes255 heads, 63 sectors/track, 130cylindersunits = cylinders  of 16065 * 512 =8225280 bytessector size  (logical/physical):  512bytes  / 512 bytesI/O size  (minimum/optimal):  512 bytes/ 512 bytesdisk  identifier: 0x7f3aa9cb   device boot      start          End      Blocks   Id  System/dev/sdb1                1          14      112423+ 83   Linux Command  (M FOR HELP): ncommand action  e    extended  p   primary partition  (1-4) e   ===> Create a new extended partition partition number  (1-4): 1partition 1 is already defined.   Delete it before re-adding it.===> because the previous partition number 1 is used, the error command  will be indicated here (m  FOR HELP): ncommand action  e   extended  p    primary partition  (1-4) epartition number  (1-4): 2first cylinder  ( 15-130, DEFAULT 15):  usingdefault value 15last cylinder, +cylinders or +size{k,m,g}  (15-130, default 130): usingdefault value 130===> Both the start and end bars of the partition use the default value, which is to allocate the remaining disk space to the partition command  (M&nbsP;FOR HELP): p disk /dev/sdb: 1073 mb, 1073741824bytes255 heads,  63 sectors/track, 130cylindersunits = cylinders of 16065 * 512 = 8225280 bytessector size  (logical/physical): 512bytes / 512 bytesi/o  size  (minimum/optimal):  512 BYTES/ 512 BYTESDISK IDENTIFIER: 0X7F3AA9CB    Device Boot      Start          end      blocks  id  system/dev/sdb1                1           14      112423+ 83   linux/dev/sdb2              15          130      931770   5  extended   Command  (m for help):  ncommand action  l   logical   (5 or over)   ===> since the extended partition can only have one, the above new extended partition   p   primary  partition  (1-4)    The logical partition is displayed here, and you can see the fdisk command,p                                 to create a new logical partition, you need to create a new extended partition partition number  (1-4): 3no free  Sectors available===> also want to create a new primary partition, but there is no disk space remaining command  (M FOR HELP):  ncommand  action  l   logical  (5 or over)   p    primary partition  (1-4) l   ===> Create a new logical partition first cylinder  (15-130,  DEFAULT 15): usingdefault value 15last cylinder, +cylinders or+size{k,m,g}  (15-130, default 130):  +400M Command  (M FOR HELP): p disk /dev/sdb: 1073 mb,  1073741824bytes255 heads, 63 sectors/track, 130cylindersunits = cylinders  of 16065 * 512 =8225280 bytessector size  (logical/physical):  512bytes  / 512 bytesI/O size  (minimum/optimal):  512 bytes/ 512 bytesdisk  identifier: 0x7f3aa9cb   device boot      start          End     Blocks    Id System/dev/sdb1                1          14       112423+ 83   linux/dev/sdb2              15          130      931770    5  Extended/dev/sdb5               15          66       417658+ 83  Linux Command  (m for help):  ncommand action   l   logical  (5 or over)   p   primary  partition  (1-4) lfirst cylinder  (67-130, default 67):  usingdefault value  67Last cylinder, +cylinders or+size{K,M,G}  (67-130, default 130):  usingdefault value 130 command  (M FOR HELP):  p disk /dev/sdb:  1073 mb, 1073741824bytes255 heads, 63 sectors/track, 130cylindersunits = cylinders of 16065  * 512 =8225280 bytesSector size  (logical/physical): 512bytes /  512 bytesi/o size  (Minimum/optimal): 512 bytes/ 512 bytesdisk  identifier: 0x7f3aa9cb   device boot      start          end      blocks  id   System/dev/sdb1                1          14       112423+ 83  Linux/dev/sdb2               15         130       931770   5  extended/dev/sdb5              15           66      417658+  83  Linux/dev/sdb6               67        130      514048+   83 Linux Command  (M FOR HELP): w ===> Save changes The partition  table has been altered! calling ioctl ()  to re-read  Partitiontable. Syncing disks.

OK, you can see that the partition method of Fdisk is very simple, but the premise is that you need to have a knowledge of the hard disk, such as: the internal structure of the hard disk, head, cylinder, sector, etc., this knowledge needs to be very familiar with it, otherwise, using FDISK to partition the word is just--"mirrors , the moon in the water ", mastering the principle is the most important, and the use of command tools only to achieve our needs, but also to deepen our understanding of the principle.

(3) Notification of changes to the Linux kernel partition information

[Email protected] ~]# Partprobe/dev/sdb

This step is required after partitioning is complete, or an error message occurs when you use these partitions. Of course, if you do not do this, you can also take the method of restarting the system.

(4) Formatting partitions

The partition is formatted to create a file system that allocates inode and block

[Email protected] ~]# mkfs.ext4/dev/sdbsdb sdb1 sdb2 sdb5 sdb6 [[email protected] ~]# mkfs.ext4/dev/sdb1 ...  This filesystem would be automaticallychecked every to mounts or180 days, whichever comes first. Use Tune2fs-c or-i to override.

The last hint that the system will check the file system regularly, here do not want to check the system, you can use the following command:

[Email protected] ~]# tune2fs-c -1/dev/sdb1tune2fs 1.41.12 (17-may-2010) Setting maximal mount Count to-1

(5) Mount partition

[Email protected] ~]# mount/dev/sdb1/mnt[[email protected] ~]# df-hfilesystem Size used Avail use% mounted On/dev /sda3 9.2G 1.8G 7.0G 21%/tmpfs 937M 0 937M 0%/dev/shm/dev/sda1 194M 34M 151M 19%/boot/ DEV/SDB1 107M 5.6M 96M 6%/mnt

The mount here is temporarily mounted, and if you need to mount it permanently (that is, the boot mount), you need to modify the/etc/fstab file, which is not mentioned here.


OK, through the above practical steps, you can actually master the use of Fdisk, so that after the need to add hard disk, partition format, you will not know how to do it?

3. Expand: How does fdisk non-interactive partition???

As you can see from the Fdisk partitioning process above, Fidisk uses an interactive process, and if you learn the parted command, you should know that parted is non-interactive, so the question here is, can fdisk be a non-interactive partition?

The answer is yes, please refer to the following:


(1) write the command implementation you want to enter in the Fdisk command line into a text file, such as Fdisk.txt

(2) Then the content of the fdisk.txt is similar to this:

np10100mw

It's actually the partitioning process that we're interacting with (certainly not the same as the partition above me)

(3) Then use a command similar to the following to achieve automatic partitioning:

Fdisk/dev/hda < Fdiskcmd.txt


Ok! The content is so much, see is no use, heavy in practice, hope can help everyone!

This article is from the "fragrant fluttering leaves" blog, please make sure to keep this source http://xpleaf.blog.51cto.com/9315560/1683385

FDISK partition commands in detail with Fdisk non-interactive partitioning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.