Linux挂载磁盘教程

###挂载前查看各分区基本情况:

1
2
3
4
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda2 36G 2.3G 32G 7% /
tmpfs 15G 0 15G 0% /dev/shm

###查看各磁盘基本情况:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost ~]# fdisk -l 
Disk /dev/xvda: 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: 0x00014faa

Device Boot Start End Blocks Id System
/dev/xvda1 1 523 4194304 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/xvda2 * 523 5222 37747712 83 Linux

Disk /dev/xvde: 493.9 GB, 493921239040 bytes
255 heads, 63 sectors/track, 60049 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

###挂载磁盘/dev/xvde的具体步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[[email protected] ~]# fdisk /dev/xvde 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb28f7207.
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): p^H
Disk /dev/xvde: 493.9 GB, 493921239040 bytes
255 heads, 63 sectors/track, 60049 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: 0xb28f7207
Device Boot Start End Blocks Id System
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
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
x extra functionality (experts only)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-60049, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-60049, default 60049):
Using default value 60049
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

###在不重启的情况下识别出来刚才创建的分区:

1
2
3
[[email protected] ~]# partprobe 
Warning: WARNING: the kernel failed to re-read the partition table on /dev/xvda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.

###再次查看各磁盘基本情况:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost ~]# fdisk -l 
Disk /dev/xvda: 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: 0x00014faa

Device Boot Start End Blocks Id System
/dev/xvda1 1 523 4194304 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/xvda2 * 523 5222 37747712 83 Linux

Disk /dev/xvde: 493.9 GB, 493921239040 bytes
255 heads, 63 sectors/track, 60049 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: 0xb28f7207

Device Boot Start End Blocks Id System
/dev/xvde1 1 60049 482343561 83 Linux /*系统已接入磁盘*/

###以ext3的格式格式化磁盘:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@localhost ~]# mkfs.ext3 /dev/xvde1 
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
30146560 inodes, 120585890 blocks
6029294 blocks (5.00%) reserved for the super user

First data block=0
Maximum filesystem blocks=4294967296
3680 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

###编辑磁盘挂载配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[[email protected] ~]# vim /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Tue Mar 26 14:54:14 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=5056bbc2-cf00-4f7c-95e1-35be323fc523 / ext3 defaults 1 1
UUID=c2a7b4a1-c806-46e5-a97d-b9a964fc9e05 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/xvde1 /opt/ ext3 defaults 0 0 /*增加这一行内容*/

###执行挂载:

1
[root@localhost ~]# mount -a

###查看各分区基本情况:

1
2
3
4
5
[[email protected]calhost ~]# df -h 
Filesystem Size Used Avail Use% Mounted on
/dev/xvda2 36G 2.3G 32G 7% /
tmpfs 15G 0 15G 0% /dev/shm
/dev/xvde1 453G 199M 430G 1% /opt /*/opt分区已挂载上/dev/xvde1这个磁盘*/