Use fdisk/mke2fs/mount in linux to add a new hard disk partition

Source: Internet
Author: User
To add a hard disk for linux, you need to partition the disk before formatting it, and mount the partition before using it.

Disk Partition

A hard disk can have a maximum of four primary partitions. the larger partitions need to be placed in the extended partition. The information is stored in the MBR (master boot recorder) of the disk, that is, the primary boot partition;

MBR is located in the hard disk's 0-track, the first hard disk to be read. when the MBR is damaged, the entire hard disk will be reimbursed;

After a hard disk partition is formatted into fdisk, each partition is a file system. by default, the starting position of each file system is the super block, which stores the metadata of the partition, including the total number of blocks and inode, the size of each block and inode, the file system loading time, and the valid bit;

When the super block is damaged, the partition will be reimbursed;

The super block and block group information of ext2/3 can be read through dump2fs, and the root permission is required;

-H: only check the super block

-B: View bad blocks.

View the file systems supported by linux. you can call ls-l/lib/modules/'uname-r'/kernel/fs;

$ Ls-l/lib/modules/'uname-r'/kernel/fs

Total 160

Drwxr-xr-x 2 root 4096 Dec 17 2007 autofs4

Drwxr-xr-x 2 root 4096 Dec 17 2007 cifs

Drwxr-xr-x 2 root 4096 Dec 17 2007 cramfs

Drwxr-xr-x 2 root 4096 Dec 17 2007 exportfs

Drwxr-xr-x 2 root 4096 Dec 17 2007 ext3

Drwxr-xr-x 2 root 4096 Dec 17 2007 fat

Drwxr-xr-x 2 root 4096 Dec 17 2007 freevxfs

Drwxr-xr-x 2 root 4096 Dec 17 2007 hfs

Drwxr-xr-x 2 root 4096 Dec 17 2007 hfsplus

Drwxr-xr-x 2 root 4096 Dec 17 2007 jbd

Drwxr-xr-x 2 root 4096 Dec 17 2007 jffs2

Drwxr-xr-x 2 root 4096 Dec 17 2007 lockd

Drwxr-xr-x 2 root 4096 Dec 17 2007 msdos

Drwxr-xr-x 2 root 4096 Dec 17 2007 nfs

Drwxr-xr-x 2 root 4096 Dec 17 2007 nfs_common

Drwxr-xr-x 2 root 4096 Dec 17 2007 nfsd

Drwxr-xr-x 2 root 4096 Dec 17 2007 nls

Drwxr-xr-x 2 root 4096 Dec 17 2007 smbfs

Drwxr-xr-x 2 root 4096 Dec 17 2007 udf

Drwxr-xr-x 2 root 4096 Dec 17 2007 vfat

If you have enabled a file system, use cat/proc/filesystems;

$ Cat/etc/filesystems

Ext3

Ext2

Nodev proc

Nodev devpts

Iso9660

Vfat

Hfs

Linux uses VFS, a virtual file system, to provide unified calling interfaces for all file systems;

 

Initialize the file system

Disk formatting uses the mke2fs command, which has many common options as follows:

-B: block size, including 1024/2048/4096 bytes

-I: The size of each inode in bytes.

-J: create ext3 journal

-N: simulate and test the file creation effect, but it is not actually executed.

-N: Number of inode allocated. the number of inode cannot be changed after the file system is created.

-S: Initializes the super block and group descriptor. generally, it is treated as the last action after the Super block and its backup are damaged. e2fsck detection should be called immediately after use.

 

Load

Note: After a partition is loaded to a directory, its original subdirectories will be temporarily hidden until the partition is detached. different file systems may have different options, the following sections apply only to ext3

Using the mount command, many common options are as follows:

-O: partition loading options, including rw (read/write)/ro (read-only); noatime does not update the access time, which can be accelerated; noexec does not allow the execution of binary mechanism files;

-Grpid: specifies the default group for newly created files. if this group is not set, the fsgid of the current process is used.

