Linux mount disk

Hard Disk Identification in Linux

  Generally, the "fdisk -l" command can be used to list the currently connected hard disks in the system.

  Device and partition information. The new hard disk has no partition information, only the hard disk size information is displayed.

1. Turn off the server and add a new hard disk

 shutdown -r

 reboot

2. Start the server and log in as root user

3. View hard disk information

fdisk -l

or df -h

Disk /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  System  

4. Create a new hard disk partition command parameters

fdisk can use the m command to view the internal commands of the fdisk command:
a: command to specify the boot partition;
d: command to delete an existing partition;
l: command to display a list of partition ID numbers;
m: to view the fdisk command help;
n: command to create A new partition;
p: command to display the partition list;
t: command to modify the type ID number of the partition;
w: command to save the modification to the partition table to make it work.

5. Go to the disk and partition the disk

fdisk /dev/sdb

Command (m for help):n  
Command action  
     e extended                   // Enter e to create an extended partition   
     p primary partition ( 1 - 4 )       // Enter p to create a logical partition   
p  
Partion number( 1 - 4 ): 1       // Enter l here to enter the logical partition stage;   
First cylinder ( 51 - 125 , default 51 ):    // Note: This is the Start value of the partition; it is best to directly Press Enter, if you enter a non-default number, it will cause a waste of space;   
Using default value 51   
Last cylinder or +size or +sizeM or +sizeK ( 51 - 125 , default 125 ): +200M Note: This is a definition For the partition size, +200M means the size is 200M; of course, you can also calculate it according to the size of the unit cylinder indicated by p, and then specify the value of End. Look back and see how it is calculated; it is still more intuitive to use the method of +200M to add. If you want to add a partition with a size of about 10G, please enter + 10000M;  
  
Command (m for help): w                      // Finally enter w and press Enter to save.  

  Take a look at fdisk -l and you can see the /dev/sdb1 partition.

6. Format the partition

mkfs.ext3 /dev/sdb1 //Note: Format /dev/sdb1 as ext3, ext4, etc. The specific choice depends on what kind of file system you need, or refer to the mounted disk through df -h.

mke2fs 1.41.12 (17-May-2010)  
filesystem label =  
Operating System: Linux  
block size = 4096 (log= 2 )  
chunk size = 4096 (log= 2 )  
Stride=0 blocks, Stripe width=0 blocks  
640848 inodes, 2562359 blocks  
128117 blocks (5.00%) reserved for the super user  
First data block = 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  
   
Writing to inode table: done  
Creating journal (32768 blocks): 完成  
Writing superblocks and filesystem accounting information: 完成  
   
This filesystem will be automatically checked every 35 mounts or  
180 days, whichever comes first.  Use tune2fs -c or -i to override.  

  This is formatted, we can mount the partition with mount, and then use the file system;

7. Create a disk mount directory

mkdir /data1

8. Start to mount the partition

mount /dev/sdb1 /data1

  Or you can:

vim /etc/fstab #Modify the table of disk mounts, add the last line:

/dev/sdb1  /data1  ext3 defaults 0 0  

9. Check the hard disk size and mounted partitions

df -h

10. Configure automatic mount at startup

  Because the mount will fail after restarting the server, you need to write the partition information to the /etc/fstab file to make it permanently mounted:

vim /etc/fstab

join in:

/dev/sdb1 (disk partition) /data1 (mount directory) ext3 (file format) defaults 0 0

11. Restart the system

  This depends on the system. Some systems need to be restarted, and some do not. As for whether they are needed or not, you can execute the command df -h after mount -a to check whether the mount is successful. If there is no restart, the mount is successful. , you don't need to restart.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325283875&siteId=291194637