遷移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/

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章