实验案例一:迁移/home分区
公司原来安装的RHEL6服务器采用了自动分区的方案,随着使用服务器的系统用户数量不断增多,根据分区经常面临磁盘空间耗尽的情况,偶尔有几次还导致系统无法启动。为了解决这些问题,现需要为服务器新增加一块SCSI硬盘,并将用户目录“/home”中的数据迁移到该硬盘中,要求迁移不能影响原有用户账号的使用。
在虚拟机中添加一块80G的SCSI磁盘。
在新硬盘中建立一个20G的分区,用于存放所有普通用户的宿主文件夹
新建的分区仍然挂载到“/home”目录下,需要导入系统中原有用户的数据
服务器在每次开机后能够自动挂载该分区
1. 关机后添加新硬盘,重新开机进入RHEL6系统 2. 分区并格式化 1. 使用fdisk命令对新硬盘进行分区,建立一个20GB的主分区(“/dev/sdb1”) 2. 执行“partprobe”更新分区表信息,使用mkfs命令将上一步新建的分区格式化为ext4文件系统 3. 迁移“/home”分区 1. 转移原有“/home"目录中的内容并做好备份 2. 修改“/etc/fstab”文件中的分区挂载设置。 3. 按“/etc/fstab”文件中的设置将新建的分区挂载到“/home”目录下。 4. 将本步骤1中备份的数据复制到新挂载的“/home”文件系统。
实施过程
实验案例:迁移/home分区
公司原来安装的RHEL6服务器采用了自动分区的方案,随着使用服务器的系统用户数量不断增多,根据分区经常面临磁盘空间耗尽的情况,偶尔有几次还导致系统无法启动。为了解决这些问题,现需要为服务器新增加一块SCSI硬盘,并将用户目录“/home”中的数据迁移到该硬盘中,要求迁移不能影响原有用户账号的使用。
在虚拟机中添加一块80G的SCSI磁盘。
选择添加硬盘
选择硬盘类型
选择硬盘
选择硬盘容量
指定存储路径
添加硬盘完成
在初始界面可以看到新增加的硬盘
[root@test2 jason]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000d0a36 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/sdb: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xa8f24694 Device Boot Start End Blocks Id System /dev/sdb1 1 2612 20980858+ 83 Linux /dev/sdb2 2613 5224 20980890 83 Linux /dev/sdb3 5225 10443 41921617+ 83 Linux Disk /dev/sdc: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_jason-lv_root: 18.8 GB, 18798870528 bytes 255 heads, 63 sectors/track, 2285 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_jason-lv_swap: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@test2 jason]#
在新硬盘中建立一个20G的分区,用于存放所有普通用户的宿主文件夹
[root@test2 jason]# Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x764db371. 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): **Disk /dev/sdc: 85.9 GB, 85899345920 bytes** 255 heads, 63 sectors/track, 10443 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x764db371 Device Boot Start End Blocks Id System
[root@test2 jason]# fdisk /dev/sdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x8967e34e. 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): 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, +cylinders or +size{K,M,G} (1-10443, default 10443): +20G Command (m for help): Disk /dev/sdc: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x8967e34e Device Boot Start End Blocks Id System /dev/sdc1 1 2612 20980858+ 83 Linux Command (m for help): The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
[root@test2 jason]# mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1313760 inodes, 5245214 blocks 262260 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 161 block groups 32768 blocks per group, 32768 fragments per group 8160 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 filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@test2 jason]#
[root@test2 jason]# sdc sdc1 [root@test2 jason]# partprobe /dev/sdc
[root@test2 jason]# fdisk -l /dev/sdc1 Disk /dev/sdc1: 21.5 GB, 21484399104 bytes 255 heads, 63 sectors/track, 2611 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@test2 jason]#
新建的分区仍然挂载到“/home”目录下,需要导入系统中原有用户的数据
[root@test2 ~]# tar czvf home.bak.tar.gzip /home/*
[root@test2 ~]# ls anaconda-ks.cfg Downloads install.log man.txt Pictures Videos Desktop etc.tar.gz install.log.syslog Music Public Documents home.bak.tar.gzip man2.txt mvtotrash Templates [root@test2 ~]#
服务器在每次开机后能够自动挂载该分区
[root@test2 Documents]# vi /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 18 04:04:40 2016 # # Accessible filesystems, by reference, are maintained under ‘/dev/disk‘ # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/vg_jason-lv_root / ext4 defaults 1 1 UUID=12a13375-c595-4876-9fc2-3158f535861d /boot ext4 defaults 1 2 /dev/mapper/vg_jason-lv_swap swap swap defaults 0 0 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 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
[root@test2 Documents]# mount /home
[root@test2 Documents]# mount /dev/mapper/vg_jason-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other) gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev) /dev/sr0 on /media/CentOS_6.5_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500) [root@test2 Documents]#
[root@test2 Documents]# cd /home [root@test2 home]# ls lost+found [root@test2 home]#
[root@test2 ~]# tar xzvf home.bak.tar.gzip -C /home
[root@test2 ~]# cd /home [root@test2 home]# ls home lost+found [root@test2 home]#
[root@test2 Documents]# cd /home [root@test2 home]# ls home [root@test2 home]# rm -rf home [root@test2 home]# ls
[root@test2 ~]# tar xzvf home.bak.tar.gzip -c /
[root@test2 ~]# cd /home [root@test2 home]# ls backup jason
原文地址:http://11724065.blog.51cto.com/11714065/1790169