迁移home分区
主机在安装时/home没有独立分区,随着用户不断增多,经常因根分区磁盘空间耗尽而故障频发,为解决问题,需添加一块硬盘,将用户目录“/home”中的数据迁移到该硬盘中。
首先添加一块硬盘,并划分分区
用fdisk -l命令查看硬盘是否被识别
[root@localhost ~]# fdisk -l
对磁盘进行分区
[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 10443.
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): n m获取帮助,n新建分区
Command action
e extended e扩展分区
p primary partition (1-4) p主分区
p
Partition number (1-4): 1 选择分区号
First cylinder (1-10443, default 1):选择起始柱面,使用默认就可以
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-10443, default 10443): +20G 选择分区大小
Command (m for help): w 保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
重新识别磁盘分区表
[root@localhost ~]# partprobe /dev/sdb
对分区进行格式化
[root@localhost ~]# mkfs.ext3 /dev/sdb1
将/home中资料进行备份
[root@localhost ~]# cp -r /home/* /usr/cphome/
可将/home内文件清空,释放根目录空间
[root@localhost ~]# rm -rf /home/*
注:必须确认资料已备份,以免误删,此命令是强制删除,慎用
如有用户登录,提醒其退出,在迁移完成前用户无法登录
将分区挂载到/home下
[root@localhost ~]# mount /dev/sdb1 /home/
验证
[root@localhost ~]# mount | tail -1
/dev/sdb1 on /home type ext3 (rw)
对/etc/fstab文件进行更改,实现开机自动挂
[root@localhost ~]# vim /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 /home ext3 defaults 0 0
将备份文件拷贝回到/home
[root@localhost ~]# cp -r /usr/cphome/* /home/
[root@localhost ~]# ls /home/
原文:http://857398758.blog.51cto.com/8504117/1367812