centos 挂载硬盘

Linux磁盘挂载操作手册

转自:http://wenku.baidu.com/link?url=rlCF2zTPJKXwB3VhlK9DSQAgvXjOmkWJfMXrLjhSMwl6zBcy6IysyUsFvWYdn2UhSdoAq32xKBLGpOVdWmNEsREpT5E1BjgVSLyaHXDA8sS

一、挂载单个分区小于2T的分区

1.查看系统当前分区情况

命令df –h

实例:

Last login: Fri Oct 26 00:01:51 2012 from e10-3

E10-3:~ # df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda2              40G  4.7G   33G  13% /

devtmpfs               12G  144K   12G   1% /dev

tmpfs                 3.9G  100K  3.9G   1% /dev/shm

/dev/sda1             479M   72M  383M  16% /boot

/dev/sda5             869G  201M  824G   1% /home

/dev/sr0              2.9G  2.9G     0 100% /media/SLES-11-SP1-DVD-x86_64.0432..001

 

2.查看系统当前硬盘分区情况

命令:fdisk –l 

E10-3:~ # fdisk -l

 

Disk /dev/sda: 999.0 GB, 998999326720 bytes

255 heads, 63 sectors/track, 121454 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: 0x00004cb7

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          63      506016   83  Linux

/dev/sda2              64        5284    41937682+  83  Linux

/dev/sda3            5285        6328     8385930   82  Linux swap / Solaris

/dev/sda4            6329      121454   924749595    f  W95 Ext'd (LBA)

/dev/sda5            6329      121452   924733498+  83  Linux

 

Disk /dev/sdb: 999.0 GB, 998999326720 bytes

255 heads, 63 sectors/track, 121454 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

 

Disk /dev/sdc: 4994.0 GB, 4993981612032 bytes

255 heads, 63 sectors/track, 607150 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table

3.创建新的硬盘分区

命令: fdisk /dev/sdb

注:这里的/dev/sdb是具体一个硬盘,此参数可改成fdisk –l显示的硬盘的序号。

 

实例:

E10-3:~ # fdisk /dev/sdb

 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

 Building a new DOS disklabel with disk identifier 0xd3f0a6aa.

 Changes will remain in memory only, until you decide to write them.

 After that, of course, the previous content won't be recoverable.

 

 The number of cylinders for this disk is set to 121454.

 There is nothing wrong with that, but this is larger than 1024,

 and could in certain setups cause problems with:

 1) software that runs at boot time (e.g., old versions of LILO)

 2) booting and partitioning software from other OSs

    (e.g., DOS FDISK, OS/2 FDISK)

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

 

 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)

 e

 Partition number (1-4): 1

 First cylinder (1-121454, default 1): 1

 Last cylinder, +cylinders or +size{K,M,G} (1-121454, default 121454): 

 Using default value 121454

 

 Command (m for help): p

 

 Disk /dev/sdb: 999.0 GB, 998999326720 bytes

 255 heads, 63 sectors/track, 121454 cylinders

 Units = cylinders of 16065 * 512 = 8225280 bytes

 Disk identifier: 0xd3f0a6aa

 

    Device Boot      Start         End      Blocks   Id  System

 /dev/sdb1               1      121454   975579223+   5  Extended

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

E10-3:~ # fdisk -l

 

 Disk /dev/sda: 999.0 GB, 998999326720 bytes

 255 heads, 63 sectors/track, 121454 cylinders

 Units = cylinders of 16065 * 512 = 8225280 bytes

 Disk identifier: 0x00004cb7

 

    Device Boot      Start         End      Blocks   Id  System

 /dev/sda1   *           1          63      506016   83  Linux

 /dev/sda2              64        5284    41937682+  83  Linux

 /dev/sda3            5285        6328     8385930   82  Linux swap / Solaris

 /dev/sda4            6329      121454   924749595    f  W95 Ext'd (LBA)

 /dev/sda5            6329      121452   924733498+  83  Linux

 

 Disk /dev/sdb: 999.0 GB, 998999326720 bytes

 255 heads, 63 sectors/track, 121454 cylinders

 Units = cylinders of 16065 * 512 = 8225280 bytes

 Disk identifier: 0xd3f0a6aa

 

    Device Boot      Start         End      Blocks   Id  System

 /dev/sdb1               1      121454   975579223+   5  Extended

 

 Disk /dev/sdc: 4994.0 GB, 4993981612032 bytes

 255 heads, 63 sectors/track, 607150 cylinders

 Units = cylinders of 16065 * 512 = 8225280 bytes

 Disk identifier: 0x00000000

 

 Disk /dev/sdc doesn't contain a valid partition table

 

