Stay organized with collections
Save and categorize content based on your preferences.
Linux
In some situations, your applications might require you to build your own
operating system or compile a custom kernel. If you compile custom kernels or
create custom operating systems for your VMs, ensure that they meet the
requirements in this document.
You must build the operating system kernel with the following options:
CONFIG_KVM_GUEST=y
Enable paravirtualization functionality.
CONFIG_KVM_CLOCK=y
Enable the paravirtualized clock (if applies to your kernel version).
CONFIG_VIRTIO_PCI=y
Enable paravirtualized PCI devices.
CONFIG_SCSI_VIRTIO=y
Enable access to paravirtualized disks.
CONFIG_VIRTIO_NET=y
Enable access to networking.
CONFIG_PCI_MSI=y
Enable high-performance interrupt delivery, which is required for local
SSD devices.
Kernel build options for security
Use the recommended security settings in your kernel build options:
CONFIG_STRICT_DEVMEM=y
Restrict /dev/mem to allow access to only PCI space, BIOS code, and
data regions.
CONFIG_DEVKMEM=n
Disable support for /dev/kmem.
Block access to kernel memory.
CONFIG_DEFAULT_MMAP_MIN_ADDR=65536
Set low virtual memory that is protected from userspace allocation.
CONFIG_DEBUG_RODATA=y
Mark the kernel read-only data as write-protected in the pagetables,
to catch accidental (and incorrect) writes to such const data. This
option can have a slight performance impact because a portion of the kernel
code won't be covered by a 2 MB TLB anymore.
CONFIG_DEBUG_SET_MODULE_RONX=y
Catches unintended modifications to loadable kernel module's text and
read-only data. This option also prevents execution of module data.
CONFIG_CC_STACKPROTECTOR=y
Enables the -fstack-protector GCC feature. This feature puts a canary
value at the beginning of critical functions, on the stack before
the return address, and validates the value before actually
returning. This also causes stack-based buffer overflows (that need to
overwrite this return address) to overwrite the canary, which gets
detected and the attack is then neutralized using a kernel panic.
CONFIG_COMPAT_VDSO=n
Ensures the VDSO isn't at a predictable address to strengthen ASLR. If
enabled, this feature maps the VDSO to the predictable old-style
address, providing a predictable location for exploit code to jump to.
Say N here if you are running a sufficiently recent glibc version
(2.3.3 or later), to remove the high-mapped VDSO mapping and to
exclusively use the randomized VDSO.
CONFIG_COMPAT_BRK=n
Don't disable heap randomization.
CONFIG_X86_PAE=y
Set this option for a 32-bit kernel because PAE is required for NX support.
This also enables larger swapspace support for non-overcommit purposes.
CONFIG_SYN_COOKIES=y
Provides some protection against SYN flooding.
CONFIG_SECURITY_YAMA=y
This selects Yama, which extends DAC support with additional system-wide
security settings beyond regular Linux discretionary access controls.
Currently, the setting is ptrace scope restriction.
CONFIG_SECURITY_YAMA_STACKED=y
This option forces Yama to stack with the selected primary LSM when Yama
is available.
Kernel security settings
You can also harden the security of the kernel through the kernel settings
file. Edit the /etc/sysctl.conf file to include the following recommended
security settings:
Install the operating system to a boot disk and
manually import the image to
Compute Engine as a custom image.
If you have already imported your operating system as a custom image,
configure non-kernel settings
on the image so that it can functional optimally within the
Compute Engine environment.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[[["\u003cp\u003eBuilding custom operating systems or compiling custom kernels is an advanced task mainly for applications with specific kernel requirements, with most users able to use public images or import existing ones.\u003c/p\u003e\n"],["\u003cp\u003eCustom kernels must support specific hardware devices including PCI Bridge, ISA bridge, Virtio-Net or gVNIC Ethernet controller, Virtio-SCSI storage controller (or NVMe for newer machine series), and four 16550A serial ports.\u003c/p\u003e\n"],["\u003cp\u003eRequired Linux kernel build options include enabling paravirtualization, PCI devices, disks, and networking, as well as enabling high-performance interrupt delivery, which is needed for local SSD devices.\u003c/p\u003e\n"],["\u003cp\u003eRecommended kernel security settings involve restricting \u003ccode\u003e/dev/mem\u003c/code\u003e, disabling \u003ccode\u003e/dev/kmem\u003c/code\u003e, setting low virtual memory protection, using read-only protection for kernel data, enabling stack protection, and randomizing memory addresses.\u003c/p\u003e\n"],["\u003cp\u003eKernel security can also be hardened by editing \u003ccode\u003e/etc/sysctl.conf\u003c/code\u003e to include settings for syn flood protection, ignoring source-routed packets and ICMP redirects, preventing traffic routing, enabling reverse path filtering, and randomizing addresses.\u003c/p\u003e\n"]]],[],null,["Linux\n\n*** ** * ** ***\n\nIn some situations, your applications might require you to build your own\noperating system or compile a custom kernel. If you compile custom kernels or\ncreate custom operating systems for your VMs, ensure that they meet the\nrequirements in this document.\n\n[Building a custom operating system](/compute/docs/images/create-custom) is an\nadvanced task for users with applications that specifically require a custom\nkernel. Most users can create VMs from one of the available\n[public images](/compute/docs/images#os-compute-support), use the automated\n[virtual disk import tool](/compute/docs/import/importing-virtual-disks) to\nimport disks into Compute Engine from other environments, or\n[manually import a custom image](/compute/docs/import/import-existing-image)\nfrom a system with a common stock Linux distribution.\n\nHardware support requirements\n\nYour kernel must support the following devices:\n\n- PCI Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)\n- ISA bridge: Intel 82371AB/EB/MB PIIX4 ISA (rev 03)\n- Ethernet controller:\n\n - Virtio-Net Ethernet Adapter.\n - gVNIC is required for second generation\n [Tau T2A](/compute/docs/general-purpose-machines#t2a_machines),\n and all third generation and later machine series.\n\n Additionally, gVNIC is required or recommended if you use GPUs on any of\n the following:\n - General-purpose N1 machine types\n - Accelerator-optimized [A4](/compute/docs/accelerator-optimized-machines#a4-vms), [A3](/compute/docs/accelerator-optimized-machines#a3-vms), [A2](/compute/docs/accelerator-optimized-machines#a2-vms), or [G2](/compute/docs/accelerator-optimized-machines#g2-vms) machine types\n - vendor = 0x1AF4 (Qumranet/Red Hat)\n\n - device id = 0x1000. Subsystem ID 0x1\n\n - Checksum offload is supported\n\n - TSO v4 is supported\n\n - GRO v4 is supported\n\n- SCSI Storage Controller:\n\n - Virtio-SCSI Storage Controller\n - vendor = 0x1AF4 (Qumranet/Red Hat)\n - device id = 0x1004. Subsystem ID 0x8.\n - SCSI Primary Commands 4 and SCSI Block Commands 3 are supported\n - Only one request queue is supported\n - Persistent disks report 4 KiB physical sectors / 512 byte logical sectors\n - Only block devices (disks) are supported\n - The Hotplug / Events feature bit is supported\n\n| **Note:** For second generation Tau T2A and G2, and all third generation and later machine series, you must use an NVMe storage controller instead.\n\n- Serial Ports:\n - Four 16550A ports\n - ttyS0 on IRQ 4\n - ttyS1 on IRQ 3\n - ttyS2 on IRQ 6\n - ttyS3 on IRQ 7\n\nRequired Linux kernel build options\n\nYou must build the operating system kernel with the following options:\n\n- `CONFIG_KVM_GUEST=y`\n - Enable paravirtualization functionality.\n- `CONFIG_KVM_CLOCK=y`\n - Enable the paravirtualized clock (if applies to your kernel version).\n- `CONFIG_VIRTIO_PCI=y`\n - Enable paravirtualized PCI devices.\n- `CONFIG_SCSI_VIRTIO=y`\n - Enable access to paravirtualized disks.\n- `CONFIG_VIRTIO_NET=y`\n - Enable access to networking.\n- `CONFIG_PCI_MSI=y`\n - Enable high-performance interrupt delivery, which is required for local SSD devices.\n\nKernel build options for security\n\nUse the recommended security settings in your kernel build options:\n\n- `CONFIG_STRICT_DEVMEM=y`\n - Restrict `/dev/mem` to allow access to only PCI space, BIOS code, and data regions.\n- `CONFIG_DEVKMEM=n`\n - Disable support for `/dev/kmem`.\n - Block access to kernel memory.\n- `CONFIG_DEFAULT_MMAP_MIN_ADDR=65536`\n - Set low virtual memory that is protected from userspace allocation.\n- `CONFIG_DEBUG_RODATA=y`\n - Mark the kernel read-only data as write-protected in the pagetables, to catch accidental (and incorrect) writes to such `const` data. This option can have a slight performance impact because a portion of the kernel code won't be covered by a 2 MB TLB anymore.\n- `CONFIG_DEBUG_SET_MODULE_RONX=y`\n - Catches unintended modifications to loadable kernel module's text and read-only data. This option also prevents execution of module data.\n- `CONFIG_CC_STACKPROTECTOR=y`\n - Enables the `-fstack-protector` GCC feature. This feature puts a canary value at the beginning of critical functions, on the stack before the return address, and validates the value before actually returning. This also causes stack-based buffer overflows (that need to overwrite this return address) to overwrite the canary, which gets detected and the attack is then neutralized using a kernel panic.\n- `CONFIG_COMPAT_VDSO=n`\n - Ensures the VDSO isn't at a predictable address to strengthen ASLR. If enabled, this feature maps the VDSO to the predictable old-style address, providing a predictable location for exploit code to jump to. Say `N` here if you are running a sufficiently recent `glibc` version (2.3.3 or later), to remove the high-mapped VDSO mapping and to exclusively use the randomized VDSO.\n- `CONFIG_COMPAT_BRK=n`\n - Don't disable heap randomization.\n- `CONFIG_X86_PAE=y`\n - Set this option for a 32-bit kernel because PAE is required for NX support. This also enables larger swapspace support for non-overcommit purposes.\n- `CONFIG_SYN_COOKIES=y`\n - Provides some protection against SYN flooding.\n- `CONFIG_SECURITY_YAMA=y`\n - This selects Yama, which extends DAC support with additional system-wide security settings beyond regular Linux discretionary access controls. Currently, the setting is ptrace scope restriction.\n- `CONFIG_SECURITY_YAMA_STACKED=y`\n - This option forces Yama to stack with the selected primary LSM when Yama is available.\n\nKernel security settings\n\nYou can also harden the security of the kernel through the kernel settings\nfile. Edit the `/etc/sysctl.conf` file to include the following recommended\nsecurity settings: \n\n # Enable syn flood protection\n net.ipv4.tcp_syncookies = 1\n\n # Ignore source-routed packets\n net.ipv4.conf.all.accept_source_route = 0\n\n # Ignore source-routed packets\n net.ipv4.conf.default.accept_source_route = 0\n\n # Ignore ICMP redirects\n net.ipv4.conf.all.accept_redirects = 0\n\n # Ignore ICMP redirects\n net.ipv4.conf.default.accept_redirects = 0\n\n # Ignore ICMP redirects from non-GW hosts\n net.ipv4.conf.all.secure_redirects = 1\n\n # Ignore ICMP redirects from non-GW hosts\n net.ipv4.conf.default.secure_redirects = 1\n\n # Don't allow traffic between networks or act as a router\n net.ipv4.ip_forward = 0\n\n # Don't allow traffic between networks or act as a router\n net.ipv4.conf.all.send_redirects = 0\n\n # Don't allow traffic between networks or act as a router\n net.ipv4.conf.default.send_redirects = 0\n\n # Reverse path filtering—IP spoofing protection\n net.ipv4.conf.all.rp_filter = 1\n\n # Reverse path filtering—IP spoofing protection\n net.ipv4.conf.default.rp_filter = 1\n\n # Ignore ICMP broadcasts to avoid participating in Smurf attacks\n net.ipv4.icmp_echo_ignore_broadcasts = 1\n\n # Ignore bad ICMP errors\n net.ipv4.icmp_ignore_bogus_error_responses = 1\n\n # Log spoofed, source-routed, and redirect packets\n net.ipv4.conf.all.log_martians = 1\n\n # Log spoofed, source-routed, and redirect packets\n net.ipv4.conf.default.log_martians = 1\n\n # Randomize addresses of mmap base, heap, stack and VDSO page\n kernel.randomize_va_space = 2\n\n # Provide protection from ToCToU races\n fs.protected_hardlinks=1\n\n # Provide protection from ToCToU races\n fs.protected_symlinks=1\n\n # Make locating kernel addresses more difficult\n kernel.kptr_restrict=1\n\n # Set ptrace protections\n kernel.yama.ptrace_scope=1\n\n # Set perf only available to root\n kernel.perf_event_paranoid=2\n\nWhat's next\n\n- Install the operating system to a boot disk and [manually import the image](/compute/docs/import/import-existing-image) to Compute Engine as a custom image.\n- If you have already imported your operating system as a custom image, [configure non-kernel settings](/compute/docs/import/configuring-imported-images) on the image so that it can functional optimally within the Compute Engine environment."]]