Installing Kali Linux
This article covers how to install Kali Linux (Generic Cloud Image) from the BitFolk Rescue VM. It's been written by someone with no experience of Kali Linux and may be incomplete or incorrect, but at the time of writing does result in a working install of Kali.
Overview
We're going to use the Rescue VM to overwrite your VM's /dev/xvda disk with Kali Linux's Generic Cloud Image. We'll then make a few small modifications to allow it to boot at BitFolk.
Requirements
The Kali Linux Generic Cloud Image expands to 12GiB so you will need at least that much disk space. Notably that means you can't follow these instructions if you have only the base 10GiB disk.
The image is a ~1.2GiB tar.xz file with a single file in it called disk.raw. That contains a disk image with an ext4 partition that has only about 9GiB in use, so if you are able to download the image to somewhere else and perform surgery upon it, you should be able to avoid writing 12GiB to your xvda. In the interests of showing a working process, however, this article is just going to cover directly downloading it and streaming all 12GiB of it to disk.
Procedure
Set your terminal to 80x25
We're going to be using the Xen Shell a lot and it is unfortunately a little fragile regarding the size of your terminal. We recommend setting your terminal to 80x25 which will avoid display issues when lines wrap, and will leave you generally more sane.
Boot in to the Rescue VM
Connect to your Xen Shell, shut down any running VM and then boot into the Rescue VM.
you@yourhost:~ ssh youraccount@youraccount.console.bitfolk.com
xen-shell> shutdown
xen-shell> rescue
[…]
rescue login: user
user@rescue:~S
Become root
sudo is available without password to the Rescue VM user.
user@rescue:~S sudo -s
root@rescue:/home/user#
Install needed utilities in the Rescue VM
The Rescue VM doesn't start with all of the utilities we will need, but they are simple to install.
root@rescue:/home/user# apt update
root@rescue:/home/user# apt install curl parted pv
Overwrite your disk with the Kali image
Obviously this is going to destroy any data you had on xvda to begin with.
This command will download, decompress and stream the image directly to your xvda disk. You have to do it this way because you won't have enough spare disk space in the Rescue VM to take a local copy of the image. If you need to do that then you'll probably have to arrange to get more storage as an extra disk device.
The link to the Generic Cloud Image is from the "cloud" section of the "Get Kali" page. You may wish to verify its checksums before using it.
root@rescue:/home/user# curl -s https://kali.download/cloud-images/kali-2022.4/kali-linux-2022.4-cloud-genericcloud-amd64.tar.xz \
| tar -JxO disk.raw \
| pv > /dev/xvda
7.55GiB 0:02:17 [47.1MiB/s] [===========> ] 37% ETA 0:03:45
It won't take as long as pv thinks, because pv is going by the size of the destination disk.
At the end you'll see these warnings as the partition table doesn't match the size of the disk:
[ 1166.037318] GPT:Primary header thinks Alt. header is not at the end of the disk.
[ 1166.037332] GPT:25165823 != 41943039
[ 1166.037337] GPT:Alternate GPT header not at the end of the disk.
[ 1166.037344] GPT:25165823 != 41943039
[ 1166.037348] GPT: Use GNU Parted to correct GPT errors.
[ 1166.037356] xvda: xvda1 xvda14 xvda15
We'll fix that in a moment.
You now have an almost bootable Kali Linux install.
Get parted to fix the partition table
root@rescue:/home/user# parted /dev/xvda
GNU Parted 3.4
Using /dev/xvda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Warning: Not all of the space available to /dev/xvda appears to be used, you can
fix the GPT to use all of the space (an extra 16777216 blocks) or continue with
the current setting?
Fix/Ignore? f
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 21.5GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
14 1049kB 4194kB 3146kB bios_grub
15 4194kB 134MB 130MB fat16 boot, esp
1 134MB 12.9GB 12.7GB ext4
Grow filesystem to full size of disk
At this stage you have a ~12.7GiB partition that's ~9GiB used, but your xvda disk is probably larger than this. It's easy to grow it to full size. You will first continue using parted to grow the partition to the full size of your disk, and then use resize2fs to grow the ext4 filesystem to the full size of the partition. In between there is a fsck.ext4 because that is often necessary before resizing.
(parted) resizepart 1 100%
(parted) p
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 21.5GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
14 1049kB 4194kB 3146kB bios_grub
15 4194kB 134MB 130MB fat16 boot, esp
1 134MB 21.5GB 21.3GB ext4
(parted) q
Information: You may need to update /etc/fstab.
[ 661.690459] xvda: xvda1 xvda14 xvda15
root@rescue:/home/user# fsck.ext4 -fv /dev/xvda1
e2fsck 1.46.2 (28-Feb-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
283138 inodes used (36.38%, out of 778240)
62 non-contiguous files (0.0%)
126 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 0/0/0
Extent depth histogram: 271106/18
2404347 blocks used (77.24%, out of 3112704)
0 bad blocks
1 large file
248428 regular files
22505 directories
8 character device files
0 block device files
0 fifos
156 links
12188 symbolic links (11998 fast symbolic links)
0 sockets
------------
283285 files
root@rescue:/home/user# resize2fs -p /dev/xvda1
resize2fs 1.46.2 (28-Feb-2021)
Resizing the filesystem on /dev/xvda1 to 5210107 (4k) blocks.
Begin pass 1 (max = 64)
Extending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/xvda1 is now 5210107 (4k) blocks long.
Mount your filesystem in the Rescue VM
Some minor tweaks are needed, so you'll need to edit the filesystem content.
root@rescue:/home/user# mount -v /dev/xvda1 /mnt
[ 1511.313042] EXT4-fs (xvda1): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
mount: /dev/xvda1 mounted on /mnt.
Fix Grub config
Change the following lines in /mnt/etc/default/grub. (two of them just become commented out)
GRUB_CMDLINE_LINUX="console=hvc0 earlyprintk=hvc0 consoleblank=0"
#GRUB_TERMINAL="console serial"
#GRUB_SERIAL_COMMAND="serial --speed=115200"
Prepare the chroot
You will need to run some commands in the context of your new Kali Linux, so you'll have to chroot into it.
root@rescue:/home/user# mount -t proc /proc /mnt/proc
root@rescue:/home/user# mount --bind /sys /mnt/sys
root@rescue:/home/user# mount --bind /dev /mnt/dev
root@rescue:/home/user# chroot /mnt /bin/bash
root@rescue:/#
That is bash shell from the Kali Linux install. Future pathnames will omit /mnt from the start as we're inside the chroot now.
Regenerate Grub config
root@rescue:/# update-grub
[ 2106.603394] device-mapper: core: CONFIG_IMA_DISABLE_HTABLE is disabled. Duplicate IMA measurements will not be recorded in the IMA log.
[ 2106.603428] device-mapper: uevent: version 1.0.3
[ 2106.603490] device-mapper: ioctl: 4.45.0-ioctl (2021-03-22) initialised: dm-devel@redhat.com
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.0.0-kali3-cloud-amd64
Found initrd image: /boot/initrd.img-6.0.0-kali3-cloud-amd64
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
done
Those warnings are expected.
Write better fstab
root@rescue:/# cat <<EOF > /etc/fstab
/dev/xvda1 / ext4 rw,discard,errors=remount-ro 0 1
/dev/xvda15 /boot/efi vfat defaults 0 0
EOF
Set hostname and nameservers
Adjust for your hostname.
root@rescue:/# cat <<EOF > /etc/hostname
debtest1
EOF
root@rescue:/# rm /etc/resolv.conf
root@rescue:/# cat <<EOF > /etc/resolv.conf
nameserver 85.119.80.232
nameserver 85.119.80.233
nameserver 2001:ba8:1f1:f205::53
nameserver 2001:ba8:1f1:f206::53
EOF
Append sensible networking config
Here assuming that your IPv4 address is 85.119.82.225 and your IPv6 prefix is 2001:ba8:1f1:f1d7::/64. That won't be the case for you of course; you can find the addresses specific to your VM in the DNS section of the Panel.
Note the >> used here to append this text to the end of the already-existing /etc/network/interfaces file. A single > would overwrite it.
root@rescue:/# cat <<EOF >> /etc/network/interfaces
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 85.119.82.225/21
gateway 85.119.80.1
iface eth0 inet6 static
address 2001:ba8:1f1:f1d7::2
netmask 64
gateway 2001:ba8:1f1:f1d7::1
# These commands disable IPv6 autoconfiguration because we are statically
# configuring it above.
pre-up echo 0 > /proc/sys/net/ipv6/conf/default/accept_ra || true
pre-up echo 0 > /proc/sys/net/ipv6/conf/all/accept_ra || true
pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra || true
pre-up echo 0 > /proc/sys/net/ipv6/conf/default/autoconf || true
pre-up echo 0 > /proc/sys/net/ipv6/conf/all/autoconf || true
pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf || true
EOF
Exit chroot and halt Rescue VM
root@rescue:/# exit
exit
root@rescue:/home/user# umount /mnt/dev
root@rescue:/home/user# umount /mnt/sys
root@rescue:/home/user# umount /mnt/proc
root@rescue:/home/user# umount /mnt
root@rescue:/home/user# halt
xen-shell>
Boot new Kali Linux VM
BitFolk's Grub should start, then parse the grub.cfg from within the VM, and then it should boot properly and directly to a root shell. No failures are expected so you should investigate anything that appears in red.
xen-shell> boot
[…]
Kali GNU/Linux Rolling debtest1 hvc0
debtest1 login: root (automatic login)
Linux debtest1 6.0.0-kali3-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.0.7-1kali1 (2022-11-07) x86_64
The programs included with the Kali GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Feb 1 21:05:21 UTC 2023 on tty1
┏━(Message from Kali developers)
┃
┃ This is a cloud installation of Kali Linux. Learn more about
┃ the specificities of the various cloud images:
┃ ⇒ https://www.kali.org/docs/troubleshooting/common-cloud-setup/
┃
┗━(Run: “touch ~/.hushlogin” to hide this message)
root@debtest1:~#
Disable autologin (optional)
If you don't want your console to be permanently logged in as root:
root@debtest1:~# rm -v /etc/systemd/system/getty@tty1.service.d/autologin.conf \
/etc/systemd/system/serial-getty@.service.d/autologin.conf
root@debtest1:~# passwd root
Create and enable swap
BitFolk provides an xvdb disk for use as swap. Create a partition across all of xvdb and set it up as swap.
root@debtest1:~# parted /dev/xvdb --script \
--align optimal \
mklabel gpt \
mkpart primary linux-swap 1 100% \
print
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdb: 1074MB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 1073MB 1072MB linux-swap(v1) primary swap
[ 683.675260] xvdb: xvdb1
root@debtest1:~# mkswap -L SWAP /dev/xvdb1
Setting up swapspace version 1, size = 1022 MiB (1071640576 bytes)
LABEL=SWAP, UUID=71f0c740-85f3-4fa3-8610-6620d6205c49
root@debtest1:# cat <<EOF >> /etc/fstab
LABEL=SWAP swap swap defaults 0 0
EOF
oot@debtest1:~# swapon -a
[ 5740.855588] Adding 1046524k swap on /dev/xvdb1. Priority:-2 extents:1 across:1046524k SS