Details how to mount a new hard disk under Linux

  • 2020-06-03 09:08:34
  • OfStack

Linux hard disk recognition:

Generally use the "ES5en-ES6en" command to list the hard disk currently connected to the system

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

1. Close the server and add a new hard disk

2. Start the server and log in as root user

3. Check your hard drive


#fdisk -l

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 new hard disk partition command parameters:

fdisk can use the m command to see the internal commands of the fdisk command;

a: The command specifies the boot partition; d: command to delete 1 existing partition; l: The command displays a list of partition ID Numbers; m: View the fdisk command help; n: command to create 1 new partition; p: The command displays the partition list; t: command to change the type of partition ID; w: The command is to save the changes to the partitioned table for it to take effect.

5. Enter the disk, partition the disk, pay attention to the red part.


#fdisk /dev/sdb

Command (m for help):n 
Command action 
    e  extended         // The input e To create an extended partition  
    p  primary partition (1-4)   // The input p To create logical partitions  
p 
Partion number(1-4) : 1   // I'm gonna type in here l , and enter the logical partition phase;  
First cylinder (51-125, default 51):  // Note: This is the partition Start  Value; It's better to press Enter here if you've entered it 1 A non-default number, which 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 defines the partition size, +200M  That's the magnitude of 200M  ; Of course, you can also according to p Suggested unit cylinder I'm going to calculate the size of theta and then I'm going to specify it  End The numerical values. Let's go back and see how we did it; Or use +200M This is the way to add it, just so it's intuitive 1 Points. If you want to add 1 a 10G About the size of the partition, please enter  +10000M  ;  
 
Command (m for help): w           // The last input w Enter and save.  

Check 1 below:


#fdisk -l

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

6. Format partition:


#mkfs.ext3 /dev/sdb1      // Note: /dev/sdb1 Formatted as ext3 type 

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

With that formatted, we can load the partition using mount and then use the file system;

7. Create /data1 directory:


#mkdir /data1

8. Start mounting partition:


#mount /dev/sdb1 /data1

9. View hard disk size and mount partition:


#df -h

10. Configure automatic mount on startup

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


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 
0

Add:

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

Restart the system


Related articles: