trents_blog/site/posts/faster-partitioning-with-sg.../index.html

764 lines
24 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="shortcut icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.1.2, mkdocs-material-6.1.7">
<title>Faster Partitioning With sgdisk - Trent's Blog</title>
<link rel="stylesheet" href="../../assets/stylesheets/main.19753c6b.min.css">
<link rel="stylesheet" href="../../assets/stylesheets/palette.196e0c26.min.css">
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
<style>body,input{font-family:"Roboto",-apple-system,BlinkMacSystemFont,Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono",SFMono-Regular,Consolas,Menlo,monospace}</style>
<link rel="stylesheet" href="../../extra.css">
</head>
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent="">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#disclaimer" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header" data-md-component="header">
<nav class="md-header-nav md-grid" aria-label="Header">
<a href="../.." title="Trent&#39;s Blog" class="md-header-nav__button md-logo" aria-label="Trent's Blog">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 003-3 3 3 0 00-3-3 3 3 0 00-3 3 3 3 0 003 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg>
</a>
<label class="md-header-nav__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
</label>
<div class="md-header-nav__title" data-md-component="header-title">
<div class="md-header-nav__ellipsis">
<span class="md-header-nav__topic md-ellipsis">
Trent's Blog
</span>
<span class="md-header-nav__topic md-ellipsis">
Faster Partitioning With sgdisk
</span>
</div>
</div>
<label class="md-header-nav__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" data-md-state="active" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
</label>
<button type="reset" class="md-search__icon md-icon" aria-label="Clear" data-md-component="search-reset" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
</button>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<nav class="md-tabs md-tabs--active" aria-label="Tabs" data-md-component="tabs">
<div class="md-tabs__inner md-grid">
<ul class="md-tabs__list">
<li class="md-tabs__item">
<a href="../.." class="md-tabs__link md-tabs__link--active">
Home
</a>
</li>
<li class="md-tabs__item">
<a href="../../links/" class="md-tabs__link">
Links
</a>
</li>
</ul>
</div>
</nav>
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="../.." title="Trent&#39;s Blog" class="md-nav__button md-logo" aria-label="Trent's Blog">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 003-3 3 3 0 00-3-3 3 3 0 00-3 3 3 3 0 003 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg>
</a>
Trent's Blog
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle" data-md-toggle="nav-1" type="checkbox" id="nav-1" checked>
<label class="md-nav__link" for="nav-1">
Home
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" aria-label="Home" data-md-level="1">
<label class="md-nav__title" for="nav-1">
<span class="md-nav__icon md-icon"></span>
Home
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../.." class="md-nav__link">
Home
</a>
</li>
<li class="md-nav__item">
<a href="../rewrite-hugo-themes-report-in-python/" class="md-nav__link">
Rewrite Hugo Themes Report in Python
</a>
</li>
<li class="md-nav__item">
<a href="../lmde3-xfs-full-disk-encryption/" class="md-nav__link">
LMDE3 xfs Full Disk Encryption
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
Faster Partitioning With sgdisk
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
Faster Partitioning With sgdisk
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#disclaimer" class="md-nav__link">
Disclaimer
</a>
</li>
<li class="md-nav__item">
<a href="#command-line-is-faster" class="md-nav__link">
Command Line Is Faster
</a>
</li>
<li class="md-nav__item">
<a href="#gdisk-vs-sgdisk" class="md-nav__link">
gdisk vs sgdisk
</a>
</li>
<li class="md-nav__item">
<a href="#what-the-manpage-says" class="md-nav__link">
what the manpage says
</a>
</li>
<li class="md-nav__item">
<a href="#example-with-separate-efi-and-partitions" class="md-nav__link">
Example with Separate EFI and / Partitions
</a>
</li>
<li class="md-nav__item">
<a href="#practice-with-a-sparse-image" class="md-nav__link">
Practice With A Sparse Image
</a>
</li>
<li class="md-nav__item">
<a href="#example-with-separate-boot-efi-and-luks-encrypted-partitions" class="md-nav__link">
Example with Separate /boot, EFI, and luks-encrypted / Partitions
</a>
</li>
<li class="md-nav__item">
<a href="#what-about-swap" class="md-nav__link">
What About Swap?
</a>
</li>
<li class="md-nav__item">
<a href="#example-with-2gb-swap-partition" class="md-nav__link">
Example with 2GB swap partition
</a>
</li>
<li class="md-nav__item">
<a href="#conclusion" class="md-nav__link">
Conclusion
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../clear-linux-guest-virt-manager/" class="md-nav__link">
Clear Linux Guest Virt Manager
</a>
</li>
<li class="md-nav__item">
<a href="../clear-linux-encrypted-xfs-root/" class="md-nav__link">
Clear Linux Encrypted xfs Root
</a>
</li>
<li class="md-nav__item">
<a href="../simplified-raspberry-streaming/" class="md-nav__link">
Simplified Raspberry Streaming
</a>
</li>
<li class="md-nav__item">
<a href="../linux-move-cursor-with-keyboard/" class="md-nav__link">
Linux Move Cursor With Keyboard
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle" data-md-toggle="nav-2" type="checkbox" id="nav-2" >
<label class="md-nav__link" for="nav-2">
Links
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" aria-label="Links" data-md-level="1">
<label class="md-nav__title" for="nav-2">
<span class="md-nav__icon md-icon"></span>
Links
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../links/" class="md-nav__link">
Links
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#disclaimer" class="md-nav__link">
Disclaimer
</a>
</li>
<li class="md-nav__item">
<a href="#command-line-is-faster" class="md-nav__link">
Command Line Is Faster
</a>
</li>
<li class="md-nav__item">
<a href="#gdisk-vs-sgdisk" class="md-nav__link">
gdisk vs sgdisk
</a>
</li>
<li class="md-nav__item">
<a href="#what-the-manpage-says" class="md-nav__link">
what the manpage says
</a>
</li>
<li class="md-nav__item">
<a href="#example-with-separate-efi-and-partitions" class="md-nav__link">
Example with Separate EFI and / Partitions
</a>
</li>
<li class="md-nav__item">
<a href="#practice-with-a-sparse-image" class="md-nav__link">
Practice With A Sparse Image
</a>
</li>
<li class="md-nav__item">
<a href="#example-with-separate-boot-efi-and-luks-encrypted-partitions" class="md-nav__link">
Example with Separate /boot, EFI, and luks-encrypted / Partitions
</a>
</li>
<li class="md-nav__item">
<a href="#what-about-swap" class="md-nav__link">
What About Swap?
</a>
</li>
<li class="md-nav__item">
<a href="#example-with-2gb-swap-partition" class="md-nav__link">
Example with 2GB swap partition
</a>
</li>
<li class="md-nav__item">
<a href="#conclusion" class="md-nav__link">
Conclusion
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content">
<article class="md-content__inner md-typeset">
<h1>Faster Partitioning With sgdisk</h1>
<p>date: 2019-02-11T04:23:52-08:00</p>
<h2 id="disclaimer"><strong>Disclaimer</strong></h2>
<p>If any of this is wrong, let me know so I can fix it. No actual hard drives were harmed in the production of this blog post.</p>
<p>The examples are easier to read if you turn your smart phone sideways.</p>
<h2 id="command-line-is-faster"><strong>Command Line Is Faster</strong></h2>
<p>Sure you can partition your discs using a GUI disk management application or an interactive,
menu-driven terminal interface. But the command line is faster.</p>
<h2 id="gdisk-vs-sgdisk"><strong>gdisk vs sgdisk</strong></h2>
<p><code>sgdisk</code> is the scriptable version of <code>gdisk</code> (gptfdisk).</p>
<h2 id="what-the-manpage-says"><strong><a href="https://manpages.debian.org/stretch/gdisk/sgdisk.8.en.html" target="_blank">what the manpage says</a></strong></h2>
<p>If youre familiar with <code>gdisk</code>, you probably know how to interactively set the partition size and type.
If you look at the man page for <code>sgdisk</code> you see that the relevant flags are <code>-n</code> and <code>-t</code>. The beginning and ending numbers
are absolute, unless you prepend them with a <code>+</code> or <code>-</code> sign, in which case they become relative.
<div class="highlight"><pre><span></span><code><span class="gp">#</span> For New Partition:
<span class="go">-n, --new=partnum:start:end</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code><span class="gp">#</span> Change partition type:
<span class="go">-t, --typecode=partnum:{hexcode|GUID}</span>
</code></pre></div></p>
<h2 id="example-with-separate-efi-and-partitions"><strong>Example with Separate EFI and / Partitions</strong></h2>
<p>BTW, <code>gdisk</code> is a partitioning tool intended to be used with a gpt partition table, so the assumption is that you would want an efi partition,</p>
<p>(although the efi partition does not have to be on the disk you are partitioning or even on the same disk where your other system partitions are).</p>
<ol>
<li>Wipe any leftover filesystem metadata with wipefs.
<div class="highlight"><pre><span></span><code><span class="go">wipefs --all /dev/sdx</span>
</code></pre></div></li>
<li>Create a new GPT partition table.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -o</span>
</code></pre></div></li>
<li>Create an efi partition of 512MB by specifying the end of the partition (relative) and the partition type, <code>ef00</code>.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 1::+512MiB -t 1:ef00</span>
</code></pre></div></li>
<li>Create an <code>/</code> partition using the remainder of the disk, by not specifying the end or the beginning or partition type, which defaults to 8300.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 2</span>
</code></pre></div></li>
<li>Format the efi partition fat 32.
<div class="highlight"><pre><span></span><code><span class="go">mkfs.vfat -F32 /dev/sdx1</span>
</code></pre></div></li>
<li>Format the <code>/</code> partition ext4.
<div class="highlight"><pre><span></span><code><span class="go">mkfs.ext4 /dev/sdx2</span>
</code></pre></div></li>
</ol>
<h2 id="practice-with-a-sparse-image"><strong>Practice With A Sparse Image</strong></h2>
<p>If you dont want to partition a real hard drive, you can practice using an sparse image file, instead.
<div class="highlight"><pre><span></span><code><span class="gp">#</span> create a sparse image file
<span class="go">truncate -S 100G practiceImage.img</span>
<span class="gp">#</span> partition the image file with sgdisk
<span class="go">sgdisk practiceImage.img -o</span>
<span class="gp">#</span> etc
</code></pre></div></p>
<h2 id="example-with-separate-boot-efi-and-luks-encrypted-partitions"><strong>Example with Separate /boot, EFI, and luks-encrypted / Partitions</strong></h2>
<ol>
<li>Wipe any leftover filesystem metadata with <code>wipefs</code>.
<div class="highlight"><pre><span></span><code><span class="go">wipefs --all /dev/sdx</span>
</code></pre></div></li>
<li>Create a new GPT partition table.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -o</span>
</code></pre></div></li>
<li>Create an efi partition of 512MB by specifying the end of the partition (relative) and the partition type, <code>ef00</code>.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 1::+512MiB -t 1:ef00</span>
</code></pre></div></li>
<li>Create a <code>/boot</code> partition of 1GB, by specifying the end of the partition (relative), but not specifying the partition type which defaults to <code>8300</code>.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 2::+1GiB</span>
</code></pre></div></li>
<li>Create an <code>/</code> partition using the remainder of the disk, by not specifying the end or the beginning or partition type, which defaults to <code>8300</code>.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 3</span>
</code></pre></div></li>
<li>Format the efi partition fat 32.
<div class="highlight"><pre><span></span><code><span class="go">mkfs.vfat -F32 /dev/sdx1</span>
</code></pre></div></li>
<li>Format the <code>/boot</code> partition ext4.
<div class="highlight"><pre><span></span><code><span class="go">mkfs.ext4 /dev/sdx2</span>
</code></pre></div></li>
<li>Encrypt the <code>/</code> partition.
<div class="highlight"><pre><span></span><code><span class="go">cryptsetup -y -v luksFormat --type luks2 /dev/sdx3</span>
</code></pre></div></li>
<li>Decrypt the <code>/</code> device.
<div class="highlight"><pre><span></span><code><span class="go">cryptsetup open /dev/sdx3 cryptroot</span>
</code></pre></div></li>
<li>Format the <code>/</code> device.
<div class="highlight"><pre><span></span><code><span class="go">mkfs.xfs /dev/mapper/cryptroot</span>
</code></pre></div></li>
</ol>
<h2 id="what-about-swap"><strong>What About Swap?</strong></h2>
<p>I prefer to use a swap file inside the luks-encrypted / partition. But you can make a separate swap partition if you like.</p>
<h2 id="example-with-2gb-swap-partition"><strong>Example with 2GB swap partition</strong></h2>
<ol>
<li>Wipe the disc.
<div class="highlight"><pre><span></span><code><span class="go">wipefs --all /dev/sdx</span>
</code></pre></div></li>
<li>Create a new GPT partition table.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -o</span>
</code></pre></div></li>
<li>Create an EFI partition.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 1::+512MiB -t 1:ef00</span>
</code></pre></div></li>
<li>Create a <code>/boot</code> partition.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 2::+1GiB</span>
</code></pre></div></li>
<li>Create a <code>/</code> partition with a relative negative end.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 3::-2GiB</span>
</code></pre></div></li>
<li>Create a swap partion type <code>8200</code>.
<div class="highlight"><pre><span></span><code><span class="go">sgdisk /dev/sdx -n 4 -t 4:8200</span>
</code></pre></div></li>
<li>format the partitions.
<div class="highlight"><pre><span></span><code><span class="go">mkfs.vfat -F32 /dev/sdx1</span>
<span class="go">mkfs.ext4 /dev/sdx2</span>
<span class="go">mkfs.xfs /dev/sdx3</span>
<span class="go">mkswap /dev/sdx4</span>
</code></pre></div></li>
</ol>
<h2 id="conclusion"><strong>Conclusion</strong></h2>
<ul>
<li>Good luck to you.</li>
<li>Backup your data first.</li>
<li>Kind Regards, Trent</li>
</ul>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-nav">
<nav class="md-footer-nav__inner md-grid" aria-label="Footer">
<a href="../lmde3-xfs-full-disk-encryption/" class="md-footer-nav__link md-footer-nav__link--prev" rel="prev">
<div class="md-footer-nav__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
</div>
<div class="md-footer-nav__title">
<div class="md-ellipsis">
<span class="md-footer-nav__direction">
Previous
</span>
LMDE3 xfs Full Disk Encryption
</div>
</div>
</a>
<a href="../clear-linux-guest-virt-manager/" class="md-footer-nav__link md-footer-nav__link--next" rel="next">
<div class="md-footer-nav__title">
<div class="md-ellipsis">
<span class="md-footer-nav__direction">
Next
</span>
Clear Linux Guest Virt Manager
</div>
</div>
<div class="md-footer-nav__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg>
</div>
</a>
</nav>
</div>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-footer-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<script src="../../assets/javascripts/vendor.0ac82a11.min.js"></script>
<script src="../../assets/javascripts/bundle.f81dfb4d.min.js"></script><script id="__lang" type="application/json">{"clipboard.copy": "Copy to clipboard", "clipboard.copied": "Copied to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.term.missing": "Missing"}</script>
<script>
app = initialize({
base: "../..",
features: ['navigation.tabs'],
search: Object.assign({
worker: "../../assets/javascripts/worker/search.4ac00218.min.js"
}, typeof search !== "undefined" && search)
})
</script>
</body>
</html>