<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Harddisk on TokkNet</title><link>https://tokknet.eu/tags/harddisk/</link><description>Recent content in Harddisk on TokkNet</description><generator>Hugo</generator><language>de-DE</language><managingEditor>blog@tokknet.eu (Tokk)</managingEditor><webMaster>blog@tokknet.eu (Tokk)</webMaster><lastBuildDate>Tue, 04 Mar 2025 08:00:00 +0200</lastBuildDate><atom:link href="https://tokknet.eu/tags/harddisk/index.xml" rel="self" type="application/rss+xml"/><item><title>Festpatte unter Linux erweitern</title><link>https://tokknet.eu/2025/festpatte-unter-linux-erweitern/</link><pubDate>Tue, 04 Mar 2025 08:00:00 +0200</pubDate><author>blog@tokknet.eu (Tokk)</author><guid>https://tokknet.eu/2025/festpatte-unter-linux-erweitern/</guid><description>&lt;p>In diesem Artikel halte ich kurz fest, wie man die Festplatte eines Linux-Systems im laufenden Betrieb erweitert. Diese Anleitung bezeiht sich auch auf direkt formatierte Platten, eine Verwenung von LVM o.Ä. führt natürlich zu einem anderen Vorgehen, aber da es eh nur um virtuelle Systeme geht, gibt es ja keinen Grund eine weitere Abstraktionsschicht für die Platten einzuführen.&lt;br>
Zunächst muss der zur Verfügung stehende Speicher erweitert werden, das funktioniert natürlich nur bei virtuellen Systemen, eine physische Festplatte lässt sich leider nicht einfach aufblasen ;)&lt;br>
Eine weitere Einschränkung existiert noch: Das ganze funktioniert nur für die letzte Partition auf der Festplatte.&lt;/p>
&lt;p>Die folgende Anleitung bezieht sich auf die Platte &lt;code>sda&lt;/code>, bei Abweichender Platte muss das natürlich in allen Befehlen entsprechend angepasst werden.&lt;/p>
&lt;p>Wenn jetzt also mehr Platz zur Verfügung steht als verwendet wird, kann mittels &lt;code>echo 1&amp;gt;/sys/class/block/sda/device/rescan&lt;/code> ein Rescan der Platte angestoßen werden.&lt;br>
Aufgrund der Ausgabeumleitung funktioniert der Befehl &lt;a href="https://askubuntu.com/a/1466934">nicht mit vorangestelltem sudo&lt;/a>, daher entweder vorher zum User Root wechseln (&lt;code>sudo su&lt;/code>) oder eine der beiden Lösungen aus dem verlinkten Artikel verwenden und entweder die ganze Zeile in eine Subshell übergeben (&lt;code>sudo bash -c 'echo 1 &amp;gt; /sys/block/sda/device/rescan'&lt;/code>) oder die Umleitung mit &lt;code>tee&lt;/code> vornehmen (&lt;code>echo 1 | sudo tee /sys/block/sda/device/rescan &lt;/code>).&lt;/p>
&lt;p>Am Anschluss kann mittels &lt;code>fdisk -l /dev/sda &lt;/code> geprüft werden, ob die neue Größe erkannt wurde, die Ausgabe sollte eine Warnung sowie die korrekte neue Größe beinhalten.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>tokk@linux:~$sudo fdisk -l /dev/sda
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>GPT PMBR size mismatch &lt;span style="color:#f92672">(&lt;/span>&lt;span style="color:#ae81ff">33554431&lt;/span> !&lt;span style="color:#f92672">=&lt;/span> 41943039&lt;span style="color:#f92672">)&lt;/span> will be corrected by write.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>The backup GPT table is not on the end of the device.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Disk /dev/sda: &lt;span style="color:#ae81ff">20&lt;/span> GiB, &lt;span style="color:#ae81ff">21474836480&lt;/span> bytes, &lt;span style="color:#ae81ff">41943040&lt;/span> sectors
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Wenn das funktioniert hat mittels &lt;code>fdisk&lt;/code> die alte Partition gelöscht und eine neue angelegt werden:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>tokk@linux:~$sudo fdisk /dev/sda
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span>…&lt;span style="color:#f92672">]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Command &lt;span style="color:#f92672">(&lt;/span>m &lt;span style="color:#66d9ef">for&lt;/span> help&lt;span style="color:#f92672">)&lt;/span>: d
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Partition number &lt;span style="color:#f92672">(&lt;/span>1,2, default 2&lt;span style="color:#f92672">)&lt;/span>:↵
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Partition &lt;span style="color:#ae81ff">2&lt;/span> has been deleted.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Command &lt;span style="color:#f92672">(&lt;/span>m &lt;span style="color:#66d9ef">for&lt;/span> help&lt;span style="color:#f92672">)&lt;/span>: n 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Partition number &lt;span style="color:#f92672">(&lt;/span>2-128, default 2&lt;span style="color:#f92672">)&lt;/span>:↵
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>First sector &lt;span style="color:#f92672">(&lt;/span>4096-41943006, default 4096&lt;span style="color:#f92672">)&lt;/span>:↵
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Last sector, +/-sectors or +/-size&lt;span style="color:#f92672">{&lt;/span>K,M,G,T,P&lt;span style="color:#f92672">}&lt;/span> &lt;span style="color:#f92672">(&lt;/span>4096-41943006, default 41943006&lt;span style="color:#f92672">)&lt;/span>:↵ 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Created a new partition &lt;span style="color:#ae81ff">2&lt;/span> of type &lt;span style="color:#e6db74">&amp;#39;Linux filesystem&amp;#39;&lt;/span> and of size &lt;span style="color:#ae81ff">20&lt;/span> GiB. 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Partition &lt;span style="color:#75715e">#2 contains a ext4 signature.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Do you want to remove the signature? &lt;span style="color:#f92672">[&lt;/span>Y&lt;span style="color:#f92672">]&lt;/span>es/&lt;span style="color:#f92672">[&lt;/span>N&lt;span style="color:#f92672">]&lt;/span>o: N 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Command &lt;span style="color:#f92672">(&lt;/span>m &lt;span style="color:#66d9ef">for&lt;/span> help&lt;span style="color:#f92672">)&lt;/span>: w
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>The partition table has been altered. 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Syncing disks.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Der erste Sektor der neuen Partition muss hierbei identisch zum ersten Sektor der gerade gelöschten Partition sein, der letzte Sektor muss größer oder mindestens gleich dem der alten Partition sein. Wenn man keinen Wert eingibt wählt &lt;code>fdisk&lt;/code> automatisch den letzten nutzbaren Sektor aus und vergrößert die Partition somit auf den maximalen zur Verfügung stehenden Platz.&lt;br>
Sehr wichtig ist es, die Frage nach dem Löschen der bestehenden Dateisystem-Signatur zu verneinen!&lt;/p>
&lt;p>Abschließend muss das Dateisystem der Platte noch auf die neue Größe der Partition eingestellt werden:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>tokk@linux:~$sudo resize2fs /dev/sda2 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resize2fs 1.46.5 &lt;span style="color:#f92672">(&lt;/span>30-Dec-2021&lt;span style="color:#f92672">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Filesystem at /dev/sda2 is mounted on /; on-line resizing required
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>old_desc_blocks &lt;span style="color:#f92672">=&lt;/span> 2, new_desc_blocks &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">3&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>The filesystem on /dev/sda2 is now &lt;span style="color:#ae81ff">5242363&lt;/span> &lt;span style="color:#f92672">(&lt;/span>4k&lt;span style="color:#f92672">)&lt;/span> blocks long.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Der Festplattenplatz steht jetzt zur Verfügung und kann verwendet werden.&lt;br>
Vorher:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>tokk@linux:~$df -h 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Filesystem Size Used Avail Use% Mounted on
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>/dev/sda2 16G 8,1G 6,9G 54% /
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Nachher:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>tokk@linux:~$df -h 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Filesystem Size Used Avail Use% Mounted on
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>/dev/sda2 20G 8,1G 11G 44% /
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="tldr">tl;dr&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo su
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>echo 1&amp;gt;/sys/class/block/sda/device/rescan
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>fdisk /dev/sda
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Command &lt;span style="color:#f92672">(&lt;/span>m &lt;span style="color:#66d9ef">for&lt;/span> help&lt;span style="color:#f92672">)&lt;/span>: d
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Partition number &lt;span style="color:#f92672">(&lt;/span>1,2, default 2&lt;span style="color:#f92672">)&lt;/span>:↵
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Command &lt;span style="color:#f92672">(&lt;/span>m &lt;span style="color:#66d9ef">for&lt;/span> help&lt;span style="color:#f92672">)&lt;/span>: n
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Partition number &lt;span style="color:#f92672">(&lt;/span>2-128, default 2&lt;span style="color:#f92672">)&lt;/span>:↵
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>First sector &lt;span style="color:#f92672">(&lt;/span>4096-41943006, default 4096&lt;span style="color:#f92672">)&lt;/span>:↵
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Last sector, +/-sectors or +/-size&lt;span style="color:#f92672">{&lt;/span>K,M,G,T,P&lt;span style="color:#f92672">}&lt;/span> &lt;span style="color:#f92672">(&lt;/span>4096-41943006, default 41943006&lt;span style="color:#f92672">)&lt;/span>:↵ 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Do you want to remove the signature? &lt;span style="color:#f92672">[&lt;/span>Y&lt;span style="color:#f92672">]&lt;/span>es/&lt;span style="color:#f92672">[&lt;/span>N&lt;span style="color:#f92672">]&lt;/span>o: N 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Command &lt;span style="color:#f92672">(&lt;/span>m &lt;span style="color:#66d9ef">for&lt;/span> help&lt;span style="color:#f92672">)&lt;/span>: w
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resize2fs /dev/sda2 
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="warning">
 &lt;h3>&lt;i class="fa-sharp fa-thin fa-triangle-exclamation">&lt;/i> Obligatorische Warnung&lt;/h3>
 &lt;p>Dass die hier aufgeführten Befehle zu Datenverlust führen können, erwähne ich hier nur der Vollständigkeit halber, da es eigentlich klar sein sollte&lt;/p>
&lt;/div></description></item></channel></rss>