将BIOS旧版Arch安装克隆到映像文件

时间:2019-08-02 21:49:56

标签: linux bash

我正在尝试将Arch磁盘(旧版)的已用块复制到图像文件。 Arch安装仅在1个分区上 dos,可启动83,ext4

从现场CD:

// Mounting the disk to copy
sudo mount /dev/sdb1 /mnt/source

// Getting the size of the used block and adding 0.6G
size=$(sudo df -h /mnt/USB | tail -1 | sed 's/  */ /g' | cut -d ' ' -f3 | sed 's/G//g')
size=$(echo "(${size} + 0.6)" | scale=0 bc)

// Creating an empty image file of the right size
fallocate -l ${size}G copy.img

// Creating the partition
sudo fdisk copy.img <<EOF
o
n
1


a
1
w
EOF

// Mounting the image to a loop device
sudo losetup -fP copy.img

// Formatting the partition
sudo mkfs.ext4 /dev/loop0p1

// Mounting the partition
sudo mount /dev/loop0p1 /mnt/destination

// Copying the files
sudo rsync -aHAX --info=progress2 /mnt/source/* /mnt/destination

// CD to destination && mounting dev/sys/run/proc
cd /mnt/destination
sudo mount -t proc /proc proc/; sudo mount --rbind /sys sys/; sudo mount --rbind /dev dev/; sudo mount --rbind /run run/

// Chrooting in the destination
disk=$disk loopDevice=$loopDevice sudo -E chroot /mnt/destination /bin/bash <<"EOT"
mount -a
oldUUID=$(lsblk -oNAME,UUID ${disk}1 | tail -1 | cut -d ' ' -f2)
newUUID=$(lsblk -oNAME,UUID ${loopDevice}p1 | tail -1 | cut -d ' ' -f2)
sed -i "s/${oldUUID}/${newUUID}/g" /etc/fstab
sed -i "s/${oldUUID}/${newUUID}/g" /boot/grub/grub.cfg
grub-install ${loopDevice}
grub-mkconfig -o /boot/grub/grub.cfg
mkinitcpio -p linux
EOT

// Unmount disk
sudo umount /dev/source
sudo umount /dev/destination

我希望该映像可写到新磁盘,并且新磁盘是完全相同的副本。

但是我要么得到“未检测到可引导磁盘”,要么出现严重的“错误:找不到设备'UUID = XXXX'。正在跳过fsck。”即使在/ etc / fstab和/boot/grub/grub.cfg中仔细检查后,UUID才是正确的。

我被困住了...

0 个答案:

没有答案