1.进入linux:
yun@yun-desktop:/work$sudo fdisk -l //查看系统硬盘配置
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: 0x0001efb8
Device Boot Start End Blocks Id System
/dev/sda1 linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 973 2611 13157377 5 Extended
/dev/sda5 973 1222 1998848 82 Linux swap / Solaris
/dev/sda6 1222 2611 11157504 83 Linux
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: 0x720e532d
Device Boot Start End Blocks Id System
可见/dev/sdb就是添加的硬盘
2.对硬盘/dev/sdb进行分区
1、划分为扩展分区
yun@yun-desktop:/work$sudo fdisk /dev/sdb 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 b edit bsd disklabel c toggle the dos compatibility flag d delete a partition注:这是删除一个分区的动作 l list known partition types 注:l是列出分区类型,以供我们设置相应分区的类型; m print this menu注:m是列出帮助信息; n add a new partition注:添加一个分区 o create a new empty DOS partition table p print the partition table注:p列出分区表; q quit without saving changes注:不保存退出; s create a new empty Sun disklabel t change a partition's system id 注:t改变分区类型; u change display/entry units v verify the partition table w write table to disk and exit注:把分区表写入硬盘并退出; x extra functionality (experts only)注:扩展应用,专家功能; 其实我们常用的只有注有中文的,其它的功能我们不常用;x扩展功能,也不是常用的;一般的情况下只要懂得 d l m p q t w 就行了 列出当前操作硬盘的分区情况,使用p: Command(m for help):p 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: 0x720e532d Device Boot Start End Blocks Id System 通过fdisk的d指令来删除一个分区 Command(m for help):d Partition number (1-6): 6 注:我想删除 sda6 ,就在这里输入 6 ; 警告:删除分区时要小心,请看好分区的序号,如果您删除了扩展分区,扩展分区之下的逻辑分区都会删除;所以操作时一定要小心;如果知道自己操作错了,请不要惊慌,用q不保存退出;切记切记!!!!在分区操作错了之时,千万不要输入w保存退出!!! Command (m for help): n Command action e extended //选择e,将硬盘sdb格式化为扩展分区 p primary partition (1-4) e Partition number (1-4): 1 First cylinder (1-2610, default 1): //敲回车,即为默认配置注:这个就是分区的Start 值;这里最好直接按回车,如果您输入了一个非默认的数字,会造成空间浪费; Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): //敲回车,即为默认配置 Using default value 2610 Command (m for help): w //保存配置 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. 到这里为止,只是将新硬盘格式化为扩展分区,但扩展分区还需要再格式化并添加逻辑分区才可用!!!! 所以还要再继续分区一次
2、划分为逻辑分区
yun@yun-desktop:/work$sudo fdisk /dev/sdb 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 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 l logical (5 or over) //格式化为逻辑分区 p primary partition (1-4) l First cylinder (1-2610, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): Using default value 2610 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. yun@yun-desktop:/work$sudo fdisk -l 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: 0x0001efb8 Device Boot Start End Blocks Id System /dev/sda1 * 1 973 7811072 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 973 2611 13157377 5 Extended /dev/sda5 973 1222 1998848 82 Linux swap / Solaris /dev/sda6 1222 2611 11157504 83 Linux 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: 0x720e532d Device Boot Start End Blocks Id System /dev/sdb1 1 2610 20964793+ 5 Extended /dev/sdb5 1 2610 20964762 83 Linux 3、格式化分区为ext3格式 yun@yun-desktop:/work$sudo mkfs.ext3 /dev/sdb5 mke2fs 1.41.11 (14-Mar-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1310720 inodes, 5241190 blocks 262059 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 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 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. yun@yun-desktop:/work$sudo mkdir /media/sdb //新建一个目录,用于挂载硬盘sdb5 yun@yun-desktop:/work$sudo mount /dev/sdb5 /media/sdb或者 //sdb5是可用的逻辑分区 yun@yun-desktop:/work$sudo mount -t ext3 -o rw /dev/sdb5 /media/sdb yun@yun-desktop:/work$df -lh Filesystem Size Used Avail Use% Mounted on /dev/sda1 7.4G 2.5G 4.6G 35% / none 245M 264K 245M 1% /dev none 249M 252K 249M 1% /dev/shm none 249M 96K 249M 1% /var/run none 249M 0 249M 0% /var/lock none 249M 0 249M 0% /lib/init/rw /dev/sda6 11G 465M 9.5G 5% /work /dev/sdb5 20G 173M 19G 1% /media/sdb yun@yun-desktop:/work$sudo fdisk -l 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: 0x0001efb8 Device Boot Start End Blocks Id System /dev/sda1 * 1 973 7811072 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 973 2611 13157377 5 Extended /dev/sda5 973 1222 1998848 82 Linux swap / Solaris /dev/sda6 1222 2611 11157504 83 Linux 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: 0x720e532d Device Boot Start End Blocks Id System /dev/sdb1 1 2610 20964793+ 5 Extended /dev/sdb5 1 2610 20964762 83 Linux //可用的逻辑分区sdb5
3.修改系统配置文件/etc/fstab
将/dev/sdb5盘挂载到了/media/sdb下面,在文件/etc/fstab最后一行添加
/dev/sdb5 /media/sdb ext3 defaults 0 0
此时,系统启动时会自动挂载该分区,否则,只要重启linux系统,都要手动挂载硬盘。