4.创建挂载点

即创建目录,以便将新建的分区挂载到新目录下

命令:mkdir -p /webroot/1

实例:

E10-3:~ # mkdir -p /webroot/1

 

5.挂载分区

命令:mount /dev/sdb1   /webroot/1 

说明:其中/dev/sdb5是硬盘,/webroot/1是挂载点,即挂载到的目录

实例:

 

E10-3:/etc # mount /dev/sdb1 /webroot/1 

 mount: you must specify the filesystem type

 

E10-3:/etc # mount -t ext3 /dev/sdb1   /webroot/1 

mount: wrong fs type, bad option, bad superblock on /dev/sdb1,

       missing codepage or helper program, or other error

      In some cases useful info is found in syslog - try

       dmesg | tail  or so

 

E10-3:/etc # mkfs.ext3 -L /webroot/1  /dev/sdb1 

mke2fs 1.41.9 (22-Aug-2009)

mkfs.ext3: inode_size (128) * inodes_count (0) too big for a

        filesystem with 0 blocks, specify higher inode_ratio (-i)

        or lower inode count (-N).

E10-3:/ # mkdir -p /webroot/1

 E10-3:/ # mount -t nfs -o loop /dev/sdb1 /webroot/1

 mount.nfs: remote share not in 'host:dir' format

 E10-3:/ # mkfs.ext3 -L /webroot/1 /dev/sdb1

 mke2fs 1.41.9 (22-Aug-2009)

 mkfs.ext3: inode_size (128) * inodes_count (0) too big for a

         filesystem with 0 blocks, specify higher inode_ratio (-i)

         or lower inode count (-N).

 

 E10-3:/ # mkfs -t ext3 -c /dev/sdb1

 mke2fs 1.41.9 (22-Aug-2009)

 mkfs.ext3: inode_size (128) * inodes_count (0) too big for a

         filesystem with 0 blocks, specify higher inode_ratio (-i)

         or lower inode count (-N).

以上红色部分表示挂载或者格式化/dev/sdb1没有成功,经百度搜索查找原因得知,这里挂载和格式化的是扩展分区,我们不能这么做,挂载或者格式化操作对象只能是逻辑分区或者主分区。所以这里需要在扩展分区上创建逻辑分区。

 

5.1创建逻辑分区

命令:E10-3:/ # fdisk /dev/sdb

实例:E10-3:/ # fdisk /dev/sdb

 The number of cylinders for this disk is set to 121454.

 There is nothing wrong with that, but this is larger than 1024,

 and could in certain setups cause problems with:

 1) software that runs at boot time (e.g., old versions of LILO)

 2) booting and partitioning software from other OSs

    (e.g., DOS FDISK, OS/2 FDISK)

 

 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): p

 

 Disk /dev/sdb: 999.0 GB, 998999326720 bytes

 255 heads, 63 sectors/track, 121454 cylinders

 Units = cylinders of 16065 * 512 = 8225280 bytes

 Disk identifier: 0xd3f0a6aa

 

    Device Boot      Start         End      Blocks   Id  System

 /dev/sdb1               1      121454   975579223+   5  Extended

 

 Command (m for help): n

Command action

    l   logical (5 or over)

    p   primary partition (1-4)

 l

 First cylinder (1-121454, default 1): 

 Using default value 1

 Last cylinder, +cylinders or +size{K,M,G} (1-121454, default 121454): 

 Using default value 121454

 

 Command (m for help): p

 

 Disk /dev/sdb: 999.0 GB, 998999326720 bytes

 255 heads, 63 sectors/track, 121454 cylinders

 Units = cylinders of 16065 * 512 = 8225280 bytes

 Disk identifier: 0xd3f0a6aa

 

    Device Boot      Start         End      Blocks   Id  System

 /dev/sdb1               1      121454   975579223+   5  Extended

 /dev/sdb5               1      121454   975579192   83  Linux

 

