-
How to run 126 Xp in a hard disk - with a bit of help from Linux
How to run 126 Xp in a hard disk - with a bit of help from Linux
Introduction
This thread is a demonstration of a PC user learns a little bit of Linux can make a M$ system run miles. I did it to satisfy my own curiosity too see if such thing could be done.
Basically I boot any one of an activated Xp from the 126 partitions. Being poor the Xp is the same license in everyone of the 126 partitions but the scheme obviously works if each partition hold a different license of Xp. Win2k uses the same boot loader so it can be a mixture of both. The scheme is a demonstration but can be extended to several hard disks.
I run different operating systems in one PC and have a need to move around the M$ systems which I found irritating because an accidental mistake can trash the system and I have to re-activate with M$ again. Thus I tried to install Win2k, Xp, Vista and several Win7 systems onto a backup disk so that I can have a copy to go back to when I lose one of them. As the number of M$ systems are more than the 4 primary partitions available in a hard disk I was forced to install them in logical partitions and to use the boot loaders ntldr and bootmgr together. By accident I discovered Xp can be moved freely around the logical partitions and between hard disks. Seeing the way how Vista/Win7’s bootmgr treats the Win2k/Xp’s ntldr. I became convinced that I could extract the Xp (or W2k) off the disk and move it anywhere I want.
Linux has traditionally supported 63 partitions in a Pata/IDE disk and 15 on a SCSI/Sata/USB disk. A couple of years back at kernel release 2.6.20 the maximum number of partitions was standardized to 15 for all hard disks. This limit has been breached recently after a break through in the dynamic detection/assignment of the block devices. The improvement, available in the current 2.6.28 and 2.6.29 kernels, is so new that no one knows exactly how many partitions Linux can support. The reason I run 126 Xp is because I could create 130 partitions in a hard disk and then put Xp in the 126 logical partitions, just by writing short scripts in Linux. So it was one installation and 126 clones.
This thread is putting one and one together to make two.
The scheme in a nutshell
I have an activated Xp installed in a logical partition of a hard disk. It is booted by a Dos partition located at the first partition of that disk. The disk has a couple of Win7 (32 and 64 bit) so the booting was controlled by the bootmgr (same boot loader as Vista). All I did was
(1) To resize Xp to a 5Gb so that it takes less time to duplicate/clone
(2) Use a boot up Linux to write a script to automatically partition a new/spare hard disk for the number of partitions I want.
(3) Clone the system partition (Xp) into a new hard disk, format a fat16 partition in its first partition and fix the booting manually.
(4) Install/clone a Linux in the new hard disk as working tool.
(5) Verify Xp and Linux all operating normally in the new hard disk as the sole disk in the PC.
(6) Use the resident Linux to clone the number of Xp I desire in the new hard disk
(7) Configure the boot loader in Linux to select any of the Xp partitions for booting.
(8) Write in the Dos partition a selection routine to select which partition I boot the next Xp
(9) Reboot and boot to the Xp in the newly designated partition.
Why such scheme works?
Xp or any M$ system does not support foreign systems so partition types not recognised by a M$ system will not get mounted. If a user has 100 Xp partitions he/she can change the partition ID temporarily for all the Xp partitions except the one to be booted. A ntfs partition has an partition ID No. 7. To hide that partition the ID is changed to 17. To unhide it is to change back to Type 7. Hiding and unhiding is a standard technique used by all boot loaders. A partition ID is a standard entry occupying one of the 16 bytes in a partition table. It is used by operating system to select the appropriate driver to read the different filing system inside the partition.
In the booting process a NT versions of M$ Windows, of either Win2k or Xp, the MBR is normally responsible to fetch the boot code residing in the boot sector of the booting partition. That boot code loads the ntldr program which also resides in the same booting partition. The loaded ntldr checks a text file called boot.ini, which must be in the booting partition also, to determine which partition contains Xp and then proceeds to load the OS.
Thus to select from a multiple choices of which Xp partition to be booted up a user needs
(A) To amend the boot.ini to change the target partition number.
(B) Hide the unwanted Xp partitions and unhide the one to be booted.
The above operations (A) can be executed inside or outside a M$ system. I shall provide both alternatives in this thread.. For selecting which Xp to boot and amending the boot.ini file I wrote a simple Basic program executable at a command prompt within Xp. Outside Xp it is a trivial task to write a small script to amend the boot.ini stored in a M$ partition.
To accomplish the Task (B) above I have to use a boot loader capable of altering the partition ID so I chose Grub. Grub is an Open Source program that can be installed without a Linux. I place Grub in a second Dos partition to control the first boot.
The boot up sequence is Grub is loaded first for being in the MBR. It hides and unhides the appropriate partition before handing over the control to the boot sector code in the first Dos partition. The boot sector code of the first partition then loads ntldr which fires up Xp at the required partition.
How do I know I am booting to several Xp and not the same one over and over again?
Good question.
My answer is
(i) I have to change the desktop screen background with a different photo in each partition.
(ii) Also in the XP’s disk management program I can see the drive letter referring the physical position in the hard disk as a confirmation.
(iii) I labelled each partition so by clicking “My Computer” I can see which partition has been booted.
The details of the scheme
As readers are not all interested in the full details but only the selected parts I have arranged the thread broken down into small number of posts as follow
Contents
(1) Introduction – Post #1
(2) How to resize a XP partition to a designated size. – Post #2
(3) How to partition a hard disk with a large number of partition by a BASH script - Post #3
(4) How to clone one partition to anther in the same or different hard disk. - Post #4
(5) How to control the booting of Dos, Xp and Linux - Post #5
(6) How to control the booting of multi copies of Xp - Post #6
(7) Things I learned from the scheme – Post #7
(8) Conclusions - Post #2
Applications and usages
Possibly none except to those who has a need to subject a large number of Xp to different tests.
A Xp user nervous of losing the OS due to virus attacks or accidental damages may wish to keep a working and bootable copy that can fire up in seconds. Thus information of this thread could be of interest to some.
For over 30 years working with M$ systems I never understood how they boot. The few years into Linux gave me an enormous education on how things work in a PC. I did this scheme because I thought technically it should be possible.
Conclusions
(A) One can easily break up a Xp in a logical partition from a Vista/Win7 boot loader and take it to any hard disk by manually assemble the booting files.
(B) Xp can operate successfully anywhere (or any partition) in a hard disk.
(C) Multiple copies Xp can be stored in the same hard disk ready for replacing a damaged or virus-infested version.
(D) Linux has a huge amount of functionalities. It can be used beneficially to help a M$ Windows user.
(E) There is so much fun in writing a script to create 130 partitions in a hard disk, then another script to clone Xp into 126 partitions and finally using a script (or a Basic program) to select the booting of Xp in different partitions.
Last edited by saikee; 05-09-2009 at 03:38 PM.
-
How to resize a XP partition to a designated size.
The scheme I describe here requires the partitioning to be done in Linux using a script. Linux partitions are created in boundaries of the nearest cylinder. I have a newly installed and activated Xp of only about 3.1Gb large in a 30Gb partition. I decided to go for a 5Gb partition size so I use a Vista/Win7 to resize the Xp to 5Gb. The resizing exercise can be done by Linux with “gparted” program inside also, like Ubuntu working as a Live CD (no need for installation). Basically the resizer of Vista or Linux tells me how many Mb I have in the partition and I just scaled the number to give me 1/6 left. The resized partition in Linux shows up as to be 608 cylinders large. I then proceed to partition 126 logical partition each 608 cylinders large.
The exact partition size, in this case 608 cylinders, is the key in any cloning operation. This can ensure the integrity of the ntfs filing structure is maintained because many M$ systems have some system file locations "hard coded" and the relatively positions cannot be changed when the partition is re-located.
In the following partition tables the sda is the disk that has 126 Xp partitions (marked blue from sda5 to sda130) and the sdb is the source with sdb15 marked out red as the original installation.
Code:
root@saikee-desktop:/home/saikee# sfdisk -l
Disk /dev/sda: 182401 cylinders, 255 heads, 63 sectors/track
too many partitions - ignoring those past nr (507)
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 0+ 242 243- 1951897 6 FAT16
/dev/sda2 243 485 243 1951897+ 6 FAT16
/dev/sda3 486 1701 1216 9767520 83 Linux
/dev/sda4 1702 85545 83844 673476930 5 Extended
/dev/sda5 1702+ 2309 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda6 2310+ 2917 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda7 2918+ 3525 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda8 3526+ 4133 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda9 4134+ 4741 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda10 4742+ 5349 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda11 5350+ 5957 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda12 5958+ 6565 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda13 6566+ 7173 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda14 7174+ 7781 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda15 7782+ 8389 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda16 8390+ 8997 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda17 8998+ 9605 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda18 9606+ 10213 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda19 10214+ 10821 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda20 10822+ 11429 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda21 11430+ 12037 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda22 12038+ 12645 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda23 12646+ 13253 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda24 13254+ 13861 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda25 13862+ 14469 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda26 14470+ 15077 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda27 15078+ 15685 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda28 15686+ 16293 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda29 16294+ 16901 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda30 16902+ 17509 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda31 17510+ 18117 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda32 18118+ 18725 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda33 18726+ 19333 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda34 19334+ 19941 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda35 19942+ 20549 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda36 20550+ 21157 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda37 21158+ 21765 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda38 21766+ 22373 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda39 22374+ 22981 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda40 22982+ 23589 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda41 23590+ 24197 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda42 24198+ 24805 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda43 24806+ 25413 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda44 25414+ 26021 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda45 26022+ 26629 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda46 26630+ 27237 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda47 27238+ 27845 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda48 27846+ 28453 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda49 28454+ 29061 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda50 29062+ 29669 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda51 29670+ 30277 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda52 30278+ 30885 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda53 30886+ 31493 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda54 31494+ 32101 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda55 32102+ 32709 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda56 32710+ 33317 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda57 33318+ 33925 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda58 33926+ 34533 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda59 34534+ 35141 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda60 35142+ 35749 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda61 35750+ 36357 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda62 36358+ 36965 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda63 36966+ 37573 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda64 37574+ 38181 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda65 38182+ 38789 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda66 38790+ 39397 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda67 39398+ 40005 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda68 40006+ 40613 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda69 40614+ 41221 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda70 41222+ 41829 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda71 41830+ 42437 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda72 42438+ 43045 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda73 43046+ 43653 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda74 43654+ 44261 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda75 44262+ 44869 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda76 44870+ 45477 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda77 45478+ 46085 608- 4883759+ 7 HPFS/NTFS
/dev/sda78 46086+ 46693 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda79 46694+ 47301 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda80 47302+ 47909 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda81 47910+ 48517 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda82 48518+ 49125 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda83 49126+ 49733 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda84 49734+ 50341 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda85 50342+ 50949 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda86 50950+ 51557 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda87 51558+ 52165 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda88 52166+ 52773 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda89 52774+ 53381 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda90 53382+ 53989 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda91 53990+ 54597 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda92 54598+ 55205 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda93 55206+ 55813 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda94 55814+ 56421 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda95 56422+ 57029 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda96 57030+ 57637 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda97 57638+ 58245 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda98 58246+ 58853 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda99 58854+ 59461 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda100 59462+ 60069 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda101 60070+ 60677 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda102 60678+ 61285 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda103 61286+ 61893 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda104 61894+ 62501 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda105 62502+ 63109 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda106 63110+ 63717 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda107 63718+ 64325 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda108 64326+ 64933 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda109 64934+ 65541 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda110 65542+ 66149 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda111 66150+ 66757 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda112 66758+ 67365 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda113 67366+ 67973 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda114 67974+ 68581 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda115 68582+ 69189 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda116 69190+ 69797 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda117 69798+ 70405 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda118 70406+ 71013 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda119 71014+ 71621 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda120 71622+ 72229 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda121 72230+ 72837 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda122 72838+ 73445 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda123 73446+ 74053 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda124 74054+ 74661 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda125 74662+ 75269 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda126 75270+ 75877 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda127 75878+ 76485 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda128 76486+ 77093 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda129 77094+ 77701 608- 4883759+ 17 Hidden HPFS/NTFS
/dev/sda130 77702+ 78309 608- 4883759+ 17 Hidden HPFS/NTFS
Disk /dev/sdc: 38913 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/sdc1 * 0+ 242 243- 1951866 6 FAT16
/dev/sdc2 243 485 243 1951897+ 16 Hidden FAT16
/dev/sdc3 3890 7536 3647 29294527+ 83 Linux
/dev/sdc4 7537 38912 31376 252027720 5 Extended
/dev/sdc5 7537+ 8752 1216- 9767488+ 17 Hidden HPFS/NTFS
/dev/sdc6 11184+ 14830 3647- 29294496 83 Linux
/dev/sdc7 14831+ 18477 3647- 29294496 83 Linux
/dev/sdc8 18478+ 22124 3647- 29294496 17 Hidden HPFS/NTFS
/dev/sdc9 22125+ 25771 3647- 29294496 17 Hidden HPFS/NTFS
/dev/sdc10 25772+ 29418 3647- 29294496 17 Hidden HPFS/NTFS
/dev/sdc11 29419+ 30634 1216- 9767488+ 17 Hidden HPFS/NTFS
/dev/sdc12 30635+ 31850 1216- 9767488+ 83 Linux
/dev/sdc13 31851+ 33066 1216- 9767488+ 17 Hidden HPFS/NTFS
/dev/sdc14 33067+ 34282 1216- 9767488+ 17 Hidden HPFS/NTFS
/dev/sdc15 34283+ 34890 608- 4883728+ 7 HPFS/NTFS
/dev/sdc16 35499+ 36714 1216- 9767488+ 17 Hidden HPFS/NTFS
/dev/sdc17 36715+ 37930 1216- 9767488+ 83 Linux
/dev/sdc18 37931+ 38912 982- 7887883+ 82 Linux swap / Solaris
root@saikee-desktop:/home/saikee#
How to prepare Xp for duplication
Remove pagefiles and connections with other drives.
My Xp was installed in a logical partition booted from a Dos in a primary partition. Thus ntldr will make the booting partition as a "C" drive, Xp a "D" drives by re-mapping all partitions it recognises as other drives. The feature has to be recreated in the new environment.
A working Xp partition is of course has to be much bigger than 5Gb. The one in here is for demonstration only to show how the concept works.
Last edited by saikee; 05-09-2009 at 01:18 PM.
-
How to partition a hard disk with a large number of partition by a BASH script
Actually I did it in several small scripts although it is possible to combine all of them together.
First I create a file called a2 by specifying 243 cylinders (2Gb) in the 1st and 2nd primary partition. The 3rd primary partition is to be 1216 cylinders (10Gb), the rest is to be for an extended partition. Inside the extended partition I did a loop of requiring 200 logical partitions each 608 cylinders large. The command creating a2 is listed below
Code:
echo ",243,6" >a2
echo ",243,6" >>a2
echo ",1216,83" >>a2
echo ",,E" >>a2
for ((i=1;i<=200;i++))
do
echo ",608,17"
done >>a2
The above instructions are understood by program “sfdisk” only which is one of the many partitioning tools available in Linux. The manual of sfdisk is available in a Linux terminal if this command is issued
For those new to the sfdisk (by the way I never used sfdisk myself before this thread. I did so because it can do most number of partition for me and is so simple) I print out the relevant part of the man page below
Code:
INPUT FORMAT
sfdisk reads lines of the form
<start> <size> <id> <bootable> <c,h,s> <c,h,s>
where each line fills one partition descriptor.
Fields are separated by whitespace, or comma or semicolon possibly fol‐
lowed by whitespace; initial and trailing whitespace is ignored. Num‐
bers can be octal, decimal or hexadecimal, decimal is default. When a
field is absent or empty, a default value is used.
The <c,h,s> parts can (and probably should) be omitted - sfdisk com‐
putes them from <start> and <size> and the disk geometry as given by
the kernel or specified using the -H, -S, -C flags.
Bootable is specified as [*|-], with as default not-bootable. (The
value of this field is irrelevant for Linux - when Linux runs it has
been booted already - but might play a role for certain boot loaders
and for other operating systems. For example, when there are several
primary DOS partitions, DOS assigns C: to the first among these that is
bootable.)
Id is given in hex, without the 0x prefix, or is [E|S|L|X], where L
(LINUX_NATIVE (83)) is the default, S is LINUX_SWAP (82), E is
EXTENDED_PARTITION (5), and X is LINUX_EXTENDED (85).
The default value of start is the first nonassigned sector/cylinder/...
The default value of size is as much as possible (until next partition
or end-of-disk).
However, for the four partitions inside an extended partition, the
defaults are: Linux partition, Extended partition, Empty, Empty.
But when the -N option (change a single partition only) is given, the
default for each field is its previous value.
The a2 is merely the terminal command I would issue when using the program “sfdisk”. To make the operation automatic I finally issued it formally in a terminal for partitioning a hard disk sdb
Code:
sfdisk /dev/sdb < a2
The sfdisk program actually stopped after creating 130 partitions even though it has been asked to create 204.
In perfecting my script I of course made mistakes and so I use this scripe to remove all the partitions in a partition table.
Code:
echo "Input disk partition table to be nuked, e.g. choose sda or sdb or hda etc"
read kill_disk
for ((i=1;i<=4;i++))
do echo "d"
echo $i
done > a1
echo "w" >>a1 | fdisk /dev/$kill_disk < a1
It is noteworthy to point out when one deletes all the partitions in a hard disk one only needs to delete the 4 primaries. If one of the primary is an extended partition then the access to the chain of logical partitions is broken automatically if its head is cut off..
A few words about the maximum number of partition in a hard disk.
The hard disk’s legacy partition table started by Dos does not appear to have a finite limit on the number of partitions in a hard disk. The layout of the logical partition is that it must be consecutive with one logical partition carrying the hard disk location of the next logical partition down the line. The last one is confirmed if its partition boundary matches the end boundary of the extended partition. This feature works satisfactorily as long as there is only be one extended partition in the legacy partition table. The chain of a set of logical partition can be as long as we want as we can use smaller links (partitions) in between.
My point here is that as long as a M$ system supports the legacy partition table it is obligated to chase the logical partition chain to find its end. M$ system mounts every partition it recognised and can run out of the drive letters from the available 26 English alphabets. However a M$ system does not mount a foreign partition it does not support so technically a M$ system by default must be able to cope with more than 26 partitions in a hard disk. The number beyond which a M$ system, or ant PC system, will stop search for the end of the logical partitions has not been put to a test.
Linux used to permit 63 partition in a IDE/Pata hard disk and 15 on a SCSI/Sata/USB disk, presumably there can be only 4 disks for the former and 16 disks for the latter. A partition is a block device name in Linux and including the whole disk itself this arrangement gives a total of 256 devices names for both types of hard disks, namely 4x64 for IDE/Pata and 16x16 for SCSI/Sata/USB. These were the limits for a long time. Thus the number of partitions has been self imposed in Linux.
A couple of years back starting with kernel 2.6.20 Linux Linux ceased to support the 63 partitions in Pata hard disks and standardised on 15 partitions for every SCSI/Sata/Pata/USB disk up to the kernel 2.6.27. However a recent break through in the block device detection/assignment procedure allows the kernel 2.6.28 or newer starting to breach the maximum 15 partition limit again. The new freedom is so new that no one has declared the maximum number of partitions possible and the new capability has not been universally adopted in various Linux programs, installers and kernel components. So nobody know where we can go from here.
With distros having the 2.6.28 and newer kernels the maximum limit of partitions in a hard disk depends on the partitioning tools selected. Linux is endowed with several versatile partitioning tools. The most robust tool “fdisk” (not the Dos version although it shares the same name) only handles 60 partitions, “cfdisk” can be used to create up to 63 partitions, “sfdisk” has a limit of 130 and “gparted” can do even more. I have not investigated “parted” and did not use gparted because the “sfdisk” is easy for writing scripts to automatically partition the disk. Gparted stands for Gnome Partition Editor. Since Gnome is the name of one of the two most widely used desktop Gparted therefore does not entertain script for its own execution. Creating 130 partitions manually in a desktop is too time consuming for me.
Thus the 130 partitions is a consequence of using a script on program “sfdisk”.
A word of caution here as the kernel is not fully ready to deal with high-number partition it may not have the device names available for partition manipulations. Therefore currently I may be able to generate 130 partitions and put XP in them I will have difficulty to mount the partitions beyond the 63th position because other components of the kernel have not been aligned to cope with the latest features.
The usage of my 130 partition scheme is as follow, assuming my disk mounted as device sda in Linux when connected as the sole hard disk:-
First primary partition sda1 is formatted to have a fat16 filing system (Type 6) with a 2Gb large to house the boot loader for Xp
Second primary partition sda2 is also the same for back up purpose and storing the partition alteration procedure.
Third primary partition sda3, 10Gb large of Type 83, is to house a Linux. I used Ubuntu v9.04 without a swap partition.
The fourth primary partition is to be converted to an extended partition with 126 logical partitions, each 5Gb, inside. The first logical partition is sda5 and the last one sda130. To make life easy I create the partition as type 17 defined as “hidden ntfs/hpfs”. My 126 Xp are to be housed inside the 126 logical partitions.
The disk can be a raw disk from a new purchase or a spare disk with useful data already back up. My current disk is a 1.5TB Seagate Barracuda Sata which is not even half full.
Last edited by saikee; 04-04-2010 at 08:56 AM.
-
How to clone one partition to another partition in the same or different hard disk
Cloning partition is done easily in a Unix/Linux system because it has a “data dump” command called “dd” that reads a hard disk in units of sectors and duplicates the same on a file or another hard disk. This is a sector-by-sector copying of the binary bits of “1” and “0” of the hard disk. The content of the hard disk or partition is irrelevant. By copying sectors the starting point has to be either at the beginning of a disk or a partition. The data dump stops when number of sectors is exhausted in either source or the target, unless it is instructed otherwise.
The dd command is very simple but can be very useful. M$ users unfamiliar with such Unix/Linux basic function pay out money to proprietary software to get the same thing done. In the simplest form the dd command is to read from an input file defined as a device (say /dev/sda) and dumps the same on an output device (say /dev/sdb). Device sda and sdb without a number denote the whole disk. The number after the disk name denotes the partition number. The first 4 numbers are primaries and all logicals start from the 5th position. Thus looking at a device like sdc7 means it will be the 7th partition of the 3rd hard disk. If the first disk is withdrawn the 2nd and 3rd disks of sdb and sdc will be automatically elevated to sda and sdb respectively.
This command clones the whole disk from sda to sdb.
Code:
dd if=/dev/sda of=/dev/sdb
If the number of sectors is not specified, usually by a parameter called block size bs, dd defaults to one section of 512 bytes at each transfer. I clone all the partitions by bs=32256 which is an exact size of one head that has 63 sectors. The 32256 bytes is the product of 63x512. This appears to be the optimum as I have tried to increase the bs size up to a couple of Gb in a 64-bit operating system with 6Gb DDR3 memory but the bs=32256 still gives me the best speed.
In the cloning process I copied my original Xp from the 17th partition of disk sda and put it in the new disk sdb at the first of the logical partition (sdb5). The command is just
Code:
dd if=/dev/sda17 of=/dev/sdb5 bs=32256
To have a Linux to use I also cloned a Ubuntu to sdb3 so that I could withdraw all the other hard disk and use the Ubuntu to execute the cloning of the remaining 125 Xp partitions.
The cloning will take some times. As there was no need to spin other hard disks so I powered down, removed other disks and booted my new disk as the sole hard disk in the system. It had only Ubuntu in sda3 and Xp in sda5. I tested both systems, satisfied that they were operating normally and then proceeded to clone partition sda5 to partitions sda6 to sda130 inclusively by just this script (in red).
The time taken to clone each partition has been reported after the script.
Code:
saikee@saikee-desktop:~$ sudo su
[sudo] password for saikee:
saikee@saikee-desktop:~$ date
Fri May 8 00:51:30 BST 2009
root@saikee-desktop:/home/saikee# for ((i=6;i<=129;i++))
> do dd if=/dev/sda5 of=/dev/sda$i bs=32256
> done
date
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.403 s, 47.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 102.977 s, 48.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 100.794 s, 49.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.025 s, 44.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 99.3423 s, 50.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 103.678 s, 48.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 104.813 s, 47.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 102.131 s, 49.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 101.966 s, 49.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 103.31 s, 48.4 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 102.124 s, 49.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.179 s, 47.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 104.015 s, 48.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 104.388 s, 47.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 103.087 s, 48.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 105.193 s, 47.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 102.791 s, 48.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 103.986 s, 48.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 104.832 s, 47.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 102.529 s, 48.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 105.862 s, 47.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 107.749 s, 46.4 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.294 s, 47.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 104.407 s, 47.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.74 s, 46.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 103.827 s, 48.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.058 s, 47.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 105.15 s, 47.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.591 s, 46.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 108.112 s, 46.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.78 s, 46.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 110.372 s, 45.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 111.564 s, 44.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 111.847 s, 44.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 109.518 s, 45.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 107.176 s, 46.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.628 s, 46.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 108.983 s, 45.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.711 s, 46.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 107.192 s, 46.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 107.449 s, 46.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 107.368 s, 46.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 107.888 s, 46.4 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 109.255 s, 45.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.119 s, 44.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 107.63 s, 46.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 108.996 s, 45.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 110.5 s, 45.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.808 s, 44.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 106.966 s, 46.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 109.242 s, 45.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 109.059 s, 45.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 108.374 s, 46.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.052 s, 44.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.029 s, 44.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 110.885 s, 45.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 113.416 s, 44.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 110.051 s, 45.4 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 109 s, 45.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 110.165 s, 45.4 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 110.495 s, 45.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 111.723 s, 44.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.37 s, 44.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 114.192 s, 43.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 110.085 s, 45.4 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 110.49 s, 45.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 111.614 s, 44.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.459 s, 44.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 116.089 s, 43.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 113.59 s, 44.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 111.127 s, 45.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.575 s, 44.4 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 111.481 s, 44.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 117.782 s, 42.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 117.358 s, 42.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.397 s, 44.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 114.723 s, 43.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 113.912 s, 43.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 113.351 s, 44.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 111.944 s, 44.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.253 s, 44.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 113.642 s, 44.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.453 s, 44.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 114.273 s, 43.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 113.274 s, 44.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.206 s, 44.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.981 s, 44.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 116.085 s, 43.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.962 s, 44.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 123.663 s, 40.4 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 114.3 s, 43.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 113.165 s, 44.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 112.314 s, 44.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 114.611 s, 43.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 115.87 s, 43.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 121.752 s, 41.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 115.476 s, 43.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 114.673 s, 43.6 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 116.405 s, 43.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 115.828 s, 43.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 116.705 s, 42.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 113.832 s, 43.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 116.745 s, 42.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 115.83 s, 43.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 115.236 s, 43.4 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 116.044 s, 43.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 122.654 s, 40.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 119.118 s, 42.0 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 123.477 s, 40.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 117.797 s, 42.5 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 115.724 s, 43.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 115.872 s, 43.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 117.242 s, 42.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 118.256 s, 42.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 119.609 s, 41.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 119.845 s, 41.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 118.407 s, 42.2 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 121.617 s, 41.1 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 118.353 s, 42.3 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 122.334 s, 40.9 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 119.796 s, 41.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 119.683 s, 41.8 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 125.902 s, 39.7 MB/s
155039+1 records in
155039+1 records out
5000969728 bytes (5.0 GB) copied, 120.203 s, 41.6 MB/s
root@saikee-desktop:/home/saikee# date
Fri May 8 04:41:38 BST 2009
The cloning time was decreasing from 50Md/s to about 40Mb/s, indicating as the read/write arm getting closer to the rotating centre the circumference became smaller, therefore at a constant rotating speed the throughput of the data transfer was reducing.
The cloning operation
started at Fri May 8 00:51:30 BST 2009
Finished at Fri May 8 04:41:38 BST 2009
Which was about 4 hours for 125x5 Gb. This averaged 43.4 Mb/s of data transfer speed which is acceptable by any standard.
The dd command is a “hard” cloning that transfers sectors regardless if they are empty or not. It is totally reliable and can be used to good effect.
Last edited by saikee; 05-09-2009 at 02:52 PM.
-
How to control the booting of Dos, Xp and Linux
I did transfer the existing Dos partition where Xp was originally booted so there was no challenge and gave me nothing to do. However my original Dos partition was managed by bootmgr from two Win7 installation. The bootmgr did manage to survive in the new environment without a Vista or Win7 present and was able to boot up the Xp selected by loading its ntldr. I felt I could do away with bootmgr so I manually arranged the booting files myself. In so doing I used Linux to format my new sda1 and sda2 with simple commands
Code:
mkdosfs –F16 /dev/sda1
Mkdosfs –F16 /dev/sda2
To make the Xp bootable in sda5 bootable I copied the following 3 files from the previous booting partition in the source disk sdb1 into the new booting partition sda1.
Ntldr
Boot.ini
Ntdetect.com
Using Linux the commands were
Code:
mkdir /mnt/sda1
mkdir /mnt/sdb1
mount /dev/sda1 /mnt/sda1
mount /dev/sdb1 /mnt/sdb1
cp /mnt/sdb1/ntldt /mnt/sda1/
cp /mnt/sdb1/ntdetect.com /mnt/sda1/
cp /mnt/sdb1/boot.ini /mnt/sda1/
I then “copied” the boot sector code into the new booting partition. The boot code can be sourced from any of the Xp ior a Vista/Win7 installation disc. With the former I just boot up the disc, opt for the Recovery Console and issue the instructions in Windows recovery Console
If a Vista/Win7 installation disc is used the same can be achieved by
Since I have a booting Dos partition in the first partition and Xp in the first logical partition the Dos will always be detected first for being in the early position of the hard disk and get assigned as the “C” drive.
A MS Dos doesn’t boot in a Sata so my Dos partition, after migrating from a Pata/IDE disk, doesn’t boot even if I restored the MBR with command
This is an interesting feature because I am virtually booting Xp from a data-only partition using Grub. When I withdrew other hard disks leaving only the new disk as the first disk (hd0) Xp can be fired up, after I correct the partition reference in the boot.ini. using these commands in a Grub prompt
Code:
root (hd0,0)
chainloader +1
boot
Last edited by saikee; 05-09-2009 at 03:02 PM.
-
How to control the booting of multi copies of Xp
When I started this idea of booting multiple copies of Xp I knew it can be done with help of Linux so my first attempt was using Linux to control the booting selection. This is because Linux has the following features
(i) Linux sees all hidden files in a M$ partition and can edit them directly without hiding and unhiding.
(ii) Grub is the boot loader used by Linux so it can be configured easily within Linux.
As again I wrote the following script, called 1st-bash, to arrange the boot.ini and to hide/unhide partition before booting of a Xp from any one of the 126 partitions.
Code:
saikee@saikee-desktop:~$ cat 1st-bash
#First mount the sda1 Dos partition
mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
#second iInput from the user which partition is to be booted
echo 'Please enter the Xp partition No to be booted (between 5 to 126)'
read XpNo
XpNo=$(($XpNo-1))
#the partition No less 1 to account for Grub count from 0
#also boot.ini omit counting extended partition as 1 partition
#Third to extract the partion No booted last time and call it old
sed -i "/partition/{h;s/.*partition(\([0-9]*\)).*/\1/;wtmp
x;s/partition([0-9]*)/partition($XpNo)/;}" /mnt/sda1/boot.ini
old=$(sort < tmp | uniq)
rm tmp
echo "Last time it was partition($old) that got booted"
#Four to hide the "old" partition and unhide the new "XpNo"
echo "hide (hd0,$old)" > any
echo "unhide (hd0,$XpNo)" >> any
grub < any
#Five just to display on screen everything is working out before a reboot
cp /mnt/sda1/boot.ini /mnt/sda1/old_boot.ini
fdisk -l
cat /mnt/sda1/boot.ini
chmod u-w /mnt/sda1/boot.ini
The steps involved are
(1) Mount the Dos partition sda1 as a subdirectory /mnt/sda1, so that I could access the file boot.ini
(2) Input from a Linux terminal a new Xp partition number, called XpNo, to be booted.
(3) Extract from the boot.ini the partition previously booted and call it $old and substitute in its position the new partition reference XpNo (Thanks to Forum member Furrycat for suggestions to the code here)
(4) Write out Grub commands of hiding of the old partition and unhiding of the new partition and ask Grub to execute them at the Linux terminal.
(5) Keep a record of the boot.ini, check the arrangement by displaying the partition layout and the content of boot.ini. Finally remove the write attribute in boot.ini.
The above script works satisfactorily but it has two major drawbacks. The first is every time I change to a new Xp partition to boot I need to boot to a Linux first. That is time consuming. Secondly to the purist M$ Windows users using a Linux to help booting a Xp looks bad and so I had to come up with a second scheme requiring the least involvement from Linux.
My second scheme is executed as a Basic program called Xpboot.bas listed as below
Code:
root@saikee-desktop:/home/saikee# cat /mnt/sda2/xpboot.bas
'program xpboot
input "Please enter a partition No. between 5 to 130"; new$
i=val(new$)-1
new$=mid$(str$(i),2)
'new.txt as the new boot.ini
open "f:\new.ini" for output as #1
shell("attrib -r -s -h c:\boot.ini")
print
open "c:\boot.ini" for input as #2
while not eof(2)
i1=0
input #2, a$
for j=1 to len(a$)-10
if mid$(a$,j,10)="partition(" then
i1=j+10
for k=1 to 5
L=i1+k-1
if mid$(a$,L,1)=")" then
i2=L-1
end if
next k
old$=mid$(a$,i1,i2-i1+1)
'print #1,old$
print #1, left$(a$,i1-1)+new$+mid$(a$,i2+1)
end if
next j
if i1=0 then print #1,a$
wend
close
open "f:\boot\grub\menu.bup" for input as #1
line input #1,a$
print a$
print "------------------------------------------"
for i=1 to len(a$)
if mid$(a$,i,5)=chr$(10)+"hide" then
for j=i+5 to len(a$)
if mid$(a$,j,1)="," then i1=j
if mid$(a$,j,1)=")" then
i2=j
exit for
end if
next j
end if
next i
a$=left$(a$,i1)+old$+mid$(a$,i2)
for i=1 to len(a$)
if mid$(a$,i,7)=chr$(10)+"unhide" then
for j=i+7 to len(a$)
if mid$(a$,j,1)="," then j1=j
if mid$(a$,j,1)=")" then
j2=j
exit for
end if
next j
end if
next i
a$=left$(a$,j1)+new$+mid$(a$,j2)
open "f:\boot\grub\menu.lst" for output as #3
print #3,a$
close
print a$
shell ("copy f:\new.ini c:\boot.ini")
shell ("attrib +r +s +h c:\boot.ini")
shell ("type f:\boot\grub\menu.lst")
shell ("type f:\new.txt")
When I am in a Xp I change directory to “F” drive which is the second Dos partition sda2, as I need its boot sector to house Grub, since the one in first partition sda1 has been used up by for loading the Xp's boot loader ntldr. I then execute the Basic program Xpboot.exe which I compiled from the above code. The xpboot.exe changes the boot.ini and also Grub's configuration file in /boot/grub subdirectory in partition sda2. The change to the Grub's menu.lst is just the partition numbers for hiding and unhiding.
In the final arrangement I create a /boot/grub subdirectory in sda2 (know to Grub as (hd0,1)), place Grub's stage1 and stage2 files there plus the configuration file menu.lst. I could in any Grub prompt to change the boot control to sda2 by Grub commands
Code:
root (hd0,1)
setup (hd0)
This allow the Grub inside sda2 (from the two files stage1 and stage2) takes over the overall control. It will load the menu.lst, which I edit with the Basic program Xpboot.bas, and carrying the hiding and unhiding of partitions before passing the control to ntldt.
The menu.lst was copied from Linux whose text files do not use line feed character as a MS system does. Thus in MS Windows the menu.lst is one long line.
The changes conducted by two different booting arrangement (in Linux and within Xp) are marked out in red below on the two affected files
Code:
root@saikee-desktop:/home/saikee# cat /mnt/sda1/boot.ini
;
;Warning: Boot.ini is used on Windows XP and earlier operating systems.
;Warning: Use BCDEDIT.exe to modify Windows Vista boot options.
;
[boot loader]
timeout=5
default=multi(0)disk(0)rdisk(0)partition(79)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(79)\WINDOWS="Microsoft Windows XP Home Edition" /NOEXECUTE=OPTIN /FASTDETECT
root@saikee-desktop:/home/saikee#
Code:
root@saikee-desktop:/home/saikee# cat /mnt/sda2/boot/grub/menu.lst
default 2
timeout 8
title Ubuntu 9.04 @ sda3
root (hd0,2)
kernel /boot/vmlinuz-2.6.28-11-generic root=/dev/sda3 ro quiet splash
initrd /boot/initrd.img-2.6.28-11-generic
quiet
title Xp booted by sda1 (choice selected in Linux)
root (hd0,0)
chainloader +1
title Xp in any partition booted from sda1/sda2
hide (hd0,76)
unhide (hd0,79)
root (hd0,0)
chainloader +1
Last edited by saikee; 05-09-2009 at 03:30 PM.
-
Things I learned from the scheme
(1) It takes a long time to go through the 126 logical partitions. The logical partitions work by one carrying the hard disk address of the one next down the line. Thus to locate the 100th logical partition the boot loader of a computer program must go through 99 logical partitions first. This is not bad for a boot loader that hoops in and hoop out the 99 hard disk locations. However Xp’s boot loader ntldr is very nosy and appears to have been shouldered with the responsibility to mount every partition it recognises and to ensure the target booting system is assigned with the drive letter as originally installed. Since my booting and system partition are “C” and “D” drive respectively therefore if ntldr finds two other partition sandwiched in between it will maintain the existing drive letters and gives new drive letters to the newly discovered partitions even though they are detected earlier in the sequence than the Xp system partition itself. This extra work slows down the ntldr booting operation considerably.
(2) The drive letter of Xp is rigid. When I put a Xp installed as a "D" drive, originally in a logical partition, into a primary and boot it as the only system in the PC it still boots as a "D" when there isn't a "C" around.
When I moved another XP installed as a "C" in a primary partition (sda1) to a a logical partition sda5) it survives as a "C" when I managed to fire it up with a floppy. I then created a Dos partition to boot it (as technically Xp cannot boot itself from a logical partition) the Dos partition (new sda1) is a primary so it is detected first but become a "D" while Xp in a logical (sda5) keeps its "C" drive status regardless.
(3) The NT versions of the boot loader ntldr can be installed in a non-bootable primary partition. I discover this by having a Dos F16 partition housing the ntdlr in a Pata (or IDE) disk but later cloned into a Sata, causing the Dos no longer bootable in sda1. Yet the same Dos partition serves as a spring board to fire up Xp same as before without a hint of stress. Finally on the latest setup I just formatted the sda1 Dos partition in Linux and selectively copied only 3 system files needed for booting. After restoring the boot sector the ntldr inside sda1 can fire up any of the 126 Xp. It should be noted the ntldr is chainloaded by Grub first, as I haven't found a M$ MBR yet that can fire up the ntldr this way.
(4) Altering which partition to be booted in Xp's command prompt is a lot faster. The process is Linux free except using Grub to carry out the first boot.
(5) What I have done is a back door method to use ntldr/boot.ini, which has a static booting screen displayable only the first 10 operating systems, to boot 126 systems (can be different OS in each partition). With Grub I have done it with 145 systems and the bootmgr of Vista has been stretched to boot 150 Linux. Grub is still the easiest, fastest and the most versatile.
(6) The Xp to be moved and cloned should be defraged first. The pagefiles, seen in defrag program as immovable files, should be removed first.
Last edited by saikee; 05-12-2009 at 03:48 AM.
-
writing the menu.lst file to the fat 16 partition containing grub
saikee,
i sent a post something along these lines to this thread several days ago but it doesn't seem to be on the site. so i'll repeat:
using your ideas on booting multiple os's with grub and a linux ive-cd, i've successfully installed grub stages 1, 1.5 and 2 in hda2, the small data-only fat 16 partition i created in my computer's hd and got a grub prompt when powering up.
but i'm unable to write the menu.lst file to go into that fat16 partition before installing any of the os's.
again, using a linux live-cd, i opened a terminal and wrote the following:
sudo mount /mnt/hda2/boot/grub
then i tried using gedit to create menu.lst and save it to this directory, but it failed because i'm doing something wrong. what?
could you please write the exact code necessary to do this? i don't mean the code for the menu.lst file, i can already do that as per your examples, only the code that creates /mnt/hda2/boot/grub/menu.lst
thank you.
janb
-
janb,
Grub when asked to boot to a partition will try to find menu.lst either from /boot or /boot/grub subdirectory. If none is found Grub defaults to a Grub prompt. If one is found then Grub will execute the menu.lst.
Therefore to arrange menu.lst in subdirectory /boot/grub you simply edit a file and call it menu.lst.
In general you need to format a partition before you can write on it. I assume this partition has been created say it is sda2 ( say using cfdisk program with its type specified as b).
To format sda2 with fat16 filing system
Code:
mkdosfs -F16 /dev/sda2
Then you mount the partition on the Linux filing system tree, say on the branch /mnt
Code:
mkdir /mnt/sda2
mount /dev/sda2 /mnt/sda2
Now you can create the subdirectory /boot, /boot/grub and put a menu.lst in
Code:
mkdir /mnt/sda2/boot
mkdir /mnt/sda2/boot/grub
gedit /mnt/sda2/boot/grub/menu.lst
Depending on the distro you can use "kwrite", "nano", "vim" in place of "gedit".
Hope the above is clear to you.
-
writing the menu.lst file to the fat 16 partition containing grub
saikee,
i had all the code as you indicated but when i entered the last line of code:
gedit /mnt/sda2/boot/grub/menu.lst
i got a page that read "/mnt/sda2/boot/grub/menu.lst is a directory" and the only option i had was to click on "cancel"
janb
-
In that case you might have accidentally create menu.lst as a subdirectory.
You can check it in the desktop. The other way is to list the content of a subdirectory. If /mnt/sda2/boot/grub/menu.lst is indeed a directory then it will report error if you edit or display it. To display the content of a text file you can use the command
Code:
cat /mnt/sda2/boot/grub/menu.lst
To list the content of it as directory
Code:
ls /mnt/sda2/boot/grub/menu.lst
To remove /mnt/sda2/boot/grub/menu.lst as a file
Code:
rm /mnt/sda2/boot/grub/menu.lst
To remove /mnt/sda2/boot/grub/menu.lst as a directory
Code:
rmdir /mnt/sda2/boot/grub/menu.lst
To remove /mnt/sda2/boot/grub/menu.lst regardless if it is a directory or not plus all the subdirectories inside
Code:
rm -r /mnt/sda2/boot/grub/menu.lst
-
i tried each of the commands indicated consecutively and they all gave the same result--"no such file or directory".
very strange, wouldn't you say?
the hard drive is a sata but i still have a tendency to inconsistently refer to satas as hda, hdb... rather than sda, sdb.... do you think this confusion may be part of the problem?
as a last resource, would it help to just wipe the hard drive and repartiton using a live-cd?
-
you always do this command at a root console
Different age Linux and different distros can call your hard disks by various names (normally sda, sdb for new kernels but some distros maintain compatibility refer it to hda, hdb etc if you sre still working withg Pata/IDE disks).
The above command is the first one you should do in any root terminal. Get the device names from the horse's mouth!
-
the same problem as before exists although i re-partitioned. let's just leave that aside for now.
i'm still missing something very essential and elemental, so bear in mind that i'm not a programmer. if i can see this big picture the mystery would be removed:
assuming i had been able to write menu.lst in the fat 16 partition now containing directory /mnt/sda3/boot/grub, using "empty" for the name of each os to be later installed, i would have to write in the name of the first linux os i install only after i install it from its live-cd. correct?
but during each os install process, using the "advanced user" option when it comes to setting up that os's partitioner prior to install so it can re-format the selected partition as ext3 and select the mount point as the "root" of that partition, that os's installation program is going to write its own menu.lst to the mbr in the first 512 bytes of the hard drive. is this so?
so how is control passed to the fat16 grub's menu.lst with its chainloader +1 command to indirectly boot (ie. bootstrap) the selected os?
----------------
finally, as an aside, i've noted that i can easily and successfully install win xp in the first primary partition and multiple linux os's in logical partitions without using a fat 16 partition with grub in it if i use the mount point "root" for each and install either open suse or mandriva live cd's last. somehow, each of these 2 os's installer writes a menu.lst which allows one the option of choosing any one of the previously installed os's to boot at start-up. how do you figure the open suse and mandriva install programs do it?
thanks for your help.
janb
-
What you are asking is the very principle of how a system is booted.
When you partition the hard disk to say 15 partitions. None of them are formatted but each partition's starting and finishing points in the hard disk are defined. Grub just goes to that partition and hand over the control to the boot loader inside it. The "chainloader +1" is to tell Grub to cut its own head off, leaving only its 1st sector of 512 bytes and "paste" it to the +1 (the second sector) position of the partition it has been instructed to boot.
When you install a Linux it always (99% of the cases) allows the boot loader to be placed in the MBR or inside it root partition. The latter is to put the boot loader in the first sector which is permanently reserved as the boot sector in most of the filing systems. If you let the installer write the boot loader on the MBR you can always change it, using any Linux, any Grub prompt or any Grub shell.
Therefore as soon as a system has been installed, its installer has been told to put the boot loader in its root partition that system will boot up regardless what you put in the "title" statement. Grub just displays on the screen whatever you have written after word "title".
In conclusion as long as Grub knows where to find a partition (off the partition table of course) and a boot loader is inside that partition then whatever inside will be booted up.
Most users think booting is a complicated process. It is in fact laughingly simple in Linux. Only M$ has an agenda to make its boot loaders more complicated than they need to be.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|