Linux磁盘挂载操作手册一、挂载单个分区小于2T的分区1.查看系统当前分区情况命令df –h实例:Last login: Fri Oct 26 00:01:51 2012 from e10-3E10-3:~ # df -hFilesystem Size Used Avail Use% Mounted on/dev/sda2 40G 4.7G 33G 13% /devtmpfs 12G 144K 12G 1% /devtmpfs 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 –lE10-3:~ # fdisk -lDisk /dev/sda: 999.0 GB, 998999326720 bytes255 heads, 63 sectors/track, 121454 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x00004cb7Device 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 LinuxDisk /dev/sdb: 999.0 GB, 998999326720 bytes255 heads, 63 sectors/track, 121454 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x00000000Disk /dev/sdb doesn't contain a valid partition tableDisk /dev/sdc: 4994.0 GB, 4993981612032 bytes255 heads, 63 sectors/track, 607150 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x00000000Disk /dev/sdc doesn't contain a valid partition table3.创建新的硬盘分区命令:fdisk /dev/sdb注:这里的/dev/sdb是具体一个硬盘,此参数可改成fdisk –l显示的硬盘的序号。
实例:E10-3:~ # fdisk /dev/sdbDevice 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): mCommand actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitionl list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)Command (m for help): nCommand actione extendedp primary partition (1-4)ePartition number (1-4): 1First cylinder (1-121454, default 1): 1Last cylinder, +cylinders or +size{K,M,G} (1-121454, default 121454):Using default value 121454Command (m for help): pDisk /dev/sdb: 999.0 GB, 998999326720 bytes255 heads, 63 sectors/track, 121454 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0xd3f0a6aaDevice Boot Start End Blocks Id System/dev/sdb1 1 121454 975579223+ 5 ExtendedCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.E10-3:~ # fdisk -lDisk /dev/sda: 999.0 GB, 998999326720 bytes255 heads, 63 sectors/track, 121454 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x00004cb7Device 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 LinuxDisk /dev/sdb: 999.0 GB, 998999326720 bytes255 heads, 63 sectors/track, 121454 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0xd3f0a6aaDevice Boot Start End Blocks Id System/dev/sdb1 1 121454 975579223+ 5 ExtendedDisk /dev/sdc: 4994.0 GB, 4993981612032 bytes255 heads, 63 sectors/track, 607150 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x00000000Disk /dev/sdc doesn't contain a valid partition table4.创建挂载点即创建目录,以便将新建的分区挂载到新目录下命令:mkdir -p /webroot/1实例:E10-3:~ # mkdir -p /webroot/15.挂载分区命令:mount /dev/sdb1 /webroot/1说明:其中/dev/sdb5是硬盘,/webroot/1是挂载点,即挂载到的目录实例:E10-3:/etc # mount /dev/sdb1 /webroot/1mount: you must specify the filesystem typeE10-3:/etc # mount -t ext3 /dev/sdb1 /webroot/1mount: wrong fs type, bad option, bad superblock on /dev/sdb1,missing codepage or helper program, or other errorIn some cases useful info is found in syslog - trydmesg | tail or soE10-3:/etc # mkfs.ext3 -L /webroot/1 /dev/sdb1mke2fs 1.41.9 (22-Aug-2009)mkfs.ext3: inode_size (128) * inodes_count (0) too big for afilesystem with 0 blocks, specify higher inode_ratio (-i)or lower inode count (-N).E10-3:/ # mkdir -p /webroot/1E10-3:/ # mount -t nfs -o loop /dev/sdb1 /webroot/1mount.nfs: remote share not in 'host:dir' formatE10-3:/ # mkfs.ext3 -L /webroot/1 /dev/sdb1mke2fs 1.41.9 (22-Aug-2009)mkfs.ext3: inode_size (128) * inodes_count (0) too big for afilesystem with 0 blocks, specify higher inode_ratio (-i)or lower inode count (-N).E10-3:/ # mkfs -t ext3 -c /dev/sdb1mke2fs 1.41.9 (22-Aug-2009)mkfs.ext3: inode_size (128) * inodes_count (0) too big for afilesystem with 0 blocks, specify higher inode_ratio (-i)or lower inode count (-N).以上红色部分表示挂载或者格式化/dev/sdb1没有成功,经百度搜索查找原因得知,这里挂载和格式化的是扩展分区,我们不能这么做,挂载或者格式化操作对象只能是逻辑分区或者主分区。