Formatting and mounting the hard disk

Linux hard disk mounting is a solution to using external hard disks on Linux systems. Here we will introduce step by step how to check the number of hard disks currently on the machine, create disk partitions for the hard disks to be mounted, and format the partitions to be mounted. , Mount the partition, here are the first two steps of Linux hard disk mounting.
Linux hard disk mounting steps 1. First check how many hard disks there are currently on the machine. There are two kinds of commands to check:
Command 1: # fdisk –l
Command 2: # dmesg | grep sd
Among them: fdisk command description is as follows:
fdisk command usage: observation The physical usage of the hard disk and the use of partitioning the hard disk.
How to use the fdisk command:
1. Enter fdisk -l on the console to observe the physical usage of the hard disk.
2. Enter fdisk /dev/sda (specific disk name) on the console to enter the split hard disk mode.
Enter m to display a list of all commands.
Enter p to display the hard disk partition situation.
Enter a to set the hard disk boot area.
Enter n to set up a new hard disk partition.
Enter e hard disk as [extend] partition (extend).
Enter p hard disk as the [primary] partition (primary).
Enter t to change the hard disk partition properties.
Enter d to delete the hard disk partition attribute.
Enter q to end without saving the hard disk partition attribute.
Enter w to end and write the hard disk partition properties.
The description of the dmesg command is as follows:
Function description: Display the boot information.
Syntax: dmesg [-cn][-s]
Supplementary note: The kernel will store the boot information in the ring buffer. If you don't have time to view the information when you boot, you can use dmesg to view it. Boot messages are also stored in a file named dmesg in the /var/log directory.
Parameters:
-c After displaying the information, clear the content in the ring buffer.
-s is preconfigured to 8196, which is exactly equal to the size of the ring buffer.
-n Configure the level of logging information.

Linux hard disk mounting step 2. Create a disk partition for the hard disk to be mounted
1: Create a hard disk partition

An example of creating a disk partition is as follows:
# fdisk /dev/sdb
Enter fdisk mode:
Command (m for help):m //View the fdisk command help
Command (m for help):n //Create a new partition
Command action:
e extended / /Enter e to create an extended partition
p primary partition (1-4) //Enter p to create a primary partition, here we choose p
Partion number(1-4): 1 //The first extended partition can be divided up to the maximum according to requirements 4 primary partitions
First Cylinder(1-1014,default 1): 1 //Number of disk blocks starting from the first primary partition, you can choose the default value
Last cylindet or +siza or +sizeM or +sizeK: +1024MB // It can be a number in MB or the number
of disk blocks. Here we enter +1024MB to indicate that the partition size is 1G
, so we have created a partition. If you want to create more partitions, you can continue to create them according to the above steps. Save the partition with w after all partitions are created.
Command (m for help): w
The partition table has been altered!

2: Formatting

The formatting steps are as follows:

1. Create a new mount folder

mkdir /xvdb2

2. Format and mount the hard disk partition

mount -t ext4 -o rw /dev/xvdb2 /xvdb2

3. Automatically mount hard disks
 into /etc/fstab to enable at boot:
/dev/xvdb2 /xvdb2 ext4 defaults 0 0

In order to be able to automatically mount at system startup. We can edit the /etc/fstab configuration file.
Add at the end of the file:
/dev/xvdb2 /xvdb2 ext4 defaults 0 0

/dev/xvdb2 is the name of the hard disk partition, preferably UUID

blkid view UUID

root@root~$  blkid /dev/sda1
/dev/sda1: LABEL="win7" UUID="40305E93305E9030" TYPE="ntfs"

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327048064&siteId=291194637