<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ubuntu 彙整 - 泰克哪裡去</title>
	<atom:link href="https://tech.uccu.website/tag/ubuntu/feed" rel="self" type="application/rss+xml" />
	<link>https://tech.uccu.website/tag/ubuntu</link>
	<description>一個科技相關的隨手記錄網站</description>
	<lastBuildDate>Wed, 11 Nov 2020 10:16:57 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
<site xmlns="com-wordpress:feed-additions:1">119574712</site>	<item>
		<title>Linux(Ubuntu)磁碟分割</title>
		<link>https://tech.uccu.website/linux-format-disk.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linux-format-disk</link>
					<comments>https://tech.uccu.website/linux-format-disk.html#respond</comments>
		
		<dc:creator><![CDATA[鳴人]]></dc:creator>
		<pubDate>Wed, 11 Nov 2020 10:16:52 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://tech.uccu.website/?p=136</guid>

					<description><![CDATA[<p>在雲端上建立的Linux VM預設的空間都不大，或是有些其它需求另外增加一個資料磁碟的情況，做了幾次新增磁碟之 ... <a title="Linux(Ubuntu)磁碟分割" class="read-more" href="https://tech.uccu.website/linux-format-disk.html" aria-label="Read more about Linux(Ubuntu)磁碟分割">閱讀全文</a></p>
<p>這篇文章 <a href="https://tech.uccu.website/linux-format-disk.html">Linux(Ubuntu)磁碟分割</a> 最早出現於 <a href="https://tech.uccu.website">泰克哪裡去</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>在雲端上建立的Linux VM預設的空間都不大，或是有些其它需求另外增加一個資料磁碟的情況，做了幾次新增磁碟之後的磁碟分割、格式化等動作，但是因為脫離GUI的環境要記下龐大的Linux指令是很困難的(年紀大了)，所以趁這次又要做一次的時候趕快把過程記錄下來。</p>



<p>一開始可以使用「sudo fdisk -l」的方式來列出目前系統中的磁碟(Disk)，看看有哪些磁碟(Disk)與分割區(Partition)。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="511" height="485" src="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/0d3c8939-image.png?resize=511%2C485&#038;ssl=1" alt="" class="wp-image-137" srcset="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/0d3c8939-image.png?w=511&amp;ssl=1 511w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/0d3c8939-image.png?resize=300%2C285&amp;ssl=1 300w" sizes="(max-width: 511px) 100vw, 511px" /><figcaption>系統中的磁碟資訊</figcaption></figure></div>



<p>從上圖看到系統中有三個不同的Disk，而我新增加的是最下面的/dev/sdc 250G大小的Disk，它就是我要下手的目標。</p>



<p>接下來輸入「sudo fdisk /dev/sdc」(後面沒數字)，執行fdisk進入操作模式。</p>



<p>一開始會出現上半部的訊息，如果常操作fdisk工具記得各種選項是做什麼用的，可以直接輸入選項的代號，不然可以輸入m來查看(如下半部)：</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img data-recalc-dims="1" decoding="async" width="551" height="719" src="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/ea018de3-image.png?resize=551%2C719&#038;ssl=1" alt="" class="wp-image-138" srcset="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/ea018de3-image.png?w=551&amp;ssl=1 551w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/ea018de3-image.png?resize=230%2C300&amp;ssl=1 230w" sizes="(max-width: 551px) 100vw, 551px" /><figcaption>fdisk選項</figcaption></figure></div>



<p>因為是一個新的完全空白的磁碟，所以選擇n來建立新的Partition，接下來會詢問是要建立主要分割區還是延伸分割區、分割區號碼、開始與結束磁區位置(就是要割多大)等，如果是使用預設值的話也可以直接按Enter不用輸入。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img data-recalc-dims="1" decoding="async" width="629" height="157" src="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/ce748140-image.png?resize=629%2C157&#038;ssl=1" alt="" class="wp-image-140" srcset="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/ce748140-image.png?w=629&amp;ssl=1 629w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/ce748140-image.png?resize=300%2C75&amp;ssl=1 300w" sizes="(max-width: 629px) 100vw, 629px" /><figcaption>建立一個新的分割區</figcaption></figure></div>



<p>完成上面的步驟之後，這些改變只是暫時存在記憶體，再輸入w選項，將變更寫入磁碟之後離開。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="352" height="68" src="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/a6f5c402-image.png?resize=352%2C68&#038;ssl=1" alt="" class="wp-image-143" srcset="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/a6f5c402-image.png?w=352&amp;ssl=1 352w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/a6f5c402-image.png?resize=300%2C58&amp;ssl=1 300w" sizes="auto, (max-width: 352px) 100vw, 352px" /><figcaption>將fdisk的變更寫入磁碟後離開</figcaption></figure></div>



<p>再輸入一次「sudo fdisk -l」指令重新查看列表，發現最下面多了/dev/sdc1的項目，這就是剛才分割的Parition了。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="511" height="561" src="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/23d11dae-image.png?resize=511%2C561&#038;ssl=1" alt="" class="wp-image-145" srcset="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/23d11dae-image.png?w=511&amp;ssl=1 511w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/23d11dae-image.png?resize=273%2C300&amp;ssl=1 273w" sizes="auto, (max-width: 511px) 100vw, 511px" /></figure></div>



<p>fdisk是用來做磁碟分割使用，分割完之後還要format格式化才能儲存檔案，在Linux環境中使用mkfs(<strong><span style="color:#ff0000" class="has-inline-color">M</span></strong>a<strong><span style="color:#ff0000" class="has-inline-color">k</span></strong>e a Linux <strong><span style="color:#ff0000" class="has-inline-color">f</span></strong>ilesy<strong><span style="color:#ff0000" class="has-inline-color">s</span></strong>tem的縮寫)，選項的說明可以輸入「sudo mkfs &#8211;help」來查看。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="580" height="243" src="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/f074fc44-image.png?resize=580%2C243&#038;ssl=1" alt="" class="wp-image-144" srcset="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/f074fc44-image.png?w=580&amp;ssl=1 580w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/f074fc44-image.png?resize=300%2C126&amp;ssl=1 300w" sizes="auto, (max-width: 580px) 100vw, 580px" /><figcaption>mkfs的選項</figcaption></figure></div>



<p>我打算將它格式化為xfs格式，所以就輸入「sudo mkfs -t xfs /dev/sdc1」(後面數字要正確)，系統使用預設的設定值格式化之後的資訊如下：</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="686" height="137" src="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/a4fe2eb2-image.png?resize=686%2C137&#038;ssl=1" alt="" class="wp-image-147" srcset="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/a4fe2eb2-image.png?w=686&amp;ssl=1 686w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/a4fe2eb2-image.png?resize=300%2C60&amp;ssl=1 300w" sizes="auto, (max-width: 686px) 100vw, 686px" /><figcaption>格式化後的資訊</figcaption></figure></div>



<p>格式化完成之後需要掛載起來，在Windows就是要給它個磁碟機代號(當然也可以掛在某個資料夾下)。</p>



<p>Windows做完格式化並設定完磁碟機代號後就可以使用了，就算重新開機還是會看得到新增的磁碟分割，但是Linux如果要開機時也會自動掛載起來的話，需要將相關資訊寫入/etc/fstab檔案中，在這之前會需要知道分割區的UUID，所以先輸入「sudo blkid」找到對應的UUID。</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="1024" height="73" src="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/dcb8550d-image-1024x73.png?resize=1024%2C73&#038;ssl=1" alt="" class="wp-image-148" srcset="https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/dcb8550d-image.png?resize=1024%2C73&amp;ssl=1 1024w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/dcb8550d-image.png?resize=300%2C21&amp;ssl=1 300w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/dcb8550d-image.png?resize=768%2C55&amp;ssl=1 768w, https://i0.wp.com/storage.googleapis.com/stateless-tech-uccu-website/2020/11/dcb8550d-image.png?w=1107&amp;ssl=1 1107w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption>找到要掛載的分割區UUID</figcaption></figure>



<p>將UUID裡面的值複製下來之後，輸入「sudo nano /etc/fstab」(我這裡用nano編輯器來修改，也可以用別的)，內容會長得像下面的樣子，分別是Device, Mount point, FileSystem, Parameters, dump, fsck，反正不是很熟就照著第一列的格式輸入大概就行了。</p>



<pre class="wp-block-code"><code>#
# /etc/fstab
# Created by anaconda on Thu Sep  7 20:55:27 2017
#
# Accessible filesystems, by reference, are maintained under &#039;/dev/disk&#039;
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=3c11fba3-32c7-4d0c-b614-aad5630504eb /                       xfs     defaults        0 0
UUID=ca02dd2d-a91b-4fb1-b24b-0fb19c18b89d /boot                   xfs     defaults        0 0
</code></pre>



<p>檔案儲存之後，如果要掛載的位置(資料夾)不存在，需要先建立之後再掛載，輸入「sudo mkdir 掛載路徑」建立完<strong><span style="color:#ff0000" class="has-inline-color">空的資料夾</span></strong>之後，最後再輸入「sudo mount -a」將fstab裡面設定的項目都掛載起來。</p>



<h3 class="wp-block-heading">參考來源</h3>



<ul class="wp-block-list"><li><a href="http://linux.vbird.org/linux_basic/0230filesystem/0230filesystem-fc4.php" target="_blank" rel="noreferrer noopener nofollow">http://linux.vbird.org/linux_basic/0230filesystem/0230filesystem-fc4.php</a></li><li><a href="https://blog.gtwang.org/linux/linux-add-format-mount-harddisk/" target="_blank" rel="noreferrer noopener nofollow">https://blog.gtwang.org/linux/linux-add-format-mount-harddisk/</a></li></ul>



<p></p>
<p>這篇文章 <a href="https://tech.uccu.website/linux-format-disk.html">Linux(Ubuntu)磁碟分割</a> 最早出現於 <a href="https://tech.uccu.website">泰克哪裡去</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tech.uccu.website/linux-format-disk.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">136</post-id>	</item>
	</channel>
</rss>
