Imaging machines dual boot and more using gparted

blackest_knight
  9 years ago
  1

Replicating and configuring PC's is a pain but today I am going to share a technique I've developed for creating images.


 

Anatomy of a Hard drive.

There are a few things to note about partitions

You can have only 4 primary partitions, an extended partition is a primary partition.

With a typical dual boot windows 7 machine you probably have

           sda1 windows loader

           sda2 windows

          sda3 linux

          sda4 linux swop file

Alternatively

         sda1 windows loader

         sda2 windows

         sda3 Extended Partition

                   sda4 linux

                  sda5 linux swop file

or even

        sda1 windows loader

       sda2 windows

       sda3 Extended Partition

                sda5 linux

              optional sda6 other linux or windows

      sda4 linux swop file

While all 3 schemes function similarly you should note that Linux can be on sda3,4,5 depending on how you partitioned the drive. If your going to have 2 installs of windows then I would put the second at the start of the Extended partition. Linux swop I tend to leave at the end of the drive outside the extended partition. Only one swop partition is needed for all linux installs but it should be 1.5x the ram size or larger.

Grub is installed to the master boot record but you will need to chroot to the new linux partition

grub-install /dev/sda

then

update-grub

This should produce a boot menu with windowsloader and linux mint (or other linux debian ubuntu ect)

windows loader

windows loader is the hidden to windows boot loader usually 100 - 300 Mb in size

The windows loader can boot more than 1 version of windows and it also holds the license key activation(s).

Sometimes you may need a windows7 install disk to repair this bootloader and possibly need to reactivate windows generally its not a problem if you keep the loader on the hard drive and windows in the same place but things happen...


 

More than 2 operating systems

If you need more partitions you need an extended partition (this counts as one of your four primary partitions) so I create

windows loader

windows

extended partition

  first os

  second os

 third os

 ect....

Linux swop

Partition names are given in order of creation which can be awkward

so

sda1 = windows loader

sda2 = windows

sda3 = extended partition

sda 4 = linux swop

sda5 first logical drive

sda6 second logical drive

sda7 .. ect

The awkward bit

Deleting partitions in an extended partition. You have to delete the last partition first  so if you want to delete sda5 you need to delete sda6 (and higher first).

The Image Drive

Partitions on a drive should be as small as possible, so they are mostly used. This means you can store more of them and perhaps more importantly minimises the time spent transfering the image to the destination drive.

You can't do a thing with a mounted drive.

Making an image

You can do it one of two ways really create a dualboot system with a regular drive or use Virtualbox and create it in there. 

Making them is about the same either way install windows install linux. Then configure them as required.

In my case I needed windows with office flash adobe reader gimp and a few others. With linux i needed gns3 along with images actually with virtualbox as well (i installed gns workbench which is an ubuntu image which has gns3 preconfigured) yes a vm within a vm.

Extracting a drive from virtualbox

Getting the image file out of virtualbox is a little tricky you need to convert the file on disk to a .img file using vboxmanage

something like

to convert .vdi to .img file :

C:\Program Files\Oracle\VirtualBox>

C:\Program Files\Oracle\VirtualBox>VBoxManage cloned

D:\Softwares\ubuntu10.vdi ovm.img -format raw

C:\Program Files\Oracle\VirtualBox>dir

should create the disk in .img format

http://sourceforge.net/projects/win32diskimager/

use the above link to get win32diskimager to write the diskimage to an external usb drive this will turn your virtual partitions to real partitions. 

 

Initially I used this along with a 2nd linux partition on the usb drive. This was so i could boot from it (copy of av linux) and unmount the partitons I wanted to copy. (see installing grub later)

It is fairly slow to boot, so its actually easier to boot with a live cd like mint mate 16.

The debian version of gparted (avLinux) had a bit of a bug that if your bios says there is a floppy drive and there isn't it hangs looking for partitions. A Live dvd is a better way to go to be fair.

 

Using Mint Live DVD as a Boot Disk

with the mint dvd, gparted isn't included on the disk so the first thing to do is

sudo apt-get install gparted (about 512k download)

if your usb drive is plugged in its quickest to unmount any mounted partitions with the file manager or the disk utility

Then

sudo gparted.

Generally you will be best to keep the existing windows loader on the destination system although you can copy it from your usb drive (if you copy it you will need the windows install cd to fix windows startup)

the procedure then is delete sda2 the existing windows partition and copy and paste the partitions from the USB drive. 

To speed this up its a good idea to resize the partitions as small as you like maybe with some head room of free space in the partition.  Resizing will save you copying zero's, which are just as slow as 1's.

Note: Windows destination partition requires 1 more MB than the source partition (weird quirk of gparted)

For the destination drive you can resize to your requirements the minimum hard disk size in the destination drive should be at least 40 gb really  (I was working with 25gb windows 12gb linux partitions)

on a 300GB destination i would 

copy windows resize to 200gb copy linux and resize to about 94GB and swop should be 1.5x ram size or more, 6GB i used.

once these operations are set up grab a coffee or get on with finishing up a previous imaged PC.

Once gparted has finished note the partition name of the new linux partition. (sdaX)

Fixing Booting

http://howtoubuntu.org/how-to-repair-restore-reinstall-grub-2-with-a-ubuntu-live-cd

  sudo mount /dev/sda3 /mnt

sudo mount --bind /dev /mnt/dev &&
sudo mount --bind /dev/pts /mnt/dev/pts &&
sudo mount --bind /proc /mnt/proc &&
sudo mount --bind /sys /mnt/sys

sudo chroot /mnt

