An example of how to mount a disk under Linux
When using the virtual machine, it is found that the disk space is not enough, and a disk needs to be mounted for continued use, but the disk cannot be used by adding it, and it needs to be mounted.
1. Add a disk
Add a new hard disk and restart the server
After adding, you can restart the machine. If your machine is turned on, you cannot see the disk you just added when you enter the system. The installed disk will only be displayed after the system is restarted and reloaded.
2. Enter the system
Use root user to enter the system
3. View hard disk information
1
[root@localhost ~]# fdisk -l //disk command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
twenty three
twenty four
25
26
27
28
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 is loaded with three disks sda, sdb, and sdc
Where sda is the initial disk, sdb has been initialized and used, and sdc is the newly loaded, unformatted new disk
Fourth, create a new hard disk partition
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
twenty three
twenty four
25
26
27
28
29
30
[root@localhost ~]# fdisk /dev/sdc #Enter the 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 the bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition #delete a partition
l list known partition types #ID corresponding to 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 the current partition information under the disk
q quit without saving changes #Quit 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 and exit
x extra functionality (experts only)
After knowing the command, you can partition
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
twenty three
twenty four
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Command (m for help): p //Print partition information, you can see that there is no partition 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//divide logical partitions
First cylinder (1-2610, default 1): //I just press Enter here, because I don't want to divide the disk into multiple partitions, and use the entire disk as one 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 and you can see that the disk already has 1 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 the disk information
1
2
3
4
5
6
7
8
9
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 has been partitioned
Five, format the partition
1
2
[root@localhost ~]# mkfs.ext3 /dev/sdc1
//Format /dev/sdc1 as ext3 type, it seems that most of the disks are formatted as ext3 type, why there is no in-depth study, it is not clear for the time being, friends who want to know can check it by themselves
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
twenty three
twenty four
[root@localhost ~]# mkfs.ext3 /dev/sdc1
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
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 to inode table: done
Creating journal (32768 blocks): Done
Writing superblocks and filesystem accounting information: Done
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
After formatting, you can use the "mount" command to mount the partition, and then use the disk space
6. Mounting partitions and auto-mounting at startup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
twenty three
twenty four
25
26
27
28
29
30
31
[root@localhost ~]# df -h //Only two disks, sda1 and sdb1, 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 usage 4
drwxr-xr-x. 4 root root 4096 Jul 28 17:04 diskone
[root@localhost disk]# cd diskone/
[root@localhost diskone]# ll
Total dosage 20
drwx------. 2 root root 16384 Jul 28 16:12 lost+found
drwxr-xr-x. 2 root root 4096 Jul 28 17:09 software
[root@localhost diskone]# cd ../
[root@localhost disk]# mkdir disktwo //Create a mounted path
[root@localhost disk]# ll
Total usage 8
drwxr-xr-x. 4 root root 4096 Jul 28 17:04 diskone
drwxr-xr-x. 2 root root 4096 Aug 1 16:48 disktwo
[root@localhost disk]# mount /dev/sdc1 /disk/disktwo/ // mount
[root@localhost disk]# df -h //Check again and find that sdc1 has been 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 already mounted
Set the following to automatically mount at startup
Edit the /etc/fstab file and add at the end
/dev/sdc1 (disk partition) /disk/disktwo (mount directory) ext3 (file format) defaults 0 0
1
2
vim /etc/fstab
/dev/sdc1 (disk partition) /disk/disktwo (mount directory) ext3 (file format) defaults 0 0
After restarting it is OK! ! !
The above is the whole content of this article, I hope it will be helpful to everyone's learning, and I hope everyone will support Scripting Home.