很多企业在网站发布前,在linux测试机上测试服务,很多程序员用户目录也在linux测试机上测试程序。然而,随着项目的进行,出现了测试机卡死的状况。用df -h命令查看,结果吓一跳,根目录上资源占用竟然达到了100%,不卡死才怪呢,,,而其他磁盘挂载的目录空间几乎没有用!!!
怎么解决呢,首先通知所有用户,让他们删除自己工作目录中的那些没用的文件,效果还是有的,不一会就腾出了差不多6个G的空间。。。可惜好景不长,没过几天,再次卡死,这次还是来个彻底点的解决办法吧,迁移!!!方案如下:
/home分区迁移方案一
1)新建一个新分区 /dev/sdb1
2)将/dev/sdb1挂载到/data/sdb1
3)迁移用户(提醒该用户暂时不要登录)
mkdir /data/sdb1/home
cp -rp /home/kaka /data/sdb1/home/
4)vim /etc/passwd --> /home/kaka --> /data/sdb1/home/kaka
5)ls -ld/data/sdb1/home/kaka
6) su - kaka
####################################################
/home分区迁移方案二
1)新建一个新分区 /dev/sdb1
2)迁移用户(提醒该用户暂时不要登录)
mkdir /opt/home
cp -rp /home/* /opt/home
3)将/dev/sdb1挂载到/home
4)将数据拷贝回去
cp -rp /opt/home/* /home/
5)验证权限
ls -ld /home
ls -ld /home/kaka
6) su - kaka
下边给出实验性的命令,然后放入实际环境中执行
[root@localhost ~]# fdisk -l sdc
[root@localhost ~]# fdisk /dev/sdc
Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes willremain 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 isset to 10443.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partitiontable 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
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): t
Selected partition 1
Hex code (type L to list codes): 83
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkfs.ext3 /dev/sdc1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2443200 inodes, 4885760 blocks
244288 blocks (5.00%) reserved for thesuper user
First data block=0
Maximum filesystem blocks=4294967296
150 block groups
32768 blocks per group, 32768 fragments pergroup
16288 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]#
[root@localhost ~]# mkdir /datac1
[root@localhost ~]# mount /dev/sdc1 /datac1
[root@localhost ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts(rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint typevmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)
/dev/sdc1 on /datac1 type ext3 (rw)
[root@localhost ~]# useradd user01
[root@localhost ~]# useradd user02
[root@localhost ~]# cp -rp /home/ /datac1
[root@localhost ~]# vim /etc/passwd
[root@localhost ~]# su - user01
su: warning: cannot change directory to/datac1/user01: 没有那个文件或目录
-bash-3.2$ exit
logout
[root@localhost ~]# cd /datac1/
[root@localhost datac1]# ll
总计 20
drwxr-xr-x 4 root root 4096 08-02 19:23 home
drwx------ 2 root root 16384 08-02 19:20lost+found
[root@localhost datac1]# vim /etc/passwd
[root@localhost datac1]# ls -ld/datac1/home/user01
drwx------ 3 user01 user01 4096 08-02 19:23/datac1/home/user01
[root@localhost datac1]# su - user01
[user01@localhost ~]$ pwd
/datac1/home/user01
[user01@localhost ~]$ exit
logout
[root@localhost datac1]# umount /dev/sdc1
umount: /datac1: device is busy
umount: /datac1: device is busy
[root@localhost datac1]# cd ..
[root@localhost /]# cd
[root@localhost ~]# umount /dev/sdc1
[root@localhost ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts(rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint typevmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)
[root@localhost ~]# cp -rp /home/ /opt/
[root@localhost ~]# ls -ld /opt/home/
drwxr-xr-x 4 root root 4096 08-02 19:23/opt/home/
[root@localhost ~]# ls -ld /opt/home/user01
drwx------ 3 user01 user01 4096 08-02 19:23/opt/home/user01
[root@localhost ~]# mount /dev/sdc1 /home/
[root@localhost ~]# vim /etc/passwd
[root@localhost ~]#\cp -rfp /opt/home/ /
[root@localhost ~]# ls -ld /home/user01
drwx------ 3 user01 user01 4096 08-02 19:23/home/user01
[root@localhost ~]# su - user01
[user01@localhost ~]$ pwd
/home/user01
原文地址:http://8879567.blog.51cto.com/8869567/1535106