说明:
服务器磁盘快满了,需要添加新硬盘。由于之前并没有做过增加硬盘的操作,因此先在虚拟上测试下
此篇文章记录如何添加硬盘/dev/sde分区(添加两个分区/dev/sde1,/dev/sde2),格式化及加载硬盘
实现:
1.vmware中添加linux硬盘。虚拟机开机添加硬盘需要重启或关机添加硬盘,不然新加的硬盘无法识别出来。
2.在vmware中查看硬盘信息,第1个硬盘是/dev/sda(之前总共添加了4个硬盘), 第5个硬盘是/dev/sde
# 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 fd Linux raid autodetect
/dev/sda2 14 77 514080 fd Linux raid autodetect
/dev/sda3 78 1305 9863910 fd Linux raid autodetect
。。。。。。跳过另外三个盘的信息
Disk /dev/sde: 10.7 GB, 10737418240 bytes //10G的硬盘
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
3. 创建硬盘分区,添加两个分区/dev/sde1,/dev/sde2
# fdisk /dev/sde
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)
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-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +5120M //可以输入扇区号或分区大小(要添加+)
Command (m for help): n //按n添加新分区
Command action
e extended
p primary partition (1-4)
p //选p(主分区)
Partition number (1-4): 2 //创建第二个主分区
First cylinder (624-1305, default 624):
Using default value 624
Last cylinder or +size or +sizeM or +sizeK (624-1305, default 1305):
Using default value 1305
Command (m for help): w //写入分区信息
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
这时可以看到/dev/sde已经有分区信息了。为了能使用该硬盘,还需要对该硬盘进行格式化,挂载
# fdisk -l /dev/sde
Disk /dev/sde: 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/sde1 1 623 5004216 83 Linux
/dev/sde2 624 1305 5478165 83 Linux
4. 格式化硬盘
# mkfs -t ext3 /dev/sde1 //格式化sde1分区,可以使用df -T -h查看原有硬盘采用什么文件系统ext2,ext3等
# mkfs -t ext3 /dev/sde2 //格式化sde2分区
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
685440 inodes, 1369541 blocks
68477 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1405091840
42 block groups
32768 blocks per group, 32768 fragments per group
16320 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 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
5. 创建用于mount的目录
# mkdir -p /opt/a
# mkdir -p /opt/b
6. mount到指定的目录
# mount /dev/sde1 /opt/a -o rw //-o options 描述设备或档案的挂接方式,rw:采用读写方式挂接设备
# mount /dev/sde1 /opt/b -o rw
7. 如果需要每次启动加载,修改/etc/fstab文件
# vim /etc/fstab //在fstab文件最后里面添加以下内容
/dev/sde1 /opt/a ext3 defaults 0 3
/dev/sde2 /opt/b ext3 defaults 0 3挂载点 分区的类型 挂载选项 dump选项 fsck选项
dump选项,设置是否让备份程序dump备份文件系统,0为忽略,1为备份,如果上次用dump备份,将显示备份至今的天数
fsck选项,这里用来指定如何使用fsck来检查硬盘。如果这里填0,则不检查;挂载点为 / 的(即根分区),必须在这里填写1,其他的都不能填写1。如果有分区填写大于1的话,则在检查完根分区后,接着按填写的数字从小到大依次检查下去。同数字 的同时检查。比如第一和第二个分区填写2,第三和第四个分区填写3,则系统在检查完根分区后,接着同时检查第一和第二个分区,然后再同时检查第三和第四个 分区
转载于:https://blog.51cto.com/atong/1294728