Knowledge about disk Partitioning in Linux operating systems

Source: Internet
Author: User

Each hard disk's MBR can store up to four partition information, that is, each physical hard disk can be divided into four primary partitions (P + P ), or three primary partitions plus one extended partition (P + E ). If we want to divide more partitions, we can divide the extended partitions into more and smaller logical partitions.

Linux will be numbered 1 ~ 4. fixed allocation to 4 primary partitions. That is to say, even if we only have one primary partition and one extended partition, the first logical partition can only be hda5 (or sda5 ).

When talking about Linux partitions, they are very different from Windows because these partitions usually exist in a directory (or mount point ).
/: Default mount point. unspecified directories are stored in partitions.
/Home: the user's home directory, which is equivalent to Windows's Documents and Settings. It stores user-related data files and is suitable for separate partitioning.
/Usr: Installation directories of various executable programs, which are equivalent to Windows's Program files and Winnt directories. Separate partitions are recommended.
/Var: it is usually used to store various temporary files and cached files, which may easily generate disk fragments. We recommend that you separate partitions.
Of course, do not forget to act as a virtual memory swap partition.

The following is the partitioning method I personally use.

/: 1 GB ~ 2 GB.
/Usr: 1 GB ~ 2 GB, depending on the services and software to be installed.
Swap: generally 2 times the physical memory, but it does not seem necessary to exceed 1 GB.
/Home: all available space
/Var: About 1 GB
We use Fdisk to perform a partition demonstration on an 8 GB hard disk.

Yuanyuan @ yuyun-desktop :~ $ Sudo 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 0x416ba19a.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
And coshould in certain setups cause problems:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(E.g., dos fdisk, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w (rite)

Command (m for help): p # view partition information

Disk/dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Disk identifier: 0x416ba19a

Device Boot Start End Blocks Id System

Command (m for help): n # create a primary partition/
Command action
E extended
P primary partition (1-4)
P # create a primary Partition
Partition number (1-4): 1 # Partition number
First cylinder (1-1044, default 1): # Start cylinder. The default value is usually used.
Using default value 1
Last cylinder, + cylinders or + size {K, M, G} (1-1044, default 1044): + 1024 M # partition size 1 GB.

Command (m for help): n # create a primary partition/usr
Command action
E extended
P primary partition (1-4)
P
Partition number (1-4): 2
First cylinder (133-1044, default 133 ):
Using default value 133
Last cylinder, + cylinders or + size {K, M, G} (133-1044, default 1044): + 1024 M

Command (m for help): n # create a primary partition swap
Command action
E extended
P primary partition (1-4)
P
Partition number (1-4): 3
First cylinder (265-1044, default 265 ):
Using default value 265
Last cylinder, + cylinders or + size {K, M, G} (265-1044, default 1044): + 512 M

Command (m for help): n # create an extended partition
Command action
E extended
P primary partition (1-4)
E
Selected partition 4
First cylinder (331-1044, default 331 ):
Using default value 331
Last cylinder, + cylinders or + size {K, M, G} (331-1044, default 1044): # all remaining space
Using default value 1044

Command (m for help): p # view partitions

Disk/dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Disk identifier: 0x416ba19a

Device Boot Start End Blocks Id System
/Dev/sdb1 1 132 1060258 + 83 Linux
/Dev/sdb2 133 264 1060290 83 Linux
/Dev/sdb3 265 330 530145 83 Linux
/Dev/sdb4 331 1044 5735205 5 Extended

Command (m for help ):

So far, we have completed the division of four primary partitions, and then we will create a logical partition.

Command (m for help): n # create/home logical Partition
First cylinder (331-1044, default 331 ):
Using default value 331
Last cylinder, + cylinders or + size {K, M, G} (331-1044, default 1044): + 4096 M

Command (m for help): n # create/var logical Partition
First cylinder (854-1044, default 854 ):
Using default value 854
Last cylinder, + cylinders or + size {K, M, G} (854-1044, default 1044 ):
Using default value 1044

Command (m for help): p # display partitions

Disk/dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Disk identifier: 0xe1bd2899

Device Boot Start End Blocks Id System
/Dev/sdb1 1 132 1060258 + 83 Linux
/Dev/sdb2 133 264 1060290 83 Linux
/Dev/sdb3 265 330 530145 83 Linux
/Dev/sdb4 331 1044 5735205 5 Extended
/Dev/sdb5 331 853 4200966 83 Linux
/Dev/sdb6 854 1044 1534176 83 Linux

Command (m for help ):

Do not forget to save the partition table, otherwise the above work will be done in white.

Command (m for help): w
The partition table has been altered!

Calling ioctl () to re-read partition table.
Syncing disks.

Check the effect.

Yuanyuan @ yuyun-desktop :~ $ Sudo fdisk-l/dev/sdb

Disk/dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Disk identifier: 0x71f06c9b

Device Boot Start End Blocks Id System
/Dev/sdb1 1 132 1060258 + 83 Linux
/Dev/sdb2 133 264 1060290 83 Linux
/Dev/sdb3 265 330 530145 83 Linux
/Dev/sdb4 331 1044 5735205 5 Extended
/Dev/sdb5 331 853 4200966 83 Linux
/Dev/sdb6 854 1044 1534176 83 Linux

The next step is to format the partition.

Yuanyuan @ yuyun-desktop :~ $ Sudo mke2fs-j-L "root"/dev/sdb1
Mke2fs 1.41.4 (27-Jan-2009)
Filesystem label = root
OS type: Linux
Block size = 4096 (log = 2)
Fragment size = 4096 (log = 2)
66384 inodes, 265064 blocks
13253 blocks (5.00%) reserved for the super user
First data block = 0
Maximum filesystem blocks = 272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7376 inodes per group
Superblock backups stored on blocks:
32768,983 04, 163840,229 376

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.

Set a Label for the partition to facilitate future management.

For more information about partition mount points, see the subsequent sections.

--------------------- Split line ----------------------

It is the partition setting when I install Ubuntu Desktop 9.04 on VMware. Because Desktop is integrated with some software by default, there is a minimum size limit for "/" and "/usr.

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.