How to mount the second hard disk in Linux system

888u

Last update at :2024-05-13,Edit by888u

The cloud host has two hard disks. The first hard disk is generally 10G and is used to install the system. The second disk has different sizes depending on the type of cloud host. We recommend that you use the second hard drive as a data disk to store your website data, so that when you restore the system, the data on the data disk will not be formatted and deleted. For newly activated cloud hosts, the second hard drive is not mounted by default and we need to mount it manually. Below we will explain step by step how to mount the second hard drive.

1. Check hard disk information: The method to view all hard disks in your Linux system is: fdisk -l

You can see that only the first hard disk /dev/sda 10.7G is mounted and used by the system, while the second hard disk /dec/sdb 32.2G is not mounted. It just cannot be used by the system. In fact, we can also check the hard disk usage of the current system through the df -h command:

2. Create a new partition for the second hard drive (/dev/sdb): Here we use the fdisk command. The command line usage of fdisk is: fdisk hard disk device name

In this way, we enter the interactive mode of fdisk. We can enter different commands after "Command (m for help):" to complete our operation. fdisk provides 5 basic operations accordingly: n – create a new partition d – Delete an existing partition p – Print existing partition table w – Write changes to the partition table, that is, save them. q – exit fdisk Note: All your operations will only take effect after being saved with the "w" command. Let’s start our actual operation: 1). First, use the "p" command to look at the existing partition table of our hard disk:

There is no partition information. 2) Create a new partition Create a new partition using the "n" command:

Two menus appear, "e" indicates extended partition and "p" indicates primary partition. What we have here is a second separate hard disk. You can create a primary partition directly. Enter "p" at the bottom and press Enter.

"Partition number:" is the partition number, we enter 1. "First cylinder:" is the starting cylinder, the default is 1, you can enter "1", or enter nothing, and then press Enter. "Lastcylinder:" is the ending cylinder. The default is the last cylinder number of your hard disk, which means that the newly created partition contains all the remaining space. We use the default and press Enter. Use the "p" command to look at our current hard disk partition table. The partition /dev/sdb1 we just created appears: 4), save and exit Note that after creation, we must use the "w" command to save our operations, otherwise, all your operations will be wasted:

Then, use the "q" command to exit fdisk. At this point, our hard disk still cannot be mounted because we still need to format our partition into a file format that the Linux system can read.

3. Format the hard drive Formatting a hard drive is very simple and can be done with just one command, but we need to first check the partition we need to format: Also use fdisk -l to check the partition information:

Then use mkfs to format the partition /dev/sdb1: [root@htuidc ~]# mkfs -t ext4 /dev/sdb1 The parameter -t represents the file system format to be formatted, here it is ext4 format. The process is as follows:

4. Mount partition You can mount your second hard disk to any directory. I mounted it to my /data directory (if there is no /data directory, it needs to be created in advance): [root@htuidc~]# mkdir /data In this way, you can place your website data in the /data directory, which ensures that the data will not be lost when the system is reinstalled or the system disk is damaged. Of course, you can also mount it to other directories. Okay, next I will mount my partition /dev/sdb1 to the /data directory: [root@htuidc ~]# mount /dev/sdb1 /data Then check the space usage of our file system: [root@htuidc ~]# df -h

5. Configure automatic mounting at boot At this point, we have successfully mounted the second hard drive, but you may find that if I restart my system, I need to remount the partition /dev/sdb1. We can set the system to automatically mount it when it starts. There are two ways to achieve this: 1) Write the mount command to /etc/rc.local: [root@htuidc ~]# echo “mount /dev/sdb1 /data” >> /etc/rc.local 2), use the /etc/fstab file. /etc/fstab is a file system that is automatically mounted to Linux during boot. Edit the /etc/fstab file and add a new line at the end as follows:

The data items of /etc/fstab are explained as follows: /dev/sdb1 /data ext4 defaults 1 2 /dev/sdb1 – is the device that needs to be mounted. /data – is the mount point. /, /usr, and swap are all default mount points for partitions during system installation. ext4 – refers to the file system type. defaults – refers to the rules when mounting. 1 – refers to dump (system backup tool). 1 means backup, 0 means never backup. If you last used dump to back up, the number of days since the backup will be displayed. 2 – refers to fsck (the order of fsck checks at startup). If it is 0, it means no checking. The (/) partition will always be 1, and other partitions can only start from 2. When the numbers are the same, they will be checked at the same time (but there cannot be two 1s). Note: After you modify /etc/fstab, you must reboot the system for it to take effect. Note: We recommend you use the second method, but if you use the second method, you must pay attention to the format, otherwise you will be unable to boot when you restart.

Recommended site searches: php virtual host, Hong Kong high-defense server registration and cancellation, foreign server rental price, website registration number, server in the United States, foreign server rental price, Hong Kong virtual host space, purchase of high-defense server, Wanwang domain name registration Official website,

How to mount the second hard disk in Linux system

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码