分类: LINUX
2009-11-01 22:38:48
Liunx下如何加载一块新硬盘
我们在使用linux的情况下,难免有时会需要增加一块硬盘,在windows下增加硬盘很简单,所有的操作都是有画面。linux下增加一块硬盘,并且让这块硬盘可以正常的使用,所有的操作都在字符命令行的方式下,因此对于初学者的我来说,接受起来比较困难,因此把这一部分整理为一个专题和大家共享。
在linux下加载一块硬盘从总体上分为以下几个步骤:
1、用fdisk对硬盘进行分区
2、用mkfs.ext3对硬盘进行格式化
3、建立一个挂接目录(如果需要挂接到已存在的目录,此步骤可以省略)
4、用mount将该分区挂接到指定的目录
5、如果想实现启动时自动挂接,那么还需要修改fstab文件
具体操作如下:
[root@redhad ~]# fdisk -l --查看硬盘分区信息
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 3661 29406951 83 Linux
/dev/sda2 3662 3915 2040255 82 Linux swap
Disk /dev/sdb: 1073 MB, 1073741824 bytes --可以看到有一块空闲的硬盘还未分区
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
[root@redhad ~]# fdisk /dev/sdb --使用fdisk工具对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.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): m --列出fdisk工具的参数
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 --输入“n”增加一个分区
Command action --选择是建立主分区还是扩展分区
e extended
p primary partition (1-4)
p --输入“p”建立主分区
Partition number (1-4): 1 --输入分区号
First cylinder (1-130, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): 130
Command (m for help): w --写入分区表并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@redhad ~]# mkfs.ext3 /dev/sdb1 --将新建立的分区进行格式化
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261048 blocks
13052 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@redhad ~]# mkdir /newdisk --建立一个新的挂接目录
[root@redhad ~]# mount /dev/sdb1 /newdisk --将sdb1挂接到/newdisk下
[root@redhad ~]# df -lh --查看目前硬盘空闲,新建硬盘已经成功挂接
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 28G 2.4G 24G 9% /
none 506M 0 506M 0% /dev/shm
/dev/sdb1 1004M 18M 936M 2% /newdisk
到此为止,我们的新硬盘已经加载成功了,但是这里有一个问题,一旦我们重新启动系统,还需要用mount命令重新挂接才能访问新硬盘,如果我需要挂接的工作在系统启动过程中完成,那么我需要用vi配置/etc/fstab文件,将/dev/sdb1 /newdisk ext3 defaults 1 1 添加到/etc/fstab的最后,然后重新启动系统即可。