CentOS system disk migration

environment

  • Linux physical machine with VirtualBox virtual machine software installed
  • CentOS6.9 live boot U disk
  • CentOS6.9 iso image file
  • Notebook IBM x32 to be installed

VirtualBox creates a Redhat6 virtual machine

VMware has never used it. It is recommended that the hardware configuration be consistent with the target device as much as possible. For example, my X32 processor has only one core, no PAE, 1024MB of memory, and 8G of virtual hard disk. After installing the virtual machine with CentOS6.9 iso, disable it. selinux, may need to be restarted to take effect.

Package OS root directory

cd /
tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /

export/backup.tgz file

Return to the operating system of the physical machine, and copy /backup.tgz of the virtual machine to /root in the physical machine through ssh, http or other methods

format the disk

Take out the hard disk of the notebook to be installed, mount it on the physical machine via USB or other methods, partition it with fdisk, and format it

# fdisk 分成俩个分区,前面一个大的根分区,后面一个2G的 swap 分区,其他情况自己决定
# 假设刚挂载的这个目标磁盘设备是 sdg
mkfs.ext3 /dev/sdg1
mkswap /dev/sdg2

Deploy the operating system

Mount the root partition of the disk to be deployed, decompress the operating system files, and modify startup parameters

mount /dev/sdg1 /mnt
tar xvpzf /root/backup.tgz -C /mnt/
mkdir /mnt/proc
mkdir /mnt/sys
mkdir /mnt/mnt
# 查看目标磁盘根分区的 uuid,替换 /mnt/boot/grub/grub.conf 和 /mnt/etc/fstab 中对应项
ls -lh /dev/disk/by-uuid/|grep sdg1
# 查看目标磁盘 swap 分区的uuid,替换 /mnt/etc/fstab 中对应项
ls -lh /dev/disk/by-uuid/|grep sdg2
# 检查 /mnt/etc/mtab 中列出的信息是否正确

install grub2

Cancel the mount, install the deployed disk back into the notebook to be installed, insert the startup U disk of CentOS6.9, boot the notebook to be installed from the U disk, and enter live mode (the installation disk can be pressed Alt + at the beginning of the installation interface F1 to switch to live mode), install grub2

# 在 live 模式下切换到 root
sudo -i
# 挂载(假设 live 识别到的硬盘根分区是 /dev/sda1)
mount /dev/sda1 /mnt
# 安装 grub2
grub-install --root-directory=/mnt/ /dev/sda
# 如果显示 “no error”,即可退出,取消挂载
exit
umount -f /mnt

At this point, you can enter the system normally after restarting. If centos7 needs to update the grub configuration, perform the following steps

# 挂载
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
# 切换根目录
chroot /mnt/ /bin/bash
## 更新grub配置
grub-mkconfig -o /boot/grub/grub.cfg

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325302205&siteId=291194637