How to mount disks on Linux

When you use the virtual machine, you find that there is not enough disk space and you need to mount a disk for continued use, but the disk is not added for use and you need to mount it.

1. Add Disks

Add a new hard drive to restart the server

After adding, you can restart the machine. If your machine is on, you can't see the disk you just added when entering the system. The installed disk will not be displayed until the system is restarted.

2. Entry System

Use root user to enter the system

3. View Hard Disk Information

[root@localhost ~]# Fdisk-l //disk command
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000c4cb5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xd0f5c869

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00000000

You can see that this machine loads three disks, sda, sdb, sdc
Where sda is the initial disk, sdb is initialized and used, sdc is the newly loaded, unformatted new disk

4. Create a new hard disk partition

[root@localhost ~]# fdisk /dev/sdc #Enter Disk
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x45a3cadb.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): m
Command action
   a   toggle a bootable flag      #Set Startable Tag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition          #Delete a partition
   l   list known partition types  #ID for each partition type
   m   print this menu             #menu
   n   add a new partition         #Add a partition
   o   create a new empty DOS partition table
   p   print the partition table   #Display current partition information under this disk
   q   quit without saving changes #Exit without saving
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit #Save Exit
   x   extra functionality (experts only)

Once you know the command, you can partition

Command (m for help): p //Print the partition information and you can see that there are no partitions currently

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x45a3cadb

   Device Boot      Start         End      Blocks   Id  System

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 logical partition  
p
Partition number (1-4): 1//Partition Logical Partition
First cylinder (1-2610, default 1): //I'm returning here directly. I don't want to divide the disk into multiple partitions and use the entire disk as a partition
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): 
Using default value 2610

Command (m for help): p //Check again to see that the disk already has a partition

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x45a3cadb

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2610    20964793+  83  Linux
Command (m for help): w //Save partition
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Use the fdisk-l command again to view disk information

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x406a4c58

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2610    20964793+  83  Linux

The third disk/dev/sdc is partitioned

5. Formatting partitions

[root@localhost ~]# mkfs.ext3 /dev/sdc1
//take/dev/sdc1 Format as ext3 type,It looks like most disks are formatted ext3 type,Why is there no in-depth study?,Not clear yet,Friends you want to know can check for themselves
[root@localhost ~]# mkfs.ext3 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
File System Label=
Operating System: Linux
 Block size=4096 (log=2)
Block size = 4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
 First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000

Writing inode table: done                            
Creating journal (32768 blocks): complete
 Writing superblocks and filesystem accounting information:

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Once formatted, you can mount the partition using the "mount" command and use this disk space

6. Mount partition and boot-up auto-mount

[root@localhost ~]# Df-h //Only sda1 and sdb1 disks are mounted at this time
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   18G   15G  1.5G  92% /
tmpfs                         932M   76K  932M   1% /dev/shm
/dev/sda1                     485M   40M  421M   9% /boot
/dev/sdb1                      20G  1.2G   18G   7% /disk/diskone
/dev/sr0                      4.2G  4.2G     0 100% /media/CentOS_6.5_Final
[root@localhost /]# cd /disk/
[root@localhost disk]# ll
//Total dosage 4
drwxr-xr-x. 4 root root 4096 7month  28 17:04 diskone
[root@localhost disk]# cd diskone/
[root@localhost diskone]# ll
//Total dosage 20
drwx------. 2 root root 16384 7month  28 16:12 lost+found
drwxr-xr-x. 2 root root  4096 7month  28 17:09 software
[root@localhost diskone]# cd ../
[root@localhost disk]# mkdir disktwo //Create mounted path
[root@localhost disk]# ll
//Total dosage 8
drwxr-xr-x. 4 root root 4096 7month  28 17:04 diskone
drwxr-xr-x. 2 root root 4096 8month   1 16:48 disktwo
[root@localhost disk]# Mount/dev/sdc1/disk/disktwo/ //mount
[root@localhost disk]# Df-h // Look again and find that sdc1 is mounted under the / disk/disktwo path
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   18G   15G  1.5G  92% /
tmpfs                         932M   76K  932M   1% /dev/shm
/dev/sda1                     485M   40M  421M   9% /boot
/dev/sdb1                      20G  1.2G   18G   7% /disk/diskone
/dev/sr0                      4.2G  4.2G     0 100% /media/CentOS_6.5_Final
/dev/sdc1                      20G  173M   19G   1% /disk/disktwo

Disk is mounted
Set up boot-up automount below
Edit/etc/fstab file and add it at the end
/dev/sdc1 (disk partition)/disk/disktwo (mount directory) ext3 (file format) defaults 0

vim /etc/fstab
/dev/sdc1(Disk Partition)  /disk/disktwo(Mount Directory) ext3(File Format) defaults  0  0

Then restart OK!!!

Keywords: Linux vim

Added by kybaker on Sat, 08 Jun 2019 21:23:23 +0300