Ubuntu 22.04引导加载程序安装方法及/home分区疑似损坏时的数据备份方案咨询
Hey there, let's take this one step at a time—your top priority right now is securing the data on your /home partition, so let's start with that before we even think about fixing bootloaders or reinstalling anything. Here's how you can go about it:
一、先抢救/home分区的数据
First, boot up using an Ubuntu 22.04 Live USB (make one on another computer if you don't have it already). Choose the "Try Ubuntu" option instead of installing—this lets you work without touching your existing system partitions.
1. 确认分区位置并尝试只读挂载
- Open a terminal (press
Ctrl+Alt+T) and runlsblkorfdisk -lto list all your partitions. Look for the one that was your /home partition (it'll usually be labeled with a size that matches what you remember, and the type might beext4or similar, though it might show as unknown right now). Note down its path, like/dev/sda3. - Next, try mounting it in read-only mode (this avoids making any accidental changes that could worsen corruption):
Replacesudo mount -o ro /dev/sdXn /mnt/dev/sdXnwith your actual /home partition path. - If this works without errors, great! Plug in an external storage drive (like a USB hard disk) and mount it (just click on it in the file manager). Then copy all your /home data over:
You can find the external drive's mount point by checking the file manager—usually it'll be undersudo cp -a /mnt/* /media/ubuntu/[你的外部存储挂载点]/home_backup//media/ubuntu/with a name matching your drive.
2. 只读挂载失败?试试分区镜像或数据恢复工具
- If mounting fails, don't panic—first, create a full image of the partition to your external drive. This way you can work on the image later without risking the original data:
This might take a while depending on the partition size, so be patient.sudo dd if=/dev/sdXn of=/media/ubuntu/[外部存储路径]/home_partition.img bs=4M - Another powerful tool to try is
testdisk. Install it in the Live system first:
Run it withsudo apt update && sudo apt install testdisksudo testdisk, then follow these steps:- Select your HDD from the list, choose the partition table type (usually
Intel/PC partition), then go toAdvanced. - Select your /home partition and hit
List—if TestDisk can detect files, you can select them and copy them directly to your external storage using theckey.
- Select your HDD from the list, choose the partition table type (usually
二、备份完成后修复引导(可选)
Once your data is safe, you can tackle the bootloader issue. If Boot-Repair was throwing errors, let's try a manual GRUB install:
- Still using the Live USB, mount your existing Ubuntu /root partition (the one you confirmed is safe) to
/mnt:
Replacesudo mount /dev/sdX1 /mnt/dev/sdX1with your actual /root partition path. - Mount the necessary system directories to chroot into your Ubuntu system:
sudo mount --bind /dev /mnt/dev sudo mount --bind /proc /mnt/proc sudo mount --bind /sys /mnt/sys - Chroot into your installed Ubuntu:
sudo chroot /mnt - Install GRUB to your HDD (note: this is the disk path, not a partition—like
/dev/sda, not/dev/sda1):grub-install /dev/sda - Update the GRUB configuration to detect your new Windows installation:
update-grub - Exit the chroot environment and reboot:
Make sure to remove the Live USB before your computer starts up again.exit sudo reboot
Take it slow, and don't rush into any reinstalls until you're 100% sure your /home data is backed up. If you run into specific errors with any of these steps, just share the exact error message and we can troubleshoot further.
备注:内容来源于stack exchange,提问作者Mostafa Ashraf ELFEEL

