linux基本命令及操作13(磁碟管理)__linux

來源:互聯網
上載者:User
       磁碟管理 1.名詞解釋
  mbr
  mpt
  硬碟有效性標示
  主要磁碟分割
  擴充分區
  邏輯分區

2.磁碟查看命令
fdisk -l   ##系統中的所有磁碟裝置
df  -TH       ##系統正在掛載的磁碟裝置
blkid        ##系統可以掛載的磁碟裝置id

3.分區劃分
fidsk /dev/vdb


  m      ##獲得協助  
  n      ##建立分區
Partition type:
   p   primary          ##分區類型為主要磁碟分割
   e   extended       ##分區類型為擴充分區
Select (default p): p

Partition number (2-4, default 2): 1        ##主要磁碟分割id

First sector (206848-20971519, default 206848): ##此分區的起始位置 Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +1G ##分區大小


Command (m for help): wq   ##儲存並退出,只輸入q則表示捨棄變更退出


建立一個主要磁碟分割/dev/vdb1  wq儲存推出


[root@localhost ~]#

partprobe         ##同步分區表
mkfs.xfs /dev/vdb1    ##格式化

mount /dev/vdb1  /mnt     ##臨時掛載


將分區格式化成xfs格式,並臨時掛載到/mnt上



vim /etc/fstab         ##永久掛載
編寫格式:
device    mountpoint    ftype   defaults(mountpoint)   0   0

/dev/vdb1    /mnt        xfs    defaults       0     0


進入/etc/fstab檔案寫入,實現永久掛載


mount -a         ##使/etc/fastab中記錄的掛載生效




4.刪除分區
先使用umount命令解除掛載
  註:當掛載點被使用時,無法解除掛載,需要用fuser -kvm結束使用的進程,然後進行解除掛載

解除掛載之後,使用fdisk /dev/vdb命令 刪除分區




5.設定分區方式,將mkdocs 改為 gpt
更改之前需要把正在使用的分區關閉,才可以變更
partoff /dev/vdb2

parted /dev/vdb



6.添加swap分區
fdisk  /dev/vdb        ##添加一個分區

[root@localhost ~]# fdisk /dev/vdb

Command (m for help): n             建立分區


Command (m for help): t    選擇分區類型



Partition type (type L to list all types): 14        選擇14 Linux  swap分區

Command (m for help): p           顯示分區
             

Command (m for help): wq

The partition table has been altered!



7.更改gpt下的swap 為mkdos下的swap




8.用檔案來添加swap

dd if=/dev/zero of=/swapfile bs=1M count=1000 ##建立一個1G大小的檔案
mkswap /swapfile    ##格式化為swap類型

swapon -a /swapfile    ##臨時添加到swap裡


-p + 數字        ##更改優先順序
vim /etc/fstab        ##永久添加swap分區
類型:

/swapfile    swap  swap  defaults,pri=1  0 0 #pri優先順序

swapon -a  自動開啟所有swap裝置



9.刪除swap
vim /etc/fstab  ##刪除此檔案中添加的swap行
swapoff /swapfile ##斷開swap檔案連結
swapoff /dev/vdb1 ##斷開swap磁碟連結
rm -rf /swapfile  ##刪除檔案
fdisk /dev/vdb      ##刪除磁碟分割

partprobe      ##同步分區表





相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.