一、查看硬盘状态命令, fdisk -l
显示如下信息:
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006b898
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 209713151 104605697 5 Extended
/dev/sda5 501760 209713151 104605696 8e Linux LVM
#上面表明这块硬盘名字叫 /dev/sda,目前已经在用了,分区已经分好了。
Disk /dev/sdc: 1073.7 GB, 1073741824000 bytes
255 heads, 63 sectors/track, 130541 cylinders, total 2097152000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdc doesn't contain a valid partition table
#上面表明这块硬盘名字叫 /dev/sdc,目前还不能使用,文件系统没有建好。
Disk /dev/mapper/i--2--15703--VM-swap_1: 1606 MB, 1606418432 bytes
255 heads, 63 sectors/track, 195 cylinders, total 3137536 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/i--2--15703--VM-swap_1 doesn't contain a valid partition table
#上面表明这块硬盘名字叫 /dev/mapper/i--2--15703--VM-swap_1,这是交换的分区信息,暂时不用管。
二、在不能使用的硬盘上面新建文件系统。
step1: fdisk /dev/sdc #查看这块硬盘的信息
这时会进入对话窗口
Disk /dev/sdc: 1073.7 GB, 1073741824000 bytes
255 heads, 63 sectors/track, 130541 cylinders, total 2097152000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xaf9232a2
Device Boot Start End Blocks Id System
step2: 新建分区 命令 n
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #新建主分区
Partition number (1-4, default 1): 1 #1号主分区
First sector (2048-2097151999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151999, default 2097151999):
Using default value 2097151999 #将所有空间都交给主分区
最后 w 命令保存退出。
step3: 格式化分区为文件系统
mkfs.ext3 /dev/sdc1
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536000 inodes, 262143744 blocks
13107187 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
8000 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
step4: 挂载新的分区
在你想要挂载的位置之外,执行命令,比如我想挂载在 mnt/mydisk2目录下面
这时候你必须在这个目录之外执行
Mount dev/sdc1 mnt/mydisk2
step5: 查看挂载空间大小
root@i-2-15703-VM:/# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/i--2--15703--VM-root 99G 72G 23G 77% /
udev 3.9G 4.0K 3.9G 1% /dev
tmpfs 1.6G 276K 1.6G 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 3.9G 0 3.9G 0% /run/shm
/dev/sda1 228M 25M 192M 12% /boot
/dev/sdc1 985G 200M 935G 1% /mnt/mydisk2
ps:配置开机自动挂载
因为mount挂载在重启服务器后会失效,所以需要将分区信息写到/etc/fstab文件中让它永久挂载:
e2label /dev/hda6 先查看需要挂载硬盘分区的lable
/home
e2label /dev/hda6 home1 因为系统中已经有个/home的label了,所以这里要重新把/dev/hda6的label设置为home1
vi /etc/fstab
加入:
LABEL=home1 /data1 ext3 defaults 1 2
注意红色home1左边没有/。
查看cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/data /data ext3 defaults 1 2
LABEL=home1 /data1 ext3 defaults 1 2
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-hda3 swap swap defaults 0 0
在修改/etc/fstab文件后,运行mount -a命令验证一下配置是否正确,否则错误配置fstab文件导致系统无法正常启动。如果系统无法正常启动,则输入root密码进入修复模式,关键的一步是重新mount /(mount -n -o remount,rw /)。如果没有此步操作,则文件系统处于只读状态,导致不能修改配置文件并保存,修复存在的问题。