-Sb = n: specifies the super block location. the default value is 1. each 8192 blocks in earlier versions have a redundant backup, that is, 1st/8193/16385 .. these are all super blocks, which can cause waste when the file system is too large. in the mke2fs version 1.08, the-s option is added, that is, the sparse super block sparse superblock,

-Data: specifies the log mode of file data (non-metadata): journal-write logs before data is written to the file system; ordered-default: write data before logs; writeback --

-A: load all file systems listed in/etc/fstab.

-N: load but not update/etc/mtab. it can be used when/etc is readable.

-L/U: load the file system with the specified tag name or UUID

 

Modify disk parameters

Some parameters may be modified as needed after the disk is loaded. you can use the following command

Mknod

Creates a character or block device and assigns it a device number;

All the hard drive, floppy disk, keyboard, and other external devices in Linux are stored in/dev, but the kernel cannot identify file names such as/dev/sda, in fact, it uses the primary/secondary device number to distinguish different devices;

A device driver table is maintained in the kernel. The main device number represents the device type, and the secondary device number represents the specific device of the type. Both are stored in the I-node of the device, the value cannot be modified at will;

Mknod can also be used to create a FIFO file

$ Pwd

/Dev

$ Ll cpu * | head-5

Crw ------- 1 root 203, 0 Oct 6 cpu0

Crw ------- 1 root 203, 1 Oct 6 cpu1

Crw ------- 1 root 203, 10 Oct 6 cpu10

Crw ------- 1 root 203, 11 Oct 6 cpu11

Crw ------- 1 root 203, 12 Oct 6 cpu12

$ Ll md * | head-5

Brw-rw ---- 1 root disk 9, 0 Oct 5 md0

Brw-r ----- 1 root disk 9, 1 Oct 5 md1

Brw-r ----- 1 root disk 9, 10 Oct 5 md10

Brw-r ----- 1 root disk 9, 11 Oct 5 md11

Brw-r ----- 1 root disk 9, 12 Oct 5 23: 30 md12

 

Hdparm

Only IDE and SATA are supported. sdparm is used for SCSI.

Set hard disk parameters, such as disabling write-back and enabling DMA

-D get/set using_dma flag, d1 enables the DMA mode, the so-called DMA skips the CPU to directly access the memory

-- Direct use O_DIRECT to bypass page cache for timings

-F flush buffer cache for device on exit

-M get/set multiple sector count.-m16 means that an IO interrupt reads 16 sectors from the disk.

-P set drive prefetch count

-T View disk read count

-T View cache read count

$ Sudo hdparm-tT/dev/hda

/Dev/hda:

Timing buffer-cache reads: 128 MB in 1.34 seconds = 95.52 MB/sec

Timing buffered disk reads: 64 MB in 17.86 seconds = 3.58 MB/sec

$ Sudo hdparm/dev/hda

/Dev/hda:

Multcount = 0 (off)

I/O support = 0 (default 16-bit)

Unmaskirq = 0 (off)

Using_dma = 0 (off)

Keepsettings = 0 (off)

Nowerr = 0 (off)

Readonly = 0 (off)

Readahead = 8 (on)

Geometry = 1870/255/63, sectors = 30043440, start = 0

Multcount is the number of sector S read at an I/O interruption. it can be adjusted through-m to effectively reduce CPU usage and increase IO performance.-m16 reads 16 sectors at a time;

I/O support determines the default data transmission from PCI to controller. Currently, 32bit and-c3 are generally supported to activate 32bit transmission.

Unmaskirq enables this function. linux receives other interruptions when processing disk interruptions, that is, when the disk returns request data, linux can handle other interruption-related tasks.

 

Tune2fs

After the file system is created, some parameters can be adjusted through tune2fs.

-J: added the ext3 journal option to the file system.

-L: list Super block content

-L: Set the disk tag.

-M: set the percentage of reserved disks.

-U: Set the user who can access the reserved data block, and assign the uid or user name

Related Article

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.