It is very likely you have four primary partitions. Output from Ubuntu's sudo fdisk -l /dev/sda
(replace sda
with proper name if necessary) would be very useful, but I'll try to help without it.
As for now I can suggest a general scenario to cope with your problem. Have in mind I haven't tested it as a whole.
Having no fdisk
output yet, I will make some assumptions. We can correct them later eventually. The assumptions are:
- the drive is
/dev/sda
in Linux;
- it has DOS MBR, not GPT;
- each of four partitions is a primary partition;
- logical sector size is 512 B;
- partition numbers correspond to your numbered list;
- partition order and numbers match (
sda1
precedes sda2
and so on);
- the bootloader is grub2.
Just like acejavelin said:
DOS MBR allows for 4 primary partitions, or 3 primary and 1 extended partition
The aim is to „convert” your Ubuntu's primary partition to logical partition within extended partition. Kali's partition will be added later as the next logical partition within the extended partition.
Preparing
- Read whole my answer before you start, to get the whole picture. Some steps may be skipped depending on your current partition alignment and your desired partition alignment; i mean messing with Windows mostly.
- Backup your important data.
- Read twice, think twice, check your numbers three times – then do.
- Get any decent Live CD/DVD Linux – e.g. Knoppix or Ubuntu installer (in Try Ubuntu mode; maybe Kali installer has such a mode also, I don't know). Most important is to have
gparted
. Your already installed Ubuntu is no use here, because we cannot have its partition mounted at the time.
- If you need to resize Windows partition (see Moving Partitions section), boot into Windows and run
chkdsk
on C:
. It will probably require restart, so restart and boot back into Windows.
- Again, if you need to resize Windows partition, press WIN+R on your keyboard and type
shutdown -s -t 0
, press enter. Do not boot again to Windows until you resize its partition. If it happens by accident, shutdown with said command. (This step may be important on Windows 8, 8.1, 10 to shut it down completely. It will do no harm regardless of version, so do it anyway.)
- Boot into Ubuntu. Check whether the
/etc/fstab
and /boot/grub/grub.cfg
refer to partitions by /dev/sdaX
or by UUID. Every occurrence of /dev/sda4
will have to be replaced by /dev/sda5
later and we will get to it. References by UUID should be problem-free.
Moving Partitions
Boot Linux from Live CD. If the Live CD of your choice automounts /dev/sda*
– umount
them.
Run sudo gparted /dev/sda
. If my assumptions are correct, it will show:
- tiny
sda1
at the beginning,
- large
sda2
with Windows right next to sda1
,
- small
sda3
following sda2
,
- finally
sda4
with Ubuntu near or at the end.
I don't know where you have left place for Kali. Probably it is at the very end, just after Ubuntu; or just before.
gparted
lets you queue the operations, so you can cancel anyone of them before you do some real change.
Do not touch sda1
. Do not touch the beginning of sda2
. Doing otherwise may render your Windows unbootable. You can shrink Windows partition by moving the end of sda2
and it should not affect the boot. Do it if you want to gain more space for Kali and/or Ubuntu. In that case move also sda3
so there is no free space between sda2
and sda3
.
Move/resize Ubuntu's sda4
so there is 1 MB gap (free space) between sda3
and sda4
This gap is essential. Leave space for Kali at the very end of the disk.
Note: I think we need the gap to be just one sector only, so 1 MB is a lot more than enough; gparted
may make it even bigger. Unfortunately this tool works with megabytes, not sectors. Command line tool parted
can work with sectors but it is less friendly and probably cannot resize ntfs – that's why i chose gparted
.
Apply all the changes and wait for the result. Moving partitions needs time.
Hopefully it will go well. Do sanity check by booting to Ubuntu, Windows. It is expected that chkdsk
will run on resized Windows partition.
Creating Extended and Logical Partition
Boot from Live CD/DVD again. Save your MBR (Master Boot Record, it contains partition table) to a file:
sudo dd if=/dev/sda of=~/mbr.dd bs=512 count=1
In case you make some error, you can restore the partition table with:
sudo dd if=~/mbr.dd of=/dev/sda
Unfortunately the MBR backup is not enough when it comes to logical partitions, yet it can minimize the damage to primary partitions if you mess with them. From now on be extra careful.
Run sudo fdisk /dev/sda
; it is interactive with its own set of commands. Changes are saved to disk with w
command, not earlier. In case of trouble quit with q
command and start over.
Being inside fdisk
invoke p
command to see partition table. Write down (on paper) the start and the end sector of /dev/sda4
, since it is the primary partition we need to delete and then recreate as logical. Verify your notes three times.
The start sector of /dev/sda2
may be by one greater than the end sector of /dev/sda1
; that means there is no gap between them. The same applies for sda3
and sda2
pair. However there should be a gap between sda4
and sda3
. Get the end sector of /dev/sda3
, add one and write the result down as extended start. Verify the numbers three times. Make sure that it is a smaller number than the start of sda4
.
Delete the partition number 4 with d
command. Note that it would not really destroy your Ubuntu, even if you wrote the change to disk right now. Data is still there, fdisk
has only lost track of where the partition was. You will recreate it as logical partition in a few moments.
Make new partition with n
command; let it be extended partition. fdisk
will suggest a start sector with the number being exactly your extended start value – check if it matches, hit enter if so. Then it will suggest an end sector as the last usable sector of the disk – it's the right thing, hit enter.
Again, make new partition with n
command. It will be logical partition with number 5. Give the start and the end sector exactly as they were for original sda4
partition.
You may notice that these numbers make sda4
partition include sda5
. That is correct, logical partitions must all lay inside extended partition. Kali Linux should be able to create its own extended partition(s) inside sda4
since there is space left.
The new partition table is still in memory only (disk is not yet affected). Examine it with p
command. Before you write it with w
, triple check a few things:
sda5
should show ID=83
by default; that value is right for Linux. Use t
command to change it to 83
if it's different.
sda5
should show start and end sectors as they were for original sda4
.
- The new
sda4
should start at the sector just after the last sector of sda3
; that number should be less than sda5
start sector.
The 3rd position on the above list is very important. In a moment you will write changes to disk. Information about partitions 1-4 will be stored into MBR. This change can be reverted with MBR backup we have made. But the information about logical partition sda5
will be stored at the beginning of the extended partition sda4
. It is crucial that sda4
starts in a right place where there is no data – that is the gap we created. If you miss that gap you may lose some data in a moment.
Having it all triple checked, invoke w
command to write changes to disk. fdisk
should tell kernel about the new partitions, so there should be /dev/sda5
available to mount. This is now your Ubuntu.
(In case there is no /dev/sda5
node, try sudo partprobe
to fix it.)
Updating Files (if needed)
At the beginning I suggested to check if your Ubuntu fstab
and/or grub.cfg
uses /dev/sda4
instead of UUID. Old sda4
will be sda5
from now on, so the files may have to be updated. I think it is safe to do, even if the files do not mention sda4
, so when in any doubt do it. First mount:
sudo mount -o rw /dev/sda5 /mnt
You will find those files as /mnt/etc/fstab
and /mnt/boot/grub/grub.cfg
. Do not confuse with /etc/fstab
which belongs to Live CD Linux and has nothing to do with your Ubuntu. Make a backup just in case and replace every sda4
with sda5
. This can be done by one command:
sudo sed -i.backup 's/sda4/sda5/' /mnt/etc/fstab /mnt/boot/grub/grub.cfg
Finally reboot and check if both systems boot as they should. Kali Linux should now be able to utilize free space during install.