In this case Linux mint is on sda3 but it may be different in your case which is why you saw in gparted the name of your linux partition eg sda4 sda5 sda7 ...

now just

grub-install /dev/sda

update-grub

exit

reboot

and select your new linux partition.

once booted into this

sudo su

update-grub (this should pick up the windows partition and get rid of entrys from sdb your usb drive)

grub-customizer can be used to change the default boot order, you might need to

apt-get install grub-customizer, unless you installed it on the image already, its a very easy tool to set boot order timeouts ect in the boot menu .

next  we need to make the name unique this needs to be changed in 2 places.

so

nano /etc/hosts and change the hostname.

nano /etc/hostname and change the hostname there too. (don't call it the same as the windows side)

That will probably be all you need to do to Linux Mint. If you left some empty space in an extended partition you could add another partition as required. 

Next windows

reboot and select windows

two things may happen now

on one system the sata mode was wrong in the bios and windows couldnt find the windows partition so i had to change that, 

or it may just say 1 or more disks will need to be checked, you can probably skip that the first time but eventually you should get to login as the user you had in the virtual/original machine.  As your virtual machine was fully updated there will be most of the updates already installed when logging in it will spend some time installing drivers for the new hardware.

If windows can't boot you can use a windows install disk to boot up and choose the repair option.

Be warned that windows can be a thug and sometimes may delete Linux from the drive, (but now you can put it back on in 10 minutes). Generally a repair seems to be safe but installing windows can be destructive.

At this time you probably can right click on computer in the start menu select properties and choose advanced settings and change the name and put it in a workgroup if it isn't in one already. Depending on network speed it should get most of the hardware right fairly quickly so you can reboot and windows will probably want to install 50 updates or so (however it won't need to spend a day online fetching and installing updates like a regular fresh install).

If you are unlucky and your network card doesn't get a driver, you can boot to linux download the windows driver and save to the windows drive.

Check in device manager to see if all the hardware has drivers (update drivers will probably sort out most items) I did find an old s3 video chipset caused a few issues on a couple of pc's but searching for the mainboard (an asus) located a driver on the asus website.

after rebooting you can add the windows box to your domain (you need appropriate credentials to do so) You will probably find updates are available for windows and office.
 

Windows Activation

You may or maynot need to reactivate windows and office with them being volume licensed in my case they tended to  connect to the domain server which has the key licensing server and activate themselves. It is also handy to start office say excel who will suggest user name and initial and then ask about updates

it may or may not activate immediately  generally i found if i opened excel to start with it might be unlicensed the first time but if i then opened word then it had contacted the key server.

If you move virtual hard drives between PC's windows seems to stay activated.

Windows volume licensing there are 2 methods to activate using volume licensing but I'm going to describe just one type.  For volume licensing you tend to have a key server service running on a server. Windows asks to activate from a client and this server validates the license for 180 days. Periodically Windows will ask again and keep the license activated. The problem is that if you are off the domain for six months then Windows will lose activation. There is also a secondary issue a key server will not activate licenses untill it has 25 clients (a server counts as 5 clients).
 

More Notes

If your happy with the existing windows install you can do a simple resize of the existing windows partition  with gparted and just install your linux images.

I did one install with 2 sets of windows 32bit and 64 bit, I found that installing to the second ntfs partition (one was a new install) that windows wiped my linux partitions off the extended partition. I had to use the rescue mode of the windows install disk to make both windows installs boot and then copy back my linux installs. 

working with image files (untested)

I found that you should be able to copy to an image file mount it with loop device and use gparted to write to

a physical drive.

http://knoppix.net/forum/showthread.php?28527-Using-hard-drive-image-files-and-gparted

I'm not going to say any more about this as I haven't tried this myself.

Transfer Times

I found that a 12gb partition took around 8 minutes to copy over. So for that and 25gb of windows it took around 25 minutes to get the images on to the new machine. Enlarging images takes a few seconds, which is one reason you make them small as practical, remember windows has a pagefile and you at least need space for that.

Alternative Methods

I did try norton ghost but found it messed up copying linux. 

My next project is connecting Linux Mint to a windows domain

http://blog.zwiegnet.com/linux-server/join-linux-mint-to-windows-domain/

fairly simple with like-open and like-open-gui

install the two packages and use the gui to give the domain name (you need network admin credentials to do this) and then network users can use their user name / password to logon to the linux boxes (unfortunately you need to do a bit more than that to get on the domain)

However with a dualboot box their needs to be a different hostname for  the windows side and the linux side  e.g box1.yourdomain.local and box1L.yourdomain.local  you will need a separate group policy for Linux.


 


 

Comments
Slennut 9 years ago

Thoughtfully written.\ documentation.
Sadly, it is far more complex / advanced than my novice-level knowledge can fully understand.
I am actually interested in imaging a Single-Boot (No Windows) hard drive to install in a machine that only has CD capabilities (No DVD).
Anything in that regard would be helpfull and greatly appreciated.
Thank you all for the voluntary dedication and giving me and all of us the freedom from the infernal M$ Windows hell!!!


Ikem 9 years ago

I suggest to use screenshots of GParted to show the partition layout.


Ikem 9 years ago

> sda4 linux _swop_ file

It's called "swap". ;)


blackest_knight 9 years ago

Hi
Yes i'm a bit rough with English I will see about editing it later. I've been doing this for a couple of weeks so wrote everything from memory so it probably needs a good rewrite.


mdavies5 9 years ago

Very handy but I found a few sections hard to understand due to poor grammar. Nothing a few commas and apostrophes wouldn't solve.