----- 环境:centos6.2 kvm虚拟机
----- 情况:磁盘上有一分区/dev/sda5太大,希望分解成多个分区,此分区挂载在/www目录下
----- 开始操作:
#---- 卸下分区
cd /home/
umount /dev/sda5
# 如果 umount 出现 device is busy:fuser -m /dev/sda5,查看读写磁盘的pid,找出来kill之
kill方法:
执行umount 命令的时候出现 device is busy ,有人在使用这块磁盘
umount /dev/sde1
umount: /u01/app/oracle: device is busy
umount: /u01/app/oracle: device is busy
使用fuser 命令查看哪个进程在使用
[root@localhost ~]# fuser -m /u01/app/oracle/
/u01/app/oracle/: 2636c 2694c
[root@localhost ~]# ps aux | grep 2636
root 2636 0.0 0.2 4532 1464 pts/1 S 09:56 0:00 bash
root 2776 0.0 0.1 3916 696 pts/1 R+ 10:18 0:00 grep 2636
kill -9 干掉进程
[root@localhost ~]# kill -9 2636
[root@localhost ~]# umount /dev/sde1
#---- 目标:使用 fdisk /dev/sda 删除/dev/sda5,新建 15G的sda5 和 10G的sda6/7/8。以下为大致记录,删掉了一些废话
[root@FDFS-2 home]# fdisk /dev/sda
... 磁盘信息,忽略
Command (m for help): p # 查看当前分区表。更多信息:m for help
Disk /dev/sda: 62.9 GB, 62914560000 bytes...
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 1319 10485760 83 Linux
/dev/sda3 1319 1449 1048576 82 Linux swap / Solaris
/dev/sda4 1449 7649 49802240 5 Extended
/dev/sda5 1449 7649 49801216 83 Linux
Command (m for help): d # 删除动作
Partition number (1-5): 5 # 选择分区号/dev/sda5就是5
Command (m for help): n # 新建分区
First cylinder (1449-7649, default 1449): # 从默认磁盘扇区开始即可
Using default value 1449
Last cylinder, +cylinders or +size{K,M,G} (1449-7649, default 7649): +15G # 懒得计算扇区,可以照提示使用“+容量”的办法
... 多次新建动作,忽略
Command (m for help): p # 再次查看分区表
...
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 1319 10485760 83 Linux
/dev/sda3 1319 1449 1048576 82 Linux swap / Solaris
/dev/sda4 1449 7649 49802240 5 Extended
/dev/sda5 1449 3407 15728936 83 Linux
/dev/sda6 3408 4713 10490413+ 83 Linux
/dev/sda7 4714 6019 10490413+ 83 Linux
/dev/sda8 6020 7325 10490413+ 83 Linux
Command (m for help): w # 写入到磁盘中,谨慎操作!
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
# 看到上面的error提示不要慌张,回到shell后运行fdisk可以查看到重新分区已经顺利进行。
[root@FDFS-2 home]# fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 1319 10485760 83 Linux
/dev/sda3 1319 1449 1048576 82 Linux swap / Solaris
/dev/sda4 1449 7649 49802240 5 Extended
/dev/sda5 1449 3407 15728936 83 Linux
/dev/sda6 3408 4713 10490413+ 83 Linux
/dev/sda7 4714 6019 10490413+ 83 Linux
/dev/sda8 6020 7325 10490413+ 83 Linux
#---- 这时已经回到shell并且通过上面的命令已经查看到最新的分区的了,但是分区已经直接可用?
shell> mkfs -t ext4 /dev/sda6
提示错误:
Could not stat /dev/sda6 --- No such file or directory
The device apparently does not exist; did you specify it correctly?
错误原因为新的分区表不被系统识别,一种说法为可以通过partprobe命令解决,但是
shell> partprobe
后提示:
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
看来还是无法读取,需要reboot
#---- 重点来了,请重启前先确认你原来使用的分区不在/etc/fstab中!
我原来的/etc/fstab中有这么一行:
UUID=000120ad-6480-40ba-9a64-3d5c27d1ff96 /www ext4 defaults 1 2
但/www目录对应的设备/dev/sda5已经被删除了,如果/etc/fstab中还存在着旧信息,开机会提示您:
fsck.ext4: unable to resolve 'uuid=000120ad--6480-40ba-9a64-3d5c27d1ff96'......然后无法进入系统啥的
但根据提示输入root帐号,我们可以进入到"repair filesystem"界面。这时已经发现了问题,准备编辑/etc/fstab系统已经read only filesystem了,重mount之
mount -o remount rw /
vi /etc/fstab # 删除掉上面的无用记录:“UID=000120ad-6480-40ba-9a64-3d5c27d1ff96 /www ext4 defaults 1 2”
reboot
#---- 下一台同类机器,可以这么做
更新完分区表后
sed -i '/\/www/'d /etc/fstab # 删除掉fstab中原来的配置信息
reboot
# 重启后,格式化新分区,mount上就可以用了
for((i=5;i<=8;i++));do mkfs -t ext4 /dev/sda$i;done
mkdir /fdfs_tracker
for((i=1;i<=3;i++));do mkdir /fdfs_storage_${i};done
mount -t ext4 /dev/sda5 /fdfs_tracker
mount -t ext4 /dev/sda6 /fdfs_storage_1
mount -t ext4 /dev/sda7 /fdfs_storage_2
mount -t ext4 /dev/sda8 /fdfs_storage_3
#---- 新分区信息没有写入在/etc/fstab中,如何开机自动加载
1. 有看见过将mount命令写在/etc/rc.local中的。但目录如果被应用所引用,最好确保在应用启动前mount上
2. 写入信息到/etc/fstab中
文件格式:<file system> <mount point> <type> <options> <dump> <pass>
<file system> = device # 要挂载的设备名称
<mount point> = directory # 要挂载到的目录名称
<type> = fs type # 文件类型:ext*等,是什么类型就挂什么类型
<options> = 设置选项 # 挂载参数,default即可,更多知识在man mount
<dump> = 内容备份?0为不备份1为备份。
<pass> = 开机检查文件系统(使用fsck):0=不检查;1=优先检查;2/3/4次之检查;都为2的会同时第二批检查
插入以下内容到/etc/fstab
/dev/sda5 /fdfs_tracker ext4 defaults 1 2
/dev/sda6 /fdfs_storage_1 ext4 defaults 1 2
/dev/sda7 /fdfs_storage_2 ext4 defaults 1 2
/dev/sda8 /fdfs_storage_3 ext4 defaults 1 2
参考文档:http://blog.csdn.net/robinson1988/article/details/5283944
http://www.it165.net/os/html/201309/6262.html