Linux uses FDISK partition expansion

Source: Internet
Author: User
Tags reserved

Turn http://www.cnblogs.com/chenmh/p/5096592.htm

L

Overview

The server we manage may be running out of disk space as the volume of traffic grows, and at this point we need to increase disk space, this chapter mainly describes how to use the Fdisk partitioning tool to create disk partitions and mount partitions, two cases, one is to the original disk of the remaining space to increase the partition, The second is to partition the newly added disk.

Extended Space
Fdisk:invalid option--'-' usage:fdisk [options] <disk> change    partition table fdisk [options]-L <disk> List partition table (s) fdisk-s <partition>      give partition size (s) in blocksoptions:-B <size>                 Secto  R size (up, 1024x768, 2048 or 4096)-C                        switch off dos-compatible mode-h                        print help-u <size>                 give sizes in Sectors instead of Cylinders-v                        print version-c <number> Specify the number of               cylinders-h <number> Specify the number of               heads-s <number> Specify the number of               sectors per track

View current partition information

Fdisk-l

The red flag shows that the current SDA has a total of 3,916 cylinders, and currently only uses 2,611 cylinders, and now creates partitions on the remaining cylinders.

Creating partitions

Use: Fdisk disk File Fdisk/dev/sda

1. Enter M to view help.

A: Set bootable flag B: Modify BSD Disk label C: Set DOS operating system compatible tag d: Delete a partition L: Show known partition type, where 82 is a Linux swap partition, 83 is Linux partition m: Display Help information N: Add a new partition o: Create a new blank DOS partition table P: Show disk current partition Table Q: Quit the Fdisk program and do not save any modifications s: Create a new blank Sun disk label T: Change the system number of a partition (such as changing a Linux swap partition to a Linux partition) U: Change the display record Unit V: Verify the Disk partition Table W: Save the modified result and exit the FDISK program x: Special Features

2. Enter N to create a partition

Ask if we want to create a primary partition or an extended partition, the primary partition can only create up to 4, and if an extended partition is created then the extended partition needs to occupy a primary partition.

Here we create the extended partition, enter E

We need to enter the starting cylinder, the default is 2611 start, here can enter 2611 can also directly enter.

Finally, enter 3916 so that the extended partition is created.

3. Creating Logical partitions

Enter P to view the creation of the partition

You can find that the file system type of the SDA4 is an extended partition, the extended partition is unusable, and logical partitions must be created on the basis of the extended partition

Enter N to create the logical partition, because only the logical partition you just created needs to be created, so you don't have to select the input start and end bars.

Then enter p to display all the partitions, and you can see that the logical partition of SDA5 was created

4. Enter W Save

Of course, you can also create a primary partition directly, without creating a logical partition.

5. Formatting logical partitions

If you are using a virtual machine, a restart is required to format the partition, or you will be prompted not to find the partition file.

Mkfs-t Ext3/dev/sda5

6. Mount Partitions

Create a folder mounted on a partition first

Mkdir/newpar

Mount the SDA5 to the/newpar file

Mount/dev/sda5/newpar

7. View Mount Status

Df-h

This mount is temporary and requires a re-mount after restarting the server, making the mount permanent by modifying the/etc/fstab file

8. Permanent Mount

You can use the TAB key to write the next item when writing.

Concept

With the preheating in front, it is now easier to understand the concept.

Disk

All devices in a Linux system are stored as files. Devices are generally stored under the/dev directory, with SDA, SDA1, sda2 ..., SDB, sdb1...,hda,hdb. Now the device is generally the SD name, the old hard disk is named after ha.

SDA: The first hard disk, if the disk is partitioned there will be SDA1 (first partition), Sda2 and so on.

SDB: The second hard disk, the same hard disk partition after the SDB1,SDB2 and so on.

Partition

The purpose of partitioning is to facilitate management, such as in the Windows system we will generally divide the C, D, e disk and so on.

Look at the picture before you talk about the main partition and the extended partition.

This is my current Windows system partition situation, from here can well understand the concept of primary and extended partition, but also has the concept of cylinder, the current primary partition is the C drive, extended partition includes D, E, F disk. Meanwhile the D-disk, E-disk, F-disk are also called logical partitions.

