Running Linux, 5th Edition - Matthias Kalle Dalheimer [35]
Here is an example of a printed partition table (of a very small hard disk), where blocks, sectors, and cylinders are units into which a hard disk is organized:
Command (m for help): p
Disk /dev/hda: 16 heads, 38 sectors, 683 cylinders
Units = cylinders of 608 * 512 bytes
Device Boot Begin Start End Blocks Id System
/dev/hda1 * 1 1 203 61693 6 DOS 16-bit >=32M
Command (m for help):
In this example, we have a single Windows partition on /dev/hda1, which is 61693 blocks (about 60 MB).[*] This partition starts at cylinder number 1 and ends on cylinder 203. We have a total of 683 cylinders in this disk; so there are 480 cylinders left on which to create Linux partitions.
To create a new partition, use the n command. In this example, we'll create two primary partitions (/dev/hda2 and /dev/hda3) for Linux:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Here, fdisk is asking which type of the partition to create: extended or primary. In our example, we're creating only primary partitions, so we choose p:
Partition number (1-4):
fdisk will then ask for the number of the partition to create; because partition 1 is already used, our first Linux partition will be number 2:
Partition number (1-4): 2
First cylinder (204-683):
Now, we'll enter the starting cylinder number of the partition. Because cylinders 204 through 683 are unused, we use the first available one (numbered 204). There's no reason to leave empty space between partitions:
First cylinder (204-683): 204
Last cylinder or +size or +sizeM or +sizeK (204-683):
fdisk is asking for the size of the partition we want to create. We can either specify an ending cylinder number, or a size in bytes, kilobytes, or megabytes. Because we want our partition to be 80 MB in size, we specify +80M. When specifying a partition size in this way, fdisk will round the actual partition size to the nearest number of cylinders:
Last cylinder or +size or +sizeM or +sizeK (204-683): +80M
If you see a warning message such as this, it can be ignored. fdisk prints the warning because it's an older program and dates back before the time that Linux partitions were allowed to be larger than 64 MB.
Now we're ready to create our second Linux partition. For sake of demonstration, we'll create it with a size of 10 MB:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (474-683): 474
Last cylinder or +size or +sizeM or +sizeK (474-683): +10M
At last, we'll display the partition table. Again, write down all this information-- especially the block sizes of your new partitions. You'll need to know the sizes of the partitions when creating filesystems. Also, verify that none of your partitions overlaps:
Command (m for help): p
Disk /dev/hda: 16 heads, 38 sectors, 683 cylinders
Units = cylinders of 608 * 512 bytes
Device Boot Begin Start End Blocks Id System
/dev/hda1 * 1 1 203 61693 6 DOS 16-bit >=32M
/dev/hda2 204 204 473 82080 83 Linux native
/dev/hda3 474 474 507 10336 83 Linux native
As you can see, /dev/hda2 is now a partition of size 82,080 blocks (which corresponds to about 80 MB), and /dev/hda3 is 10,336 blocks (about 10 MB).
Note that most distributions require you to use the t command in fdisk to change the type of the swap partition to "Linux swap," which is numbered 82. You can use the l command to print a list of known partition type codes, and then use the t command to set the type of the swap partition to that which corresponds to "Linux swap."
This way the installation software will be able to automatically find your swap partitions based on type. If the installation software doesn't seem to recognize your swap partition, you might want to rerun fdisk and use the t command on the partition in question.
In the previous example, the remaining cylinders on the disk (numbered 508 to 683) are unused. You may wish to leave unused space on the disk, in case you want to create additional partitions later.
Finally, we use the w