centos 磁盤掛載

一、parted的用途及說明

概括使用說明:

parted用于對磁盤(或RAID磁盤)進行分區及管理,與fdisk分區工具相比,支持2TB以上的磁盤分區,并且允許調整分區的大小。使用它你可以創建、清除、調整、移動和復制ext2、ext3、ext4、linux-swap、FAT、FAT32和reiserfs分區;也能創建、調整和移動蘋果系統的HFS分區;還能檢測jfs、ntfs、ufs和xfs分區。該工具常用于為新安裝的操作系統創建空間,重新分配硬盤使用情況,在將數據拷貝到新硬盤的時候也常常使用。

二、 parted的使用方法及步驟

fdisk -l 查看硬盤分區格式信息
————————————————

[root@localhost ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

磁盤 /dev/sdb:536.9 GB, 536870912000 字節,1048576000 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:gpt
Disk identifier: FCD85220-83B7-436C-8BD9-D34E4878119D


Start End Size Type Name

 1         2048   1048573951    500G  Microsoft basic ofs

磁盤 /dev/sdc:322.1 GB, 322122547200 字節,629145600 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節


磁盤 /dev/sda:53.7 GB, 53687091200 字節,104857600 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x00012d21

   設備 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM

磁盤 /dev/mapper/centos-root:50.5 GB, 50457477120 字節,98549760 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節


磁盤 /dev/mapper/centos-swap:2147 MB, 2147483648 字節,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節

2.1進入parted對磁盤進行分區

[root@localhost ~]# parted /dev/sd
sda   sda1  sda2  sdb   sdb1  sdc   
[root@localhost ~]# parted /dev/sdc    **選擇需要分區的磁盤**
GNU Parted 3.1
使用 /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help      **help查看parted下命令介紹**  
  
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found
        partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) mklabel                                                          
新的磁盤標簽類型? gpt       **寫入磁盤便簽**
(parted) mkpart      **創建分區**
分區名稱?  []? test                                                      
文件系統類型?  [ext2]? ext4                                              
起始點? 1        **可以輸入具體的起始點(1M或者1G)1表示扇區最小的起始點**         
結束點? -1       **結束點一樣也可以輸入具體的結束點(100M或者300G)-1表示扇區最后的結束點**
(parted) p       **全拼print查看分區**                             
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name  標志
 1      1049kB  322GB  322GB               test

(parted) quit      **退出parted分區**                     
信息: You may need to update /etc/fstab.
 
[root@localhost ~]# mkfs.ext4 /dev/sd  
sda   sda1  sda2  sdb   sdb1  sdc   sdc1  
[root@localhost ~]# mkfs.ext4 /dev/sdc1   **mkfs.ext4 對剛剛創建的分區進行格式化**
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19660800 inodes, 78642688 blocks
3932134 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=2227175424
2400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成     

[root@localhost ~]# mkdir /ysj     **創建一個分區的掛載點**
[root@localhost ~]# mount /dev/sdc1 /ysj    **mount將新建的分區掛載到新建的掛載點**
[root@localhost ~]# df -h       **df -h 查看磁盤分區的使用情況**
文件系統                 容量  已用  可用 已用% 掛載點
/dev/mapper/centos-root   47G  8.0G   40G   17% /
devtmpfs                 905M     0  905M    0% /dev
tmpfs                    920M     0  920M    0% /dev/shm
tmpfs                    920M  9.1M  911M    1% /run
tmpfs                    920M     0  920M    0% /sys/fs/cgroup
/dev/sdb1                493G   73M  467G    1% /ofs
/dev/sda1               1014M  179M  836M   18% /boot
tmpfs                    184M   32K  184M    1% /run/user/0
/dev/sr0                 4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
/dev/sdc1                296G   65M  281G    1% /ysj
[root@localhost ~]# 

三,修改 vi/etc/fstab 設置開機自動掛載

[root@localhost ~]# vi /etc/fstab        **進去該目錄下設置開機自動掛載**


#
# /etc/fstab
# Created by anaconda on Wed Apr 29 18:09:55 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=7d7c13fd-ff7e-4ffe-b923-159e4b7f1f65 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sdb1              /ofs                     ext4    defaults        0 0 
/dev/sdc1              /ysj                     ext4    defaults        0 0
~                                                                                                                        
~                                                                                                                        
~                                                                                                                        
~                                                                                                                                                                                                                                            
:wq     **shift+;  輸入小寫wq  保存退出,不小心誤刪的可以q!不保存退出**

四,卸載分區

[root@localhost ~]# umount /dev/sdc1       **使用umount命令卸載掛載的分區**
[root@localhost ~]# df -h       **df -h 查看磁盤分區的使用情況**
文件系統                 容量  已用  可用 已用% 掛載點
/dev/mapper/centos-root   47G  8.0G   39G   17% /
devtmpfs                 905M     0  905M    0% /dev
tmpfs                    920M     0  920M    0% /dev/shm
tmpfs                    920M  9.1M  911M    1% /run
tmpfs                    920M     0  920M    0% /sys/fs/cgroup
/dev/sdb1                493G   73M  467G    1% /ofs
/dev/sda1               1014M  179M  836M   18% /boot
tmpfs                    184M   32K  184M    1% /run/user/0
/dev/sr0                 4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64

                        **發現我們剛剛掛載的ysj掛載點已經刪除***

[root@localhost ~]# parted /dev/sd
sda   sda1  sda2  sdb   sdb1  sdc   sdc1  
[root@localhost ~]# parted /dev/sdc        ****parted再次進入分區刪除殘舊的磁盤信息***
GNU Parted 3.1
使用 /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p          **查看當前的磁盤分區**                      
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name  標志
 1      1049kB  322GB  322GB  ext4         test

(parted) rm 1         **rm  刪除分區  1指的是Number下的磁盤ID**
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  標志

         *在查看發現我們創建的磁盤分區已經被刪除了**

(parted) quit        **保存退出**                                        
信息: You may need to update /etc/fstab.

[root@localhost ~]# vi /etc/fstab      ****進入此文件夾下注釋掉之前的自啟動信息 否則可能影響系統的正常啟動在對應的行列前加#號表示注銷***


#
# /etc/fstab
# Created by anaconda on Wed Apr 29 18:09:55 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=7d7c13fd-ff7e-4ffe-b923-159e4b7f1f65 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sdb1              /ofs                     ext4    defaults        0 0
#/dev/sdc1              /ysj                     ext4    defaults        0 0
~                                                                                                                        
~                                                                                                                        
~                                                                                                                        
~                                                                                                                        
                                                                                                                 
:wq   **保存退出**

五.fdisk 分區使用

上面我們已經介紹了如何通過fdisk -l 查看硬盤分區格式信息,這里不做重復的介紹,

[root@test4 ~]# fdisk /dev/sda  **對sda磁盤進行分區**
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 2597.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m          **輸出幫助信息**
 Command action
    a   toggle a bootable flag    **設置啟動分區**
    b   edit bsd disklabel        **編輯分區標簽**
    c   toggle the dos compatibility flag
    d   delete a partition        **刪除一個分區**
    l   list known partition types  **列出分區類型**
    m   print this menu           **輸出幫助信息**
    n   add a new partition       **建立一個新的分區**
    o   create a new empty DOS partition table **創建一個新的空白DOS分**區表
    p   print the partition table    **打印分區表**
    q   quit without saving changes  **退出不保存設置**
    s   create a new empty Sun disklabel
    t   change a partition's system id  **改變分區的ID**
    u   change display/entry units    **改變顯示的單位**
    v   verify the partition table    **檢查驗證分區表**
    w   write table to disk and exit  **保存分區表**
    x   extra functionality (experts only)
Command (m for help):n     
Command action
   e   extended                 **e是擴展分區**
   p   primary partition (1-4)  **p是主分區**
p
Partition number (1-4): 1       **定義分區數量   --主分區最多只能有四個**
First cylinder (1-2597, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-2597, default 2597): +100M

Command (m for help): w          **保存剛才的配置信息。**
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: 無效的參數.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

[root@test6 ~]# partprobe /dev/sda     **對硬盤進行更新**

所有新建的磁盤都需要mkfs.ext2/3/4 進行格式化 mount進行掛載并設置開啟自啟動。
from https://blog.csdn.net/weixin_45065440/article/details/105856712

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容