In fact, we can not create an extended partition, in Windows if you do not create an extended partition, the management of the program will be inconvenient, only one partition. But in Linux if you just created a section of the message will find that Linux can only create 4 primary partitions, if you need to create more partitions so long must create a logical partition, where the logical partition needs to occupy a primary partition.

File system

Linux file system is the type of partition, in Windows has Ntef,fat32, etc., Linux is common in the Ext2, Ext3, EXT4, Linux swap, Proc, SYSFS, TMPFS, etc., The currently mounted file system can be viewed with the Mount name.

Formatting

One step after creating the partition is to format the partition, which is the same in the Windows system, and you will need to format the partition after you create the good one partition, only to format it to a specific file type.

Mount

You can use partition formatting in Windows, but you must mount the partition to a specific path on a Linux system.

The next step is to demonstrate the complete process of adding a new disk.

New Hard Drive

Add a 20G hard drive to the current virtual machine

1. Use Fdisk-l to query the current system partition status

You can see that the newly added SDB disk is not yet partitioned

2. Create a primary partition

FDISK/DEV/SDB Input N

At the end of the input bar, if you don't know how much to enter, you can enter + and enter the size you want to set. Here I set the 5G primary partition.

Enter P to view the partition information, you can see the SDB1 primary partition you just created, and then create the logical partition.

3. Create an extended partition

The operation steps are marked in red on the image. You can see that the SDB2 extended partition is currently created, the cylinder is 655-2610, and all the remaining space is created as an extended partition.

4. Creating Logical partitions

A total of two logical partitions have been created, the logical partition default starting from 5, the first logical partition size 2G, used for swap partition, all left to SDB6.

5. Modify the file type ID

Because the default partition ID is 83, the Linux file type, the SDB5 file type ID is now changed to 82, which is the swap partition.

6. Save Exit

7. Formatting partitions

The next step is to format each of the SDB's partitions,

Note: Extended partitions do not need to be formatted

Input MKFS.EXT3/DEV/SDB1

Swap partition formatting to use

Mkswap/dev/sdb5

Load file SWAPON/DEV/SDB5 See if it takes effect swapon-s

Can see SDA3, and SDB5 these two swap partitions

8. Mount Partitions

This is used to permanently mount the file by modifying it directly.

Create mount file path mkdir sdb1 sdb6

9. Immediate effect

No immediate effect on my virtual machine, restart the machine.

Shutdown-r now

Reboot will find that the SDB1,SDB6 has been in effect, and swap has become 6G (SDA3+SDB5)

Add

Formatted partitions can also use the MKE2FS command with parameters

MKE2FS [-c|-l filename] [-B block-size] [-F fragment-size] [-i-    bytes-per-inode] [-i-inode-size] [-j journal-options]< C4/>[-G META Group size] [-N number-of-inodes]    [-M reserved-blocks-percentage] [-o Creator-os]    [-G Blocks-per-group] [-l Volume-label] [-M last-mounted-directory]    [-o feature[,...]] [-R Fs-revision] [-e extended-option[,...]]    [-T Fs-type] [-U UUID] [-JNQVFKSV] device [Blocks-count]
-B: Specify the chunk size in bytes. -C: Check for damaged chunks. -F: Specifies the size of the discontinuous segment, in bytes. -F: MKE2FS is enforced regardless of the specified device. -I: Specifies the scale of "byte/inode". -N: Specifies the number of inode to be established. -L: From the specified file, read the corrupted chunk information in the file West. -L: Sets the name of the file system's label. -M: Specifies the ratio of reserved chunks to the administrator, which is preset to 5%. -M: Records the last directory that was mounted. -Q: No information is displayed when executing. -r: Specifies the version of the Ext2 file system to be established. -R: Sets the disk array parameters. -S: writes only superblock and group descriptors without changing the inode able Inode bitmap and block bitmap. -V: Displays detailed information when executing. -V: Displays version information. -T: Specify File system type

DUMPE2FS command

View the details of a partition DUMPE2FS/DEV/SDB1

Only a subset of the information is captured in the figure, which allows you to view detailed information about the specified partition.

Summarize

The file system now recommends using EXT4, which is just a test using ext3, and the production environment is better for using logical volumes.

Linux uses FDISK partition expansion

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.