linux挂载新的磁盘分区

今天做了linux磁盘分区,在此做个笔记,以便以后查询

/sbin/fdisk -l 查看硬盘情况,注意需要root权限。
如下:

=================分区情况==============================
[root@localhost dinghuaneng]# /sbin/fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14          78      522112+  82  Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

我们看到sdb还没有有效的分区表。我们对sdb进行分区。
对sdb进行操作:
fdisk /dev/sdb
[root@localhost dinghuaneng]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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 1305.
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)

我们看到,n为创建一个新分区:
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
选择是创建主分区还是扩展分区。我们选择主分区,第一个主分区:
p
Partition number (1-4): 1 ------这里选择最小值即可
选择分区的起点,默认会选择下一个有效磁盘柱面,所以直接回车:
First cylinder (1-1305, default 1):
输入分区大小,默认为最大值,这里就根据个人需求了:
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): 512

Command (m for help):

至此,分区完成。
重复上述步骤即可对硬盘分区完毕了,注意一定要选择w保存退出。
Command (m for help): w
The partition table has been altered!

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

我们再次查看:
[root@localhost dinghuaneng]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14          78      522112+  82  Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         512     4112608+  83  Linux
/dev/sdb2             513        1305     6369772+  83  Linux


==========================  格式化  ==============================
分区完成后,还要进行格式化才能使用。linux下我们一般用mkfs ext3格式。
[root@localhost dinghuaneng]# ls /sbin/mkfs
mkfs         mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.msdos   mkfs.vfat
[root@localhost dinghuaneng]# mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
515072 inodes, 1028152 blocks
51407 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1056964608
32 block groups
32768 blocks per group, 32768 fragments per group
16096 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                           
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost dinghuaneng]# mkfs.ext3 /dev/sdb2
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
796544 inodes, 1592443 blocks
79622 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1631584256
49 block groups
32768 blocks per group, 32768 fragments per group
16256 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

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

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost dinghuaneng]#

==========================  自动挂载  ==============================
Linux系统对没有挂载的分区是无法访问的。我们必须将其挂载到某个目录下使用。
这里注意如果那个目录下有有用的文件,不要挂载到那里,因为挂载后,那个目录指向会改变为新分区,以前内容就无法访问了,除非umount。
挂载命令:mount [-t vfstype] [-o options] device dir
对于光盘或.iso文件较为特殊:mount -o loop linux.iso
对于硬盘分区:mount 设备 路径即可。
对于windows的fat或ntfs的格式,需要加-t选项。如:
mount -t vfat /dev/sdb1 /mnt/fat1
mount -t ntfs /dev/sdb2 /mnt/ntfs1

posted on 2014-03-17 15:29  zy-自由鱼  阅读(309)  评论(0)    收藏  举报