Command (m for help): w

 The partition table has been altered!

 

 

 Calling ioctl() to re-read partition table.

 Syncing disks.

E10-3:/ # fdisk -l

 

 Disk /dev/sda: 999.0 GB, 998999326720 bytes

 255 heads, 63 sectors/track, 121454 cylinders

 Units = cylinders of 16065 * 512 = 8225280 bytes

 Disk identifier: 0x00004cb7

 

    Device Boot      Start         End      Blocks   Id  System

 /dev/sda1   *           1          63      506016   83  Linux

 /dev/sda2              64        5284    41937682+  83  Linux

 /dev/sda3            5285        6328     8385930   82  Linux swap / Solaris

 /dev/sda4            6329      121454   924749595    f  W95 Ext'd (LBA)

 /dev/sda5            6329      121452   924733498+  83  Linux

 

 Disk /dev/sdb: 999.0 GB, 998999326720 bytes

 255 heads, 63 sectors/track, 121454 cylinders

 Units = cylinders of 16065 * 512 = 8225280 bytes

 Disk identifier: 0xd3f0a6aa

 

    Device Boot      Start         End      Blocks   Id  System

 /dev/sdb1               1      121454   975579223+   5  Extended

 /dev/sdb5               1      121454   975579192   83  Linux

 

 Disk /dev/sdc: 4994.0 GB, 4993981612032 bytes

 255 heads, 63 sectors/track, 607150 cylinders

 Units = cylinders of 16065 * 512 = 8225280 bytes

 Disk identifier: 0x00000000

 

 Disk /dev/sdc doesn't contain a valid partition table

5.2 格式化逻辑分区

命令:E10-3:/ # mkfs.ext3 -L /webroot/1 /dev/sdb5

说明:ext3是文件系统类型,需根据实际情况更改,/webroot/1是挂载点,/dev/sdb5是逻辑分区名称

 

实例:

E10-3:/ # mkfs.ext3 -L /webroot/1 /dev/sdb5

 mke2fs 1.41.9 (22-Aug-2009)

 Filesystem label=/webroot/1

 OS type: Linux

 Block size=4096 (log=2)

 Fragment size=4096 (log=2)

 60981248 inodes, 243894798 blocks

 12194739 blocks (5.00%) reserved for the super user

 First data block=0

 Maximum filesystem blocks=4294967296

 7444 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, 214990848

 

 Writing inode tables: done                            

 Creating journal (32768 blocks): done

 Writing superblocks and filesystem accounting information: done

 

 This filesystem will be automatically checked every 39 mounts or

 180 days, whichever comes first.  Use tune2fs -c or -i to override.

5.3临时挂载(逻辑)分区

命令:mount /dev/sdb5   /webroot/1

说明:因挂载信息没有写到/etc/fstab文件中,所以这里只是临时挂载,系统重启后此挂载会消失。

 

实例:

E10-3:/ # mount /dev/sdb5   /webroot/1 

 E10-3:/ # df -h

 Filesystem            Size  Used Avail Use% Mounted on

 /dev/sda2              40G  4.7G   33G  13% /

 devtmpfs               12G  152K   12G   1% /dev

 tmpfs                 3.9G  100K  3.9G   1% /dev/shm

 /dev/sda1             479M   72M  383M  16% /boot

 /dev/sda5             869G  201M  824G   1% /home

 /dev/sr0              2.9G  2.9G     0 100% /media/SLES-11-SP1-DVD-x86_64.0432..001

 /dev/sdb5             916G  200M  870G   1% /webroot/1

 

5.4取消挂载

命令:umount /dev/sdb5

说明:因为第一次挂载硬盘时不知如何挂载,所以采用了临时挂载。但因为临时挂载分区后,系统重启后挂载分区会消失,所以此处先取消挂载,再将挂载信息写到启动文件,这样系统重启时会自动挂载所有分区。

 

 

实例:

E10-3:/ # umount /dev/sdb5

 E10-3:/ # df -h

 Filesystem            Size  Used Avail Use% Mounted on

 /dev/sda2              40G  4.7G   33G  13% /

 devtmpfs               12G  152K   12G   1% /dev

 tmpfs                 3.9G  100K  3.9G   1% /dev/shm

 /dev/sda1             479M   72M  383M  16% /boot

 /dev/sda5             869G  201M  824G   1% /home

 /dev/sr0              2.9G  2.9G     0 100% /media/SLES-11-SP1-DVD-x86_64.0432..001

5.5 将挂载信息写到启动文件

说明:将挂载信息写到/etc/fstab文件,系统启动时会根据此文件的信息挂载分区

 E10-3:/ # df -h

 Filesystem            Size  Used Avail Use% Mounted on

 /dev/sda2              40G  4.7G   33G  13% /

 devtmpfs               12G  152K   12G   1% /dev

 tmpfs                 3.9G  100K  3.9G   1% /dev/shm

 /dev/sda1             479M   72M  383M  16% /boot

 /dev/sda5             869G  201M  824G   1% /home

 /dev/sr0              2.9G  2.9G     0 100% /media/SLES-11-SP1-DVD-x86_64.0432..001

 E10-3:/ # more /etc/fstab

 /dev/disk/by-id/scsi-3600605b0020ecc50181c076d1680b376-part3 swap               

   swap       defaults              0 0

 /dev/disk/by-id/scsi-3600605b0020ecc50181c076d1680b376-part2 /                  

   ext3       acl,user_xattr        1 1

 /dev/disk/by-id/scsi-3600605b0020ecc50181c076d1680b376-part1 /boot              

   ext3       acl,user_xattr        1 2

 /dev/disk/by-id/scsi-3600605b0020ecc50181c076d1680b376-part5 /home              

   ext3       acl,user_xattr        1 2

 proc                 /proc                proc       defaults              0 0

 sysfs                /sys                 sysfs      noauto                0 0

 debugfs              /sys/kernel/debug    debugfs    noauto                0 0

 usbfs                /proc/bus/usb        usbfs      noauto                0 0

 devpts               /dev/pts             devpts     mode=0620,gid=5       0 0

 

 LABEL=/webroot/1     /webroot/1     ext3     defaults 0 0

 E10-3:/ # mount -a

 mount: special device LABEL=/webroot/1 does not exist

 E10-3:/ # vi /etc/fstab

 /dev/disk/by-id/scsi-3600605b0020ecc50181c076d1680b376-part3 swap                 swap       defaults              0 0

 /dev/disk/by-id/scsi-3600605b0020ecc50181c076d1680b376-part2 /                    ext3       acl,user_xattr        1 1

 /dev/disk/by-id/scsi-3600605b0020ecc50181c076d1680b376-part1 /boot                ext3       acl,user_xattr        1 2

 /dev/disk/by-id/scsi-3600605b0020ecc50181c076d1680b376-part5 /home                ext3       acl,user_xattr        1 2

 proc                 /proc                proc       defaults              0 0

 sysfs                /sys                 sysfs      noauto                0 0

 debugfs              /sys/kernel/debug    debugfs    noauto                0 0

 usbfs                /proc/bus/usb        usbfs      noauto                0 0

 devpts               /dev/pts             devpts     mode=0620,gid=5       0 0

/dev/sdb5    /webroot/1     ext3     defaults 0 0


5.6立即挂载所有分区

命令:mount -a             

E10-3:/ # mount -a

5.7 查看挂载结果

命令:df -h

 E10-3:/ # df –h

 

Filesystem            Size  Used Avail Use% Mounted on

 /dev/sda2              40G  4.7G   33G  13% /

 devtmpfs               12G  152K   12G   1% /dev

 tmpfs                 3.9G  100K  3.9G   1% /dev/shm

 /dev/sda1             479M   72M  383M  16% /boot

 /dev/sda5             869G  201M  824G   1% /home

 /dev/sr0              2.9G  2.9G     0 100% /media/SLES-11-SP1-DVD-x86_64.0432..001

 /dev/sdb5             916G  200M  870G   1% /webroot/1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值