# Install Ubuntu 20.04 ###### tags: `tutorials` `Ubuntu 20.04` `PairLab` ## 燒錄 Ubuntu 20.04 映像檔 https://www.ubuntu-tw.org/modules/tinyd0/ - 發行版: Ubuntu 桌面版本 - 版本: 18.04 LTS(5 年支援) - 電腦架構: 64 位元版本 ### Trouble shooting * 選擇 Install Ubuntu 後卡住花屏 - 游標移動到 Install Ubuntu - 按下 e - 找到 **quite splash** - 在其後面空一格輸入 **nomodeset** - 按下 F10 儲存,並開始安裝 * reference: https://blog.csdn.net/Eclipsesy/article/details/78181147 * 切割硬碟且安裝成功後,開機時紫屏 ```shell $ sudo gedit /boot/grub/grub.cfg ## 將所有的 linux /boot/.......ro quite splash $vt_handoff ## 改為 linux /boot/.......ro quite splash $vt_handoff acpi_osi=linux nomodeset $ sudo gedit /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" ## 改為 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=linux nomodeset" ``` reference: https://blog.csdn.net/yang201610/article/details/95786193 ## 切割硬碟 * EFI,1024MB * EXT4,分割到 /boot,10240MB * EXT4,分割到 /tmp,10240MB * EXT4,分割到 /home,102400MB * swap,等於RAM * EXT4,分割到 /,剩下的容量 ## 安裝 openssh ```shell $ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install openssh-server -y ``` ## Mount Disk 1. 查看 /dev 下面所有的硬碟情況 ```shell $ ls /dev/[sh]d* /dev/sda /dev/sdb ``` 2. 格式化硬碟 ```shell $ sudo mkfs -t ext4 /dev/sda ``` 3. 分割硬碟,切出 /dev/sda1 ```shell $ sudo gdisk /dev/sda Command (? for help): n Partition number (1-128, default 1): First sector (34-7814037134, default = 2048) or {+-}size{KMGTP}: Last sector (2048-7814037134, default = 7814037134) or {+-}size{KMGTP}: Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): c Using 1 Enter name: docker Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! ``` 4. 把 /dev/sda1 格式化才會出現 UUID ```shell $ sudo mkfs -t ext4 /dev/sda1 ``` 5. 使用指定UUID,開機時自動掛載硬碟 列出所有磁碟的 UUID ```shell $ sudo blkid ... /dev/nvme0n1p6: UUID="21028796-965b-4e7a-aa28-062fcabfce57" TYPE="ext4" PARTUUID="47668701-4323-4ac8-b8de-42baddffab32" /dev/nvme0n1: PTUUID="c2b1b471-20da-4e57-a9da-f2d56e1f77fe" PTTYPE="gpt" /dev/sda1: UUID="b2f381ef-502b-44da-ae75-a2ac08f95778" TYPE="ext4" PARTLABEL="docker" PARTUUID="a0debd96-305a-47c4-a654-a7826b49a4bb" /dev/sdb: PTUUID="1cd6a312-2481-41d5-87d0-9f97d84426a5" PTTYPE="gpt" ``` 6. 選擇想要的分區 UUID 加入至 /etc/fstab EX: /dev/sda1 掛載至 /docker_disk ```shell $ sudo vim /etc/fstab ``` 將以下加入 ```shell UUID=b2f381ef-502b-44da-ae75-a2ac08f95778 /docker_disk ext4 defaults 0 0 ``` 7. 掛載 /docker_disk ```shell $ sudo mkdir /docker_disk $ sudo mount /docker_disk ``` ### reference https://bean-li.github.io/gdisk-operation/ ## 合併硬碟 1. 切割硬碟 (欲合併的硬碟都要切割) ```shell $ sudo gdisk /dev/sda ``` ```shell ### p 查詢硬碟資訊 ### Command (? for help): p Disk /dev/sda: 3907029168 sectors, 1.8 TiB Model: ST2000DM008-2FR1 Sector size (logical/physical): 512/4096 bytes Disk identifier (GUID): DDFDC0F5-5BC7-407B-A2AA-FDC42E0A216C Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 3907029134 Partitions will be aligned on 2048-sector boundaries Total free space is 3907029101 sectors (1.8 TiB) Number Start (sector) End (sector) Size Code Name ``` ```shell ### n 切割新分區 ### Command (? for help): n Partition number (1-128, default 1): First sector (34-3907029134, default = 2048) or {+-}size{KMGTP}: Last sector (2048-3907029134, default = 3907029134) or {+-}size{KMGTP}: Current type is 8300 (Linux filesystem) Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' ``` ```shell ### 再查詢一次就會有新的分區了 ### Command (? for help): p Disk /dev/sda: 3907029168 sectors, 1.8 TiB Model: ST2000DM008-2FR1 Sector size (logical/physical): 512/4096 bytes Disk identifier (GUID): DDFDC0F5-5BC7-407B-A2AA-FDC42E0A216C Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 3907029134 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 3907029134 1.8 TiB 8300 Linux filesystem ``` 2. 安裝 LVM ```shell $ sudo apt-get install lvm2 -y ``` 3. PV 把分割槽加入物理卷 | 指令 | 說明 | | --------- | --------------------------------------------- | | pvcreate | 將實體 partition 建立成為 PV | | pvscan | 搜尋目前系統裡面任何具有 PV 的磁碟 | | pvdisplay | 顯示出目前系統上面的 PV 狀態 | | pvremove | 將 PV 屬性移除,讓該 partition 不具有 PV 屬性 | ```shell $ sudo pvcreate /dev/sda1 $ sudo pvcreate /dev/sdb1 ``` 4. VG 將物理卷加入卷組 | 指令 | 說明 | | --------- | -------------------------- | | vgcreate | 建立 VG | | vgscan | 搜尋系統上面是否有 VG 存在 | | vgdisplay | 顯示目前系統上面的 VG 狀態 | | vgextend | 在 VG 內增加額外的 PV | | vgreduce | 在 VG 內移除 PV | | vgchange | 設定 VG 是否啟動 (active) | | vgremove | 刪除一個 VG | ```shell $ sudo vgcreate vgdocker /dev/sda1 /dev/sdb1 ``` 5. LV 在卷則上建立邏輯卷 | 指令 | 說明 | | --------- | ------------------------ | | lvcreate | 建立 LV | | lvscan | 查詢系統上面的 LV | | lvdisplay | 顯示系統上面的 LV 狀態 | | lvextend | 在 LV 裡面增加容量 | | lvreduce | 在 LV 裡面減少容量 | | lvremove | 刪除一個 LV | | lvresize | 對 LV 進行容量大小的調整 | ```shell $ sudo lvcreate -L 3.5T -n lvdocker vgdocker ``` 6. 掛載邏輯卷 ```shell ## 格式化 $ sudo mkfs.ext4 /dev/vgdocker/lvdocker ## 建立掛載資料夾 $ sudo mkdir /docker_disk ## 掛載硬碟至指定資料夾 $ sudo mount /dev/vgdocker/lvdocker /docker_disk ``` 7. 設定開機掛載 ``` ### 選擇想要的分區 UUID 加入至 /etc/fstab ### EX: /dev/sda1 掛載至 /docker_disk # /docker_disk was on /dev/vgdocker/lvdocker UUID=b2f381ef-502b-44da-ae75-a2ac08f95778 /docker_disk ext4 defaults 0 0 ```