Linux virtual machine setup
Create a linux VM on windows 10 using hyper-v
- Create vhdx file :
- 1MB BlockSizeBytes (from the default 32MB)
- ext4 is more space efficient than ext3 when used with dynamic VHDX files
- when creating the filesystem specify the number of groups to be 4096, for example :
mkfs.ext4 -G 4096 /dev/sdX1
New-VHD -Path C:\Users\Public\Documents\Hyper-V\Virtual hard disks\localDebian.vhdx" -SizeBytes 127GB -Dynamic -BlockSizeBytes 1MB
- Set virtual machine options :
- name :
local-debian
- generation 2
- ram : 4096 Mo static
- networking : use localSwitch
- hard disk :
C:\Users\Public\Documents\Hyper-V\Virtual hard disks\local-debian.vhdx, 127GB
- options :
- disable secure boot
- disable checkpoints
- set 1 virtual processor
- do nothing at host startup
- save VM state at host shutdown
- name :
-
ISO install :
debian-10.4.0-amd64-netinst.iso
-
Machine settings :
- language : english
- location : france
- locales :
en_US.UTF-8
- keymap : french
- hostname :
local-debian
- domain name : n/a
- root password : n/a
- default user full name : Local Debian Admin
- default user username : administrator
- default user password : password
- guided partitioning, use entire disk, all files in one partition :
- Write partition tables for the following devices :
SCSI1 (0,0,0) (sda) - 136.4 GB Msft Virtual Disk
- Format following partitions :
PARTITION SIZE TYPE MOUNT POINT 1.0 MB FREE SPACE 1 536.9 MB B f ESP /boot/efi 2 131.5 GB f ext4 / 3 4.3 GB f swap swap (not mounted) 1.0 MB FREE SPACE
- apt config : france, deb.debian.org, no proxy, dpkg-reconfigure popularity-contest : yes
- additional software : SSH server, standard system utilities
-
Common packages :
curl nmap net-tools tmux vim vim-common vim-runtime tree bash-completion man-db jq lsb-release sysstat iftop iotop procps unzip gnupg2 psmisc cowsay cowsay-off display-dhammapada time gmemusageapt-rdepends
- Optional packages :
shellcheck ffmpeg apt-transport-https ca-certificates gnupg-agent software-properties-common busybox salt-minion python3-setuptools
- user full name : Fredy FUMIER
- user username : fredyfumier
- user username : password
# copy SSH public key to remote SSH server :
ssh-copy-id -i ~/.ssh/id_rsa.pub fredyfumier@192.168.1.18
# copy file to remote SSH server :
scp ~/test.txt fredyfumier@192.168.1.18:/home/fredyfumier/test.txt.copied
-
Setup a new device :
New-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\external.vhdx" -SizeBytes 5GB -Dynamic -BlockSizeBytes 1MB
- the new device will be recognized as /dev/sdb at startup :
sudo less /var/log/kern.log
- the new device will be recognized as /dev/sdb at startup :
-
Partition a new device :
-
sudo fdisk /dev/sdb
: F (list unpartitioned space)
Unpartitioned space /dev/sdb: 5 GiB, 5367660544 bytes, 10483712 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes Start End Sectors Size 2048 10485759 10483712 5G
-
sudo fdisk /dev/sdb
: g (create a new empty GPT partition table) -
sudo fdisk /dev/sdb
: n (add a new partition) -
sudo fdisk /dev/sdb
: n (add a new partition)- label: gpt
- label-id: B381E8D3-E992-7640-BC15-73FDBE2FC82C
- device: /dev/sdb
- unit: sectors
- first-lba: 2048
- last-lba: 10485726
PARTITION FIRST SECTOR SIZE TYPE UUID (Linux filesystem) UUID /dev/sdb1 : start= 2048, size= 5240816, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=72B193C1-07F7-BC47-9F47-BB2D900825DE /dev/sdb2 : start= 5242880, size= 5242847, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=F888B7B6-8588-1E4D-A0EA-36E466BF2D48
-
-
Create ext4 file systems for the new partitions :
sudo mkfs.ext4 -cv -E root_owner=0:0 -U random /dev/sdb1
sudo mkfs.ext4 -cv -E root_owner=0:0 -U random /dev/sdb2
-
root
owns the new file systems root directories
-
Mount new filesystems at specific mount points in host file hierarchy (!!! USE LOWER CASE FILESYSTEM UUIDS !!!) :
sudo mount -vt ext4 -U 3b042371-27f8-4b08-96cd-ec2995df0cf6 /external/disk1
sudo mount -vt ext4 -U 5f7ee3e9-0d03-4fd4-93fb-8646c873a007 /external/disk2
- USE LOWER CASE FILESYSTEM UUIDS !
-
Unmount file systems :
sudo umount /external/disk1
sudo umount /external/disk2