1 观察
##观察目录/root 所占的磁盘空间大小
root@bogon:~# du -smh /root/
1.6G /root/
root@bogon:~# du -smh /* |grep root
du: 无法访问 '/proc/19146/task/19146/fd/3': 没有那个文件或目录
du: 无法访问 '/proc/19146/task/19146/fdinfo/3': 没有那个文件或目录
du: 无法访问 '/proc/19146/fd/3': 没有那个文件或目录
du: 无法访问 '/proc/19146/fdinfo/3': 没有那个文件或目录
1.6G /root
##观察这部主机唯一内置固态硬盘,发现/root没有独立分区槽
root@bogon:~# lsblk -aip /dev/nvme0n1
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
/dev/nvme0n1 259:0 0 476.9G 0 disk
|-/dev/nvme0n1p1 259:1 0 260M 0 part
|-/dev/nvme0n1p2 259:2 0 572M 0 part /boot/efi
|-/dev/nvme0n1p3 259:3 0 1G 0 part /boot
|-/dev/nvme0n1p4 259:4 0 4G 0 part [SWAP]
|-/dev/nvme0n1p5 259:5 0 180G 0 part
| |-/dev/mapper/cs-root 253:0 0 60G 0 lvm /
| |-/dev/mapper/cs-var 253:1 0 20G 0 lvm /var
| `-/dev/mapper/cs-home 253:2 0 90G 0 lvm /home
`-/dev/nvme0n1p6 259:6 0 45G 0 part /usr
##观察到 /root目录的挂载点是 /
root@bogon:~# df -h /root/
文件系统 大小 已用 可用 已用% 挂载点
/dev/mapper/cs-root 60G 9.0G 51G 15% /
root@bogon:~# df -h /
文件系统 大小 已用 可用 已用% 挂载点
/dev/mapper/cs-root 60G 9.0G 51G 15% /
2 为/root新建一个磁盘分区 (本机使用GPT分区表,所以直接使用gdisk进行磁盘分区),然后挂载磁盘
###/dev/nvme0n1是整个主机唯一一块内置固态硬盘,只能新建分区槽在这里了
root@bogon:~# gdisk /dev/nvme0n1
GPT fdisk (gdisk) version 1.0.10Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT. ###这行提示分区类型为GPTCommand (? for help): p
Disk /dev/nvme0n1: 1000215216 sectors, 476.9 GiB
Model: KBG50ZNV512G KIOXIA
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EB04DAED-3A0D-44A9-B1F7-241AA3B90AC2
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 1000215182
Partitions will be aligned on 2048-sector boundaries
Total free space is 516158061 sectors (246.1 GiB)Number Start (sector) End (sector) Size Code Name1 2048 534527 260.0 MiB EF00 2 534528 1705983 572.0 MiB EF00 EFI System Partition3 1705984 3803135 1024.0 MiB EA00 4 3803136 12191743 4.0 GiB 8200 5 12191744 389687295 180.0 GiB 8E00 6 389687296 484059135 45.0 GiB 8314 Linux x86-64 /usr
###以上可以看到,目前这颗磁盘内共6个分区槽###下面来看看哪个文件系统类型合适,linux默认为8300,但是我想选择更适合的(个人喜好)
############################################################
Command (? for help): l
Type search string, or <Enter> to show all codes: l
0701 Microsoft Storage Replica 3900 Plan 9
4200 Windows LDM data 4201 Windows LDM metadata
7f00 ChromeOS kernel 8200 Linux swap
8300 Linux filesystem 8301 Linux reserved
8302 Linux /home 8303 Linux x86 root (/)
8304 Linux x86-64 root (/) 8305 Linux ARM64 root (/)
8306 Linux /srv 8307 Linux ARM32 root (/)
8308 Linux dm-crypt 8309 Linux LUKS
830a Linux IA-64 root (/) 830b Linux x86 root verity
830c Linux x86-64 root verity 830d Linux ARM32 root verity
830e Linux ARM64 root verity 830f Linux IA-64 root verity
8310 Linux /var 8311 Linux /var/tmp
8312 Linux user's home 8313 Linux x86 /usr
8314 Linux x86-64 /usr 8315 Linux ARM32 /usr
8316 Linux ARM64 /usr 8317 Linux IA-64 /usr
8318 Linux x86 /usr verity 8319 Linux x86-64 /usr verity
831a Linux ARM32 /usr verity 831b Linux ARM64 /usr verity
831c Linux IA-64 /usr verity 831d Linux Alpha root (/)
831e Linux ARC root (/) 831f Linux LoongArch root (/)
8320 Linux MIPS-32 BE root (/) 8321 Linux MIPS-64 BE root (/)
8322 Linux MIPS-32 LE root (/) 8323 Linux MIPS-64 LE root (/)
Press the <Enter> key to see more codes, q to quit: n
8324 Linux PA-RISC root (/) 8325 Linux PowerPC-32 root (/)
8326 Linux PowerPC-64 BE root (/) 8327 Linux PowerPC-64 LE root (/)
8328 Linux RISC-V-32 root (/) 8329 Linux RISC-V-64 root (/)
832a Linux s390 root (/) 832b Linux s390x root (/)
832c Linux TILE-Gx root (/) 832d Linux Alpha /usr
832e Linux ARC /usr 832f Linux LoongArch /usr
8330 Linux MIPS-32 BE /usr 8331 Linux MIPS-64 BE /usr
8332 Linux MIPS-32 LE /usr 8333 Linux MIPS-64 LE /usr
8334 Linux PA-RISC /usr 8335 Linux PowerPC-32 /usr
8336 Linux PowerPC-64 BE /usr 8337 Linux PowerPC-64 LE /usr
8338 Linux RISC-V-32 /usr 8339 Linux RISC-V-64 /usr
833a Linux s390 /usr 833b Linux s390x /usr
833c Linux TILE-Gx /usr 833d Linux Alpha root verity
833e Linux ARC root verity 833f Linux LoongArch root verity
8340 Linux MIPS-32 BE root verity 8341 Linux MIPS-64 BE root verity
8342 Linux MIPS-32 LE root verity 8343 Linux MIPS-64 LE root verity
8344 Linux PA-RISC root verity 8345 Linux PowerPC-64 LE root verity
8346 Linux PowerPC-64 BE root verity 8347 Linux PowerPC-32 root verity
8348 Linux RISC-V-32 root verity 8349 Linux RISC-V-64 root verity
834a Linux s390 root verity 834b Linux s390x root verity
834c Linux TILE-Gx root verity 834d Linux Alpha /usr verity
Press the <Enter> key to see more codes, q to quit: q###个人认为8304更适合作为新分区槽文件系统类型,
###下面再看一眼现有的分区槽Command (? for help): p
Disk /dev/nvme0n1: 1000215216 sectors, 476.9 GiB
Model: KBG50ZNV512G KIOXIA
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EB04DAED-3A0D-44A9-B1F7-241AA3B90AC2
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 1000215182
Partitions will be aligned on 2048-sector boundaries
Total free space is 516158061 sectors (246.1 GiB)Number Start (sector) End (sector) Size Code Name1 2048 534527 260.0 MiB EF00 2 534528 1705983 572.0 MiB EF00 EFI System Partition3 1705984 3803135 1024.0 MiB EA00 4 3803136 12191743 4.0 GiB 8200 5 12191744 389687295 180.0 GiB 8E00 6 389687296 484059135 45.0 GiB 8314 Linux x86-64 /usr#######开始新建分区
Command (? for help): n
Partition number (7-128, default 7): 7 #####从编号7开始
First sector (34-1000215182, default = 484059136) or {+-}size{KMGTP}: ####此处回车即可
Last sector (484059136-1000215182, default = 1000214527) or {+-}size{KMGTP}: +50G####我觉得新分区槽50G即可
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 8304 #####我选择8304
Changed type of partition to 'Linux x86-64 root (/)'Command (? for help): p
Disk /dev/nvme0n1: 1000215216 sectors, 476.9 GiB
Model: KBG50ZNV512G KIOXIA
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EB04DAED-3A0D-44A9-B1F7-241AA3B90AC2
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 1000215182
Partitions will be aligned on 2048-sector boundaries
Total free space is 411300461 sectors (196.1 GiB)Number Start (sector) End (sector) Size Code Name1 2048 534527 260.0 MiB EF00 2 534528 1705983 572.0 MiB EF00 EFI System Partition3 1705984 3803135 1024.0 MiB EA00 4 3803136 12191743 4.0 GiB 8200 5 12191744 389687295 180.0 GiB 8E00 6 389687296 484059135 45.0 GiB 8314 Linux x86-64 /usr7 484059136 588916735 50.0 GiB 8304 Linux x86-64 root (/)Command (? for help): w ######一切正常,输入w即可直接写入磁盘Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.###### gdisk 會先警告你可能的問題,我們確定分割是對的,這時才按下 y !不過怎麼還有警告?
##### 這是因為這顆磁碟目前正在使用當中,因此系統無法立即載入新的分割表~
root@bogon:~# cat /proc/partitions |grep 7259 0 500107608 nvme0n1259 2 585728 nvme0n1p2259 3 1048576 nvme0n1p3259 5 188747776 nvme0n1p5259 6 47185920 nvme0n1p68 1 7224822 sda18 17 16384 sdb18 19 26228736 sdb3253 1 20971520 dm-1253 2 94371840 dm-2
###发现并没有刚才新建的7号分区槽!因为核心还没有更新!
###partprobe更新Linux核心的分区信息
root@bogon:~# partprobe -s
/dev/sda: gpt partitions 1 2
/dev/sdb: gpt partitions 1 2 3 4
/dev/nvme0n1: gpt partitions 1 2 3 4 5 6 7
#现在实际的磁盘分区状态
root@bogon:~# lsblk /dev/nvme0n1
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
nvme0n1 259:0 0 476.9G 0 disk
├─nvme0n1p1 259:1 0 260M 0 part
├─nvme0n1p2 259:2 0 572M 0 part /boot/efi
├─nvme0n1p3 259:3 0 1G 0 part /boot
├─nvme0n1p4 259:4 0 4G 0 part [SWAP]
├─nvme0n1p5 259:5 0 180G 0 part
│ ├─cs-root 253:0 0 60G 0 lvm /
│ ├─cs-var 253:1 0 20G 0 lvm /var
│ └─cs-home 253:2 0 90G 0 lvm /home
├─nvme0n1p6 259:6 0 45G 0 part /usr
└─nvme0n1p7 259:7 0 50G 0 part
##核心的分区记录
root@bogon:~# cat /proc/partitions |grep 7259 0 500107608 nvme0n1259 2 585728 nvme0n1p2259 3 1048576 nvme0n1p3259 5 188747776 nvme0n1p5259 6 47185920 nvme0n1p6259 7 52428800 nvme0n1p7##现在核心也已经正确的抓到了分区参数了8 1 7224822 sda18 17 16384 sdb18 19 26228736 sdb3253 1 20971520 dm-1253 2 94371840 dm-2
##磁盘格式化(建立文件系统)
#CentOS 10预设是xfs文件系统,我们要建立的其实是xfs文件系统,因此使用mkfs.xfs这个指令
root@bogon:~# mkfs.xfs /dev/nvme0n1p7
meta-data=/dev/nvme0n1p7 isize=512 agcount=12, agsize=1092266 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=1, sparse=1, rmapbt=1= reflink=1 bigtime=1 inobtcount=1 nrext64=1= exchange=0
data = bsize=4096 blocks=13107192, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1, parent=0
log =internal log bsize=4096 blocks=25650, version=2= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
Discarding blocks...Done.
##很快格式化完毕!都用默认值!较为重要的是inode与block的值
root@bogon:~# blkid /dev/nvme0n1p7
/dev/nvme0n1p7: UUID="2ac0d69b-6988-4ea5-ae8c-044f825dbf6a" BLOCK_SIZE="512" TYPE="xfs" PARTLABEL="Linux x86-64 root (/)" PARTUUID="e89589cb-8130-4930-bbea-852a6116b4cd"
###确定建置好xfs文件系统了!
##创建一个存放/root文件的临时目录
root@bogon:~# mkdir /roottmp
#将新分区槽挂载到上面这个临时目录
root@bogon:~# mount /dev/nvme0n1p7 /roottmp/
#查看是否已经正确挂载
root@bogon:~# df -h /dev/nvme0n1p7
文件系统 大小 已用 可用 已用% 挂载点
/dev/nvme0n1p7 50G 1012M 49G 2% /roottmp
#将全部/root的内容复制到/roottmp目录下,执行命令需要稍等一会儿,具体时间看配置
root@bogon:~# cp -a /root/. /roottmp/ ####一定要加上-a参数
##取消/roottmp目录的挂载
root@bogon:~# umount /dev/nvme0n1p7
##然后把/dev/nvme0n1p7这个新分区槽 挂载 到 /root目录
root@bogon:~# mount /dev/nvme0n1p7 /root
##查看是否正确挂载
root@bogon:~# df -h /dev/nvme0n1p7
文件系统 大小 已用 可用 已用% 挂载点
/dev/nvme0n1p7 50G 2.6G 48G 6% /root
##设置开机自动挂载
root@bogon:~# vim /etc/fstab
###把下面这行加入上面的文件,:wq退出文件编辑
UUID=2ac0d69b-6988-4ea5-ae8c-044f825dbf6a /root xfs defaults 0 0
##输入自动挂载立即生效命令然后重启
root@bogon:~# mount -a
root@bogon:~# reboot##如果正常启动使用,则说明没问题
Centos7 /usr目录挂载到新分区_centos 根目录重新挂载到别的分区-CSDN博客
鳥哥私房菜 - 第七章、Linux 磁碟與檔案系統管理