About hard disk partitioning operations in Linux

Source: Internet
Author: User

Whether the Linux system is mounted on a real machine or a virtual machine, the disk partitioning process is involved, and the system files and associated program files are only loaded when the disk is well-planned. Here are some of the commands and considerations for partitioning in a Linux system.

First we need to know what steps to take to get a piece of physical hard disk to be used:

① identify the hard drive---only after the hard drive is recognized by the computer can we proceed to the next step

② Partition Planning---Generally a hard disk is divided into partitions, so easy to manage, the system is important and ordinary files can be distinguished from

③ format----Make the hard drive plan and turn each partition into the type of file system we want.

④ Mount using---mount is a necessary condition for Linux systems to use storage space

Some common sense about partitioning:

There can be up to 4 primary partitions in a Linux system,

If you want to continue dividing the partition, then there are 3 primary partitions, and the fourth one is the extended partition, and then the logical partition continues to be partitioned in the extended partition.

Note: The extended partitioning function here is to have all the logical partitions of the carrier, all the logical partitions in the extended partition like a large room, was divided into four parts, and then in the fourth part of the continued division of space. So, after continuing to divide the space, this fourth part becomes the carrier of all the space behind.

Summary: Hard disk Partitioning in Linux system: 1~4 primary partition, or 0~3 primary partition + one extended partition (n logical partition)

1 frequently view existing hard disk or partition commands:

[[email protected] desktop] #lsblk

NAME maj:min RM SIZE RO typemountpoint

SDA 8:0 0 20G 0disk

├─SDA1 8:1 0 500M 0part/boot

├─sda2 8:2 0 10G 0part/

├─sda3 8:3 0 2G 0part [SWAP]

├─SDA4 8:4 0 1K 0part

└─sda5 8:5 0 7G 0part/home

Sr0 11:0 1 3.8G 0rom

Or:

[[email protected] desktop] #ls/dev/sd*

/dev/sda

/dev/sda1

/dev/sda2

/dev/sda3

/dev/sda4

/dev/sda5

2 Partition command: fdisk


Basic format:
# fdisk/dev/vdb # because it is in the virtual machine, so the device path is finally VD, the reality may be SD or HD

For example:

[Email protected] ~]# fdisk/dev/sda2

Welcome to use fdisk (util-linux 2.23.2) .

The changes will remain in memory until you decide to write the changes to disk.

Think twice before you use the Write command.

Device does not contain a recognized partition table

Create a new DOS disk label using the disk identifier 0x30ba636e .

Command ( enter m for help ):

Enter m as follows:

Command ( enter m for help ):m

Command actions

A toggle a bootable flag

b Edit BSD Disklabel

C Toggle the DOS compatibility flag

D Delete a partition

G Create a new empty GPT partition table

G Create an IRIX (SGI) partition table

L list known partition types

M Print this menu

n Add a new partition

o Create a new empty DOS partition table

P Print the partition table

Q Quit without saving changes

s create a new empty Sun Disklabel

t change a partition ' s system ID

U Change display/entry units

V Verify the partition table

W Write table to disk and exit

X Extra functionality (experts only)

common interactive directives : 

    p View existing partition table  
    d Delete partition  


Q Discard Changes and exit
W Save changes and exit


Enter N to start the partition:

Command ( enter m for help ):n

Partition Type:

P Primary (0 primary, 0 extended, 4 free)

E Extended

Select (default P):

Using Default Response P

Partition Code (1-4, default 1):

Start Sector (2048-20971519, default = 2048):

The default value 2048 will be used

Last sector , + sector Or+size{k,m,g} (2048-20971519, default = 20971519):+100m

Partition 1 is set to Linux type, size set to MiB

Linux in the first 3 partitions are the default primary partition, if you do not want to replace can be directly ENTER to the last sector, plus the size of the partition you want, you can also in the select Enter e, select the extended partition. Note that the input partition size is sure to be added "+" before you can

You can save the exit by entering W after you have divided the area.

3 Formatting

mkfs toolset --------- partitioning commands

Commonly formatted partition file system formats are as follows:

–mkfs.ext3 partition device path

–MKFS.EXT4 partition device path

–MKFS.XFS partition device path

–mkfs.vfat-f partition device path

Note:Mkfs is followed by the file system type

For example:

[email protected] ~]# MKFS.EXT4/DEV/VDB1 # the partition VDB1 formatted as Ext4 File System Type

④ Mount use

[[Email protected] ~] #mkdir/part1

[[Email protected] ~] #mount/dev/vdb1/part1

Note: This hangs in the mode only when the boot state is useful, if the computer is no longer able to use or view the contents of the vdb1 after shutdown and restart

If you want to implement the boot automatically hang on, you need to write the configuration file:

Boot auto Mount profile in /etc/fstab

Use vim to edit the fatab :

/dev/vdb1/part1 EXT4 Defaults 0 0

After writing the above command, it is possible to automatically mount the boot

Add: If a hard disk has been semicolon-delimited for some partitions and there are already mounted partitions, you must use the partprobe command to refresh the partition table to add the new partition to the partition table after you continue partitioning the hard disk.

The basic partitioning steps are as follows:

1. lsblk View hard Drive information

2. Fdisk Partitioning

3. Partprobe Refresh the new partition table

4. MKFS.XFS Formatted partition

5. Mount Mount (/etc/fstab boot auto mount)


About hard disk partitioning operations in Linux

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.