Linux hard disk identification:

You can run the “fdisk -l” command to list the currently connected disks in the system

Device and partition information. If the new hard disk does not have partition information, only disk size information is displayed.

1. Shut down the server and add a new hard disk

2. Start the server and log in as the root user

3. View the disk information

#fdisk -lDisk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0004406e Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 2589 20480000 83 Linux /dev/sda3 2589 2850 2097152 82 Linux swap / Solaris /dev/sda4 2850 5222 19057664 5 Extended /dev/sda5 2850 5222 19056640 83 Linux Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x14b52796 Device Boot Start End Blocks Id SystemCopy the code

4. Create a new disk partition command parameters:

Fdisk You can run the m command to view the internal commands of the fdisk command.
A: Specifies the boot partition.
D: Deletes an existing partition.
L: displays a list of partition IDS.
M: View the help of the fdisk command.
N: creates a new partition.
P: displays the partition list.
T: command to change the partition type ID.
W: The command is to save the changes to the partition table for it to take effect

5. Access the disk and partition the disk. Note the red part.

#fdisk /dev/sdb
Command (m for help):n Command action e extended p primary partition (1-4) // P Partion number(1-4) : 1 // Enter l here to enter logical partition stage; First cylinder (51-125, default 51): // It is best to press Enter directly, if you enter a non-default number, you will waste space; Using default value 51 Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): Note: this is the partition size, +200M is the size of 200M; Of course, you can also calculate according to the size of the unit p, and then specify the value of End. Let's go back and see how it worked out; I'm going to add it plus 200M, just to make it a little bit more intuitive. If you want to add a partition of about 10GB, enter +10000M; Command (mfor help): w // Finally enter w and press Enter to save.Copy the code

Check it out:

#fdisk -l
Copy the code

You can see the /dev/sdb1 partition, so I’ll skip the screenshot.

6. Format partitions:

Note: Format /dev/sdb1 to ext3Mke2fs 1.41.12 (17-May-2010) File system label = OS :Linux block size =4096 (log=2) Block size =4096 (log=2) Stride=0 blocks, width=0 blocks 640848 inodes, 2562359 blocks 128117 blocks (5.00%) Reservedfor=0 Maximum filesystem blocks=2625634304 79 block groups 32768 blocks per group, 32768 fragments per group 8112 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Complete Writing superblocks and Filesystem Accounting Information: This filesystem will be automatically checked every 35 mounts or 180 days. You can use the filesystem to check every 35 mounts or 180 days. whichever comes first. Use tune2fs -c or -i to override.Copy the code

Now that it’s formatted, we can mount the partition and use the filesystem;

Create /data1 directory:

#mkdir /data1
Copy the code

8. Start mounting partitions:

#mount /dev/sdb1 /data1
Copy the code

9. Check the disk size and mount partition:

#df -h
Copy the code

10. Configure automatic mounting upon startup

Since the mount fails after the server restarts, you need to write the partition information to the /etc/fstab file to mount it permanently:

#vim /etc/fstab

Copy the code

Add:

/dev/sdb1 /data1 (mount directory) ext3 (file format) defaults 0 0Copy the code

11. Restart the system