新思路是,备份分区表,抹掉分区表,在目标逻辑分区处准确标识一个主分区,安装 xp,恢复原有的分区表。试验圆满成功:) 下面记录此次试验的过程。胆小者勿试。
工具:ubuntu livecd,windows xp 安装光盘。
环境:单硬盘 sda、单系统 ubuntu、空闲的逻辑分区用来安装 windows
步骤:
0. 确认你目前的分区表没有问题。运行 sudo parted /dev/sda print 。能够输出各分区的大小,说明分区表没有问题。
1. 备份 mbr。运行
sudo dd if=/dev/sda of=mbr bs=512 count=1
这会备份 mbr 引导代码和主分区表。
把生成的 mbr 文件保存在外置硬盘或网络上。
2. 精确列出当前分区表。记得用 -lu 选项。我的输出是
代码: 全选
billbear@billbear-laptop:~$ sudo fdisk -lu
[sudo] password for billbear:
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x000b39bb
Device Boot Start End Blocks Id System
/dev/sda1 * 63 11213369 5606653+ 83 Linux
/dev/sda2 11213370 12225464 506047+ 82 Linux swap / Solaris
/dev/sda3 12225465 33736499 10755517+ 5 Extended
/dev/sda5 12225528 33736499 10755486 b W95 FAT32
sda5 是我预备安装 xp 的逻辑分区。
3. 抹掉分区表。
sudo dd if=/dev/zero of=/dev/sda bs=512 count=1
4. 在预备安装 xp 的逻辑分区处标识一个主分区。用 sudo fdisk /dev/sda
-u 以确保绝对精确。下面是我的例子。红色是我添加的注释。
billbear@billbear-laptop:~$ sudo fdisk /dev/sda -u
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7050e650.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): p 列出分区表,显然,分区表已经被清空。
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x7050e650
Device Boot Start End Blocks Id System
Command (m for help): n 新建分区
Command action
e extended
p primary partition (1-4)
p 主分区
Partition number (1-4): 1 第一主分区
First sector (63-41943039, default 63): 12225528
Last sector or +size or +sizeM or +sizeK (12225528-41943039, default 41943039): 33736499
这里使用第二步中列出的预备安装 xp 的逻辑分区的精确起止位置。请再三确认。
Command (m for help): p 再看看现在的分区表
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x7050e650
Device Boot Start End Blocks Id System
/dev/sda1 12225528 33736499 10755486 83 Linux
Command (m for help): t 把我们新建的这个分区标识为 ntfs。这步应该可以省略。
Selected partition 1
Hex code (type L to list codes): 07
Changed system type of partition 1 to 7 (HPFS/NTFS)
Command (m for help): p 再确认分区表。
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x7050e650
Device Boot Start End Blocks Id System
/dev/sda1 12225528 33736499 10755486 7 HPFS/NTFS
Command (m for help): w 写入
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
5. 丢进 xp 安装盘。重启,在准备好的主分区安装。记得让安装程序格式化这个分区以确保能够启动。
6. 安装全部结束,进入 xp 桌面。丢进 ubuntu livecd 重启。
7. 在 livecd 环境下恢复旧的分区表连同 mbr grub 引导代码:从外置硬盘或网络上得到你先前备份的 mbr,运行
sudo dd if=mbr of=/dev/sda
8. 重启。ubuntu 又回来了。sudo fdisk -l 看看分区表,如有必要,修正分区 id。我原先的 sda5 是 fat32 的,刚才格式化成了 ntfs,所以现在把 id 改成 07。
代码: 全选
billbear@billbear-laptop:~$ sudo fdisk -l
[sudo] password for billbear:
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000b39bb
Device Boot Start End Blocks Id System
/dev/sda1 * 1 698 5606653+ 83 Linux
/dev/sda2 699 761 506047+ 82 Linux swap / Solaris
/dev/sda3 762 2100 10755517+ 5 Extended
/dev/sda5 762 2100 10755486 b W95 FAT32
billbear@billbear-laptop:~$ sudo blkid
/dev/sda1: UUID="ac4e71bb-066e-4751-83c0-7b0c4f3e8069" TYPE="ext3"
/dev/sda2: TYPE="swap" UUID="1b76caa3-941b-4210-93ca-32a7221c784f"
/dev/sda5: UUID="9A002DD6002DBA61" TYPE="ntfs"
billbear@billbear-laptop:~$ sudo fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 07
Changed system type of partition 5 to 7 (HPFS/NTFS)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
billbear@billbear-laptop:~$ sudo fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000b39bb
Device Boot Start End Blocks Id System
/dev/sda1 * 1 698 5606653+ 83 Linux
/dev/sda2 699 761 506047+ 82 Linux swap / Solaris
/dev/sda3 762 2100 10755517+ 5 Extended
/dev/sda5 762 2100 10755486 7 HPFS/NTFS
9. 修改 menu.lst,添加启动项用软盘映像引导逻辑分区上的 windows。