把home⽬录下的⽂件挂载到新设备上(⽬录迁移)1.备份/home/
[root@centos6 ~]# cp -ar /home/ /data/ ##-a保留全部属性,-r表⽰递归复制⽬录及其⼦⽬录内的所有内容
[root@centos6 ~]# ll /data/home/
总⽤量 8
drwx------. 28 cwj cwj 4096 10⽉ 5 2019 cwj
drwx------ 4 mage mage 4096 4⽉ 21 2019 mage
[root@centos6 ~]# ll /home
总⽤量 8
drwx------. 28 cwj cwj 4096 10⽉ 5 2019 cwj
drwx------ 4 mage mage 4096 4⽉ 21 2019 mage
[root@centos6 ~]#
2、利⽤新的磁盘划分出新的分区,并在分区上创建⽂件系统。
1、添加⼀块10G硬盘
2、识别硬盘
[root@centos6 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@centos6 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 48.8G 0 part /
├─sda3 8:3 0 29.3G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sr0 11:0 1 8.1G 0 rom /mnt/cdrom
sr1 11:1 1 3.7G 0 rom
sdb 8:16 0 10G 0 disk
3、创建分区
[root@centos6 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x2276d648.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G}(1-1305, default 1305): +2G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos6 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 48.8G 0 part /
├─sda3 8:3 0 29.3G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sr0 11:0 1 8.1G 0 rom /mnt/cdrom
sr1 11:1 1 3.7G 0 rom
sdb 8:16 0 10G 0 disk
cp复制文件到指定目录下└─sdb1 8:17 0 2G 0 part
3、在分区上创建⽂件系统4 /dev/sdb1 -L /home
[root@centos6 ~]# 4 /dev/sdb1 -L /home
mke2fs 1.41.12 (17-May-2010)
⽂件系统标签=/home
操作系统:Linux
块⼤⼩=4096 (log=2)
分块⼤⼩=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131648 inodes, 526120 blocks
26306 blocks (5.00%) reserved for the super user
第⼀个数据块=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7744 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
正在写⼊inode表: 完成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@centos6 ~]# blkid | grep /dev/sdb1
/dev/sdb1: LABEL="/home" UUID="fd06cd0f-0209-4621-827d-ecd42ecce1f9" TYPE="ext4"
4、创建挂载点,并把新分区挂载到新建的挂载点上。mkdir /mnt/home ;mount /dev/sdb1
/mnt/home(充当临时⽬录,⽤于把/home⽬录中的内容导⼊到新的磁盘上)
[root@centos6 ~]# mkdir /mnt/home
[root@centos6 ~]# mount /dev/sdb1 /mnt/home
[root@centos6 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/
dev/sda2 48G 3.8G 42G 9% /
tmpfs 932M 4.0K 932M 1% /dev/shm
/dev/sda1 976M 40M 886M 5% /boot
/dev/sda3 29G 71M 28G 1% /data
/dev/sr0 8.1G 8.1G 0 100% /mnt/cdrom
/dev/sdb1 2.0G 3.1M 1.9G 1% /mnt/home
5、进⼊单⽤户模式init 1(避免其他⽤户访问,造成数据不⼀致,该命令会导致断⽹)
[root@centos6 ~]# init 1
6、把原来/home⽬录⾥的所有内容复制到新分区中cp -av /home/* /mnt/home(注意:这不会复制隐藏⽂件及隐藏⽂件夹,但是⼀般home⽬录下不会有隐藏⽂件)
7、删除原先的家⽬录rm -rf /home/* ,后⾯将会作为挂在点使⽤。
8、把/mnt/home⽬录挂载⾄原先的/home⽬录上。
vim /etc/fstab
读⼊命令的输出
9、卸载临时挂载点,并删除/mnt/home上的数据。umount /mnt/home;rm -rf /mnt/home
10、切换回图形模式init 5。
验证:
切换到cwj⽤户,新建测试⽂件。
[root@centos6 ~]# su cwj
[cwj@centos6 root]$ cd
[cwj@centos6 ~]$ pwd
/home/cwj
[cwj@centos6 ~]$ mkdir testfile
[cwj@centos6 ~]$
[root@centos6 ~]# ll /home
总⽤量 24
drwx------. 29 cwj cwj 4096 4⽉ 18 17:30 cwj
drwx------ 2 root root 16384 4⽉ 18 16:09 lost+found drwx------ 4 mage mage 4096 4⽉ 21 2019 mage
注意:根分区⽆法迁移
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论