[Google Pixel 2 Guides, News, & Discussion] nathanchance:
Introduction

Hello everyone, this is a guide to assist you with customizing your Pixel 2! I will be going over installing fastboot and adb, unlocking your bootloader, how to flash the factory images for clean flashes and upgrades, and how to root. Please feel free to ask any questions if you need clarification. Enjoy!

This information has been distilled from Google's official factory image site and the Magisk thread.

Installing fastboot and adb

Thankfully, Google has provided just adb, fastboot, and systrace as a simple zip file, making this process super easy. You MUST be on at LEAST 26.0.2 for the commands in this guide to work. When in doubt, grab the latest copy and install them using the following instructions.

SDK Platform-Tools for Windows

SDK Platform-Tools for Mac

SDK Platform-Tools for Linux

Windows:

Unzip the folder somewhere on your hard drive.

Go to the folder containing the adb and fastboot files and type "cmd" in the path bar at the top.

A command prompt should open with the current folder showing on the prompt.

Type the following commands:

adb --version
fastboot --version

You should see some information appear. If that is the case, you were successful!

Mac/Linux:

Unzip the folder somewhere on your hard drive.

Navigate to that folder with your terminal.

Run the following commands:

sudo install adb dmtracedump e2fsdroid etc1tool fastboot hprof-conv make_f2fs mke2fs mke2fs.conf sload_f2fs sqlite3 /usr/local/bin
sudo mkdir -p /usr/local/lib64
sudo install lib64/libc++.so /usr/local/lib64

Type the following commands:

adb --version
fastboot --version

You should see the version information, along with telling you they are installed to /usr/local/bin. If so, you were successful!

Unlocking the bootloader

WARNING:

This WILL wipe your entire phone. Please make copies or backups of any important data. This can also go wrong rendering your device inoperable. Proceed with caution.

On your phone, open Settings, navigate to "System" then "About phone", and tap on the build number 7 times.

Go one menu up, click on "Developer options", and turn on USB debugging and OEM unlocking.

In your terminal, type the following command:

adb reboot bootloader

Run the following command:

fastboot flashing unlock

Follow the prompts on your device then reboot!

Flashing factory images

NOTE #1:

You CANNOT downgrade factory images. Google has prevented users from doing so to keep them safe from vulernabilities that were patched. You should only upgrade or reinstall the current image.

NOTE #2:

If you have mounted /system as rw at any point (like in TWRP), you must upgrade using the factory image method. OTAs will fail because they cannot verify the integrity of the disk since its verity data has been changed.

NOTE #3:

Flashing the factory images requires an unlocked bootloader. Flashing the OTA zips does not (but if anything goes wrong, you may not be able to recover without an RMA).

Updating to a new release (factory image):

Download the latest factory image from Google's website.

Reboot into the bootloader:

adb reboot bootloader

Unzip the factory image.

Inside you will see a bootloader image, a radio image, an image zip file, and a couple of flash scripts.

If you are on Windows, open the "flash-all.bat" file in a text editor. If you are on Mac or Linux, open the "flash-all.sh" instead.

Remove the "-w" flag before the fastboot command towards the end of the file. This will prevent fastboot from formatting your device.

Run the flash all script! Open a command prompt, navigate to the folder with the script, and run one of the following commands:

Windows:

flash-all

Mac/Linux:

./flash-all.sh

Reboot once it is finished!

Updating to a new release (OTA zip):

Download the latest OTA zip from Google's website

Reboot into recovery:

adb reboot recovery

Hold down the power button and push volume up

Select "Apply update from ADB"

Run the following command from the folder containing the OTA zip:

adb sideload <zip_name>.zip

Reboot once it is finished!

Clean flashing a factory image (wipe everything):

Download the latest factory image from Google's website

Reboot into the bootloader:

adb reboot bootloader

Unzip the factory image.

Run the flash all script! Open a command prompt, navigate to the folder with the script, and run one of the following commands:

Windows:

flash-all

Mac/Linux:

./flash-all.sh

Reboot once it is finished!

Rooting with Magisk

NOTE #4:

This section assumes you are not going to install TWRP. If you are, skip to the next section and just flash the latest Magisk zip after installing TWRP.

Download the Magisk zip from the official thread and install the manager from the zip.

Grab a boot image to patch (either the one from the latest factory image or a custom kernel one) and push it to your device:

adb push <path_to_file> /sdcard/Download

Open Magisk Manager and click the Install button.

Click "Install" at the first prompt then choose "Patch Boot Image File". A file manager will pop up.

Select the boot image you want to patch and let Magisk Manager patch it.

Pull it off your device:

adb pull /sdcard/MagiskManager/patched_boot.img

Reboot into the bootloader:

adb reboot bootloader

Flash the boot image and reboot.

fastboot flash boot patched_boot.img
fastboot reboot

Open Magisk Manager and you should be rooted!

Installing TWRP

NOTE #5:

If you just want to temporarily boot TWRP to flash Magisk and your custom kernel, you can just skip flashing the installer zip in this process.

NOTE #6:

TWRP can be unstable at times given the way that security has been set up on this device (lack of decryption, failing to boot, etc).

Download both the TWRP image and zip installer from the official site.

Temporarily boot the TWRP image.

fastboot boot <path_to_twrp_image>

Flash the TWRP installer zip.

Reinstall Magisk and your custom kernel if you had them.

Reboot and profit!

Common issues

Outdated fastboot/adb: This device requires the latest fastboot and adb binaries to work properly. A lot of common quick adb/fastboot installation guides link to installers that are old. Please manually install the latest using the information at the beginning of the thread!

Using a USB-3.0 or USB-C port: Some newer USB ports do not work with fastboot. Issues manifest as weird errors during a flash. Use a different USB cable/port.

Closing statements

If there are any procedures you would like to see added (like flashing a custom kernel or booting TWRP), I am happy to add them if requested. Also, when requesting help, please be as specific as possible where you get confused. I want this guide to be clear as possible.