我要增加一个10G的SCSI的磁盘。
磁盘->(fdisk建立分区表)->分区->(mkfs建立文件系统)->文件系统->(mount将文件系统挂载到相应目录下)->目录->(最后需要编辑/etc/fstab文件,让系统在启动时就加载这些文件系统)
1,一般使用“fdisk -l”命令可以列出系统中当前连接的硬盘,设备和分区信息.新硬盘没有分区信息,则只显示硬盘大小信息. 如下黄色背景就是我新添加的硬盘。
[root@localhost ~]# fdisk -l
Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 38 305203+ 83 Linux
/dev/sda2 39 10186 81513810 83 Linux
/dev/sda3 10187 10443 2064352+ 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
2,使用fdisk命令对sdb进行分区.
[root@localhost ~]# 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)
Command (m for help): n --表示新建分区
Command action
e extended
p primary partition (1-4)
p p 表示建立一个原始分区
Partition number (1-4): 1 --1 表示此分区编号为1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305
Command (m for help): p --打印分区信息
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 1305 10482381 83 Linux
Command (m for help): w ---w 保存存盘,退出fdisk.
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3,再使用fdisk -l命令查看分区情况.
[root@localhost ~]# fdisk -l
Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 38 305203+ 83 Linux
/dev/sda2 39 10186 81513810 83 Linux
/dev/sda3 10187 10443 2064352+ 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 1305 10482381 83 Linux
[root@localhost ~]# 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)
1310720 inodes, 2620595 blocks
131029 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/sdb1 /data
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 76G 13G 59G 18% /
/dev/sda1 289M 17M 258M 6% /boot
tmpfs 981M 0 981M 0% /dev/shm
/dev/sdb1 9.9G 151M 9.2G 2% /data
sdb1已挂载到/data上,剩余空间为9.2G
7,.设置新硬盘开机自动挂载
[root@localhost ~]# vi /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
/dev/sdb1 /data ext3 defaults 1 1
--格式说明
/dev/sdb1 /u01 ext3 defaults 1 1
要挂载的对象 挂载的目录 系统类型 文件系统访问权限 开机后是否检测 出问题后是否转储
8,重新启动服务器,再次df -h查看
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 76G 13G 59G 18% /
/dev/sda1 289M 17M 258M 6% /boot
tmpfs 981M 0 981M 0% /dev/shm
/dev/sdb1 9.9G 151M 9.2G 2% /data
可以看出/dev/sdb1顺利的自动挂载了。