---
# System prepended metadata

title: Disk擴充相關操作
tags: [Other]

---

# Disk擴充相關操作
[toc]
> {%hackmd BJrTq20hE %}

指令
![image](https://hackmd.io/_uploads/S1ztr6L0T.png)

架構
![image](https://hackmd.io/_uploads/BJn9SpU06.png)






# 從home 掛載到 root
```
//備份home
tar cvf /tmp/home.tar /home

//卸除＆掛載
umount /home
lvremove /dev/mapper/cl-home
lvextend -L +580G /dev/mapper/cl-root
xfs_growfs /dev/mapper/cl-root
lvcreate -L 10G -n /dev/mapper/cl-home
mkfs.xfs /dev/mapper/cl-home
mount /dev/mapper/cl-home

//還原home
tar xvf /tmp/home.tar -C /home/
```


## **擴充disk**
```
fdisk -l  //看新增的dsik路徑
fdisk /dev/sdb //(視路徑而定)
n p (1) Enter Enter t (1) (8e) p w
reboot
//此時新的z分割槽路徑已新增為 /dev/sdb1

pvcreate /dev/sdb1
vgdisplay  //看VG Name
vgextend centos /dev/sdb1
vgdisplay //看是否已擴大
lvextend /dev/centos/root /dev/sdb1
xfs_growfs /dev/mapper/centos-root
```


## **不刪除資料擴充現有disk**
待研究...
![](https://hackmd.io/_uploads/SJe0OM78h.png)
```
lsblk    //查看欲擴增路徑 (此例為"/dev/rhel/CLM")
fdisk -l    //查看partition分布狀況
pvcreate /dev/sda3    //create一個新的partition
vgdisplay  //查看vg名稱   (此例為"rhel")
vgextend rhel /dev/sda3   //擴展vg空間
xfs_growfs /dev/rhel/CLM
reboot
```





## **使用parted掛載2T以上的新disk (<font color="#C10066">過程會格式化! 請慎用!!!</font>)**
請先安裝parted 套件
parted rpm 下載點

```
fdisk -l  //看disk路徑
fdisk /dev/sdd //(視路徑而定)
d w   //確認該disk是否已創建
```
![](https://i.imgur.com/THifTDM.png)
-----------------------------------------------------------
```
parted /dev/rvdd1  //使用parted 命令新的disk
(parted) mklabel gpt  //格式化為gpt
(parted) mkpart primary 0GB 10TB //
(parted) quit
```
------------------------------------------------------------
fdisk -l  //查看是否已建立gpt label
![](https://i.imgur.com/mqIEUrP.jpg)

```
mkfs.ext4 /dev/rvdd1
mount /dev/rvdd1 /clm   //掛載disk
```
------------------------------------------------------------
//編輯 /etc/fstab 永久掛載該disk
![](https://i.imgur.com/nJdX065.png)


## **Disk usage 變負的 (參考用，沒測試過)**
![](https://i.imgur.com/IZu802Y.png)


###### tags: `Other`
Edit by Mario