不多說,直接上干貨!
本博文的主要內容有
.磁盤分區的概述
.常用的磁盤管理工具
./下分5G,給/home擴容
.系統自帶的fdisk和parted這兩款工具
.磁盤空間管理
前言
系統自帶的fdisk和parted這兩款工具,可以為我們提供更方便地對磁盤空間進行查看和管理的能力,也可以使用帶-l選項的fdisk命令來查看某塊磁盤上更新詳細的信息。
磁盤分區的概述
磁盤由兩個分區組成,即分為主分區和擴展分區,擴展分區又可由多個邏輯分區組成。
我們在安裝linux系統時,若使用自動分區的方式進行磁盤分區,系統則將自動將分成兩個分區,即根分區/和交換分區swap。交換分區的作用是充當虛擬內存,主要是物理內存不足時用於暫時對數據進行保存,並在需要時進行調用。由於交換分區只能用於暫時數據的存儲,因此系統還必須有一股分區用於長期存儲文件及數據。
Linux系統下的磁盤類型有IDE和SCSI這兩種。當然,這些磁盤設備也被映射到一個系統文件上。對於這兩種磁盤的命名方式,IDE的命名方式采用/dec/hdx(x代表磁盤快),而其下的分區則是/dec/hdxy(y代表該磁盤塊上的分區號).SCSI則采用/dev/sdx,其下的分區是/dev/sdxy。
對於Linux的磁盤分區,至少要有/分區、boot分區和swap分區。否則,安裝會受阻,考慮到實際的工作環境及后期對磁盤的維護(如后期磁盤空間需要擴容,在Linux系統下安裝Oracle數據庫)等。Linux磁盤分區的格式建議是LVM格式,而設計Oracle的安裝時,swap分區往往與物理內存對應,因此在實際的工作環境下安裝系統時應該做好分區工作。
推薦
下載地址:http://pan.baidu.com/s/1c2iLrji
磁盤管理工具是系統管理員需要經常使用的軟件,是完成磁盤管理的重要手段。常用的磁盤管理工具包括:fdisk、Partition Magic、parted、mkfs和e2fsck。
使用partprobe重載分區也只能是對不同的硬盤才能及時生效。對於同一塊硬盤,修改過分區信息后,必須重啟系統才能使修改過的分區信息生效。(比如,SCSI硬盤和IDE硬盤。)
問題的描述
可以看出,我的虛擬機里的這個系統,因之前,在安裝分區時,未考慮周到,/home的容量太小了,現在,我想,希望從/下分5G容量給/home?
或者,新建一磁盤,來進行對分區的擴容。(實則,是想從/dev/sdb擴容5G到/dev/sda下的/home)。求解!!!
流程:添加磁盤 -> 使用fdisk創建磁盤分區 -> 使用parted工具創建分區 -> 掛載磁盤分區到系統
1、使用fdisk -l查詢當前系統分區情況
[root@weekend110 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 16G 3.7G 12G 25% / tmpfs 931M 232K 931M 1% /dev/shm /dev/sda1 194M 30M 155M 16% /boot /dev/sda2 2.9G 2.8G 0 100% /home /dev/sr0 4.2G 4.2G 0 100% /media/CentOS_6.5_Final [root@weekend110 ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000491de Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 409 3072000 83 Linux Partition 2 does not end on cylinder boundary. /dev/sda3 409 536 1024000 82 Linux swap / Solaris Partition 3 does not end on cylinder boundary. /dev/sda4 536 2611 16669696 5 Extended /dev/sda5 536 2611 16668672 83 Linux [root@weekend110 ~]#
可以看到新增加的sda磁盤還沒有分區!!!
重啟機器,后,再次執行
[root@weekend110 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 16G 3.7G 12G 25% / tmpfs 931M 72K 931M 1% /dev/shm /dev/sda1 194M 30M 155M 16% /boot /dev/sda2 2.9G 2.8G 0 100% /home [root@weekend110 ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000491de 想說的是,一看/dev/sda,就是原來的硬盤。 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 409 3072000 83 Linux Partition 2 does not end on cylinder boundary. /dev/sda3 409 536 1024000 82 Linux swap / Solaris Partition 3 does not end on cylinder boundary. /dev/sda4 536 2611 16669696 5 Extended /dev/sda5 536 2611 16668672 83 Linux Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 想說的是,一看/dev/sda,就是新增的硬盤。
[root@weekend110 ~]# ll /dev/sd* brw-rw----. 1 root disk 8, 0 Oct 18 20:04 /dev/sda brw-rw----. 1 root disk 8, 1 Oct 18 20:04 /dev/sda1 brw-rw----. 1 root disk 8, 2 Oct 18 20:04 /dev/sda2 brw-rw----. 1 root disk 8, 3 Oct 18 20:04 /dev/sda3 brw-rw----. 1 root disk 8, 4 Oct 18 20:04 /dev/sda4 brw-rw----. 1 root disk 8, 5 Oct 18 20:04 /dev/sda5 brw-rw----. 1 root disk 8, 16 Oct 18 20:04 /dev/sdb [root@weekend110 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@weekend110 ~]#
可見,該新增的磁盤/dec/sdb,上沒有創建任何分區。
[root@weekend110 ~]# clear [root@weekend110 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xace34bc7. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): m Command action a toggle a bootable flag //設置可引導的標記 b edit bsd disklabel //修改bsd磁盤的標簽 c toggle the dos compatibility flag //設置dos的兼容性 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 //創建一個新的、空的Sun磁盤標簽 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):
2.創建主分區
因為,新增磁盤,是sdb。
fdisk /dev/sdb
輸入n
[root@weekend110 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xf5778f69. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4)
提示說,輸入p
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G Command (m for help):
在輸入結束柱面的這里如果你不知道該輸入多大的數字,你可以輸入+然后輸入你要設的大小。這里我設置10G的主分區。
輸入p查看分區信息,可以看到剛創建的sdb1主分區。
Command (m for help): p //查看當前分區表 Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xc0585a2e Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux Command (m for help): Command (m for help): w //保存退出 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@weekend110 ~]#
3、創建擴展分區
Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 2 First cylinder (1307-2610, default 1307): 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610): 2610 Command (m for help): p //查看當前的分區表 Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xc0585a2e Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux /dev/sdb2 1307 2610 10474380 5 Extended Command (m for help):
圖片上通過紅色標注了操作步驟。可以看到當前已創建了sdb2擴展分區,柱面從1037-2610,即將剩下的所有空間創建為擴展分區。
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@weekend110 ~]#
4.創建邏輯分區
Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (1307-2610, default 1307): 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610): +2G Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (1569-2610, default 1569): 1560^H Value out of range. First cylinder (1569-2610, default 1569): 1569 Last cylinder, +cylinders or +size{K,M,G} (1569-2610, default 2610): 2610 Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xc0585a2e Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux /dev/sdb2 1307 2610 10474380 5 Extended /dev/sdb5 1307 1568 2104483+ 83 Linux /dev/sdb6 1569 2610 8369833+ 83 Linux Command (m for help):
總共創建了兩個邏輯分區,邏輯分區默認從5開始,第一個邏輯分區大小2G,用來做交換分區用,剩下全部給sdb6.
Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xace34bc7 Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux /dev/sdb2 1307 2610 10474380 5 Extended /dev/sdb5 1307 1568 2104483+ 83 Linux /dev/sdb6 1569 2610 8369833+ 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@weekend110 ~]#
5、修改文件類型ID
因為默認分區id都是83即linux文件類型,現在將sdb5的文件類型ID改成82即交換分區。
Command (m for help): t Partition number (1-6): 5 Hex code (type L to list codes): 82 Changed system type of partition 5 to 82 (Linux swap / Solaris) Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xc0585a2e Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux /dev/sdb2 1307 2610 10474380 5 Extended /dev/sdb5 1307 1568 2104483+ 82 Linux swap / Solaris /dev/sdb6 1569 2610 8369833+ 83 Linux Command (m for help):
6、保存退出
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 p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system 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): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@weekend110 ~]#
7.格式化分區
接下來要對sdb的每一個分區進行格式化,
注意:擴展分區不需要進行格式
[root@weekend110 ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655776 inodes, 2622603 blocks 131130 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2688548864 81 block groups 32768 blocks per group, 32768 fragments per group 8096 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 25 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@weekend110 ~]# [root@weekend110 ~]# mkfs.ext4 /dev/sdb1 或者 [root@weekend110 ~]# mkfs -t ext4 /dev/sdb1 是等價的。
[root@weekend110 ~]# mkfs -t ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655776 inodes, 2622603 blocks 131130 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2688548864 81 block groups 32768 blocks per group, 32768 fragments per group 8096 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@weekend110 ~]#
[root@weekend110 ~]# mkfs.ext4 /dev/sdb6 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 523264 inodes, 2092458 blocks 104622 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2143289344 64 block groups 32768 blocks per group, 32768 fragments per group 8176 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 25 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@weekend110 ~]#
swap分區格式化要使用
mkswap /dev/sdb5 mkswap,是mkdir swap。
[root@weekend110 ~]# mkswap /dev/sdb5 Setting up swapspace version 1, size = 2104476 KiB no label, UUID=d28dfa28-7303-463a-ae0c-b1751786c656 [root@weekend110 ~]#
加載文件
swapon /dev/sdb5
查看是否生效
swapon -s
[root@weekend110 ~]# swapon /dev/sdb5 [root@weekend110 ~]# swapon -s Filename Type Size Used Priority /dev/sda3 partition 1023992 0 -1 /dev/sdb5 partition 2104472 0 -2 [root@weekend110 ~]#
可以看到sda3,和sdb5這兩個swap分區。
8.掛載分區
這里直接使用修改文件的方式永久掛載
創建掛載文件路徑
mkdir sdb1 sdb6
[root@weekend110 ~]# mkdir sdb1 sdb6 [root@weekend110 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 16G 3.7G 12G 25% / tmpfs 931M 72K 931M 1% /dev/shm /dev/sda1 194M 30M 155M 16% /boot /dev/sda2 2.9G 2.8G 0 100% /home [root@weekend110 ~]#
# # /etc/fstab # Created by anaconda on Mon Jul 18 18:45:01 2016 # # 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 # UUID=f664c4a8-f9ea-4999-b914-4071e8efdff2 / ext4 defaults 1 UUID=2da787fb-94f8-4f6a-8d75-15d66628c818 /boot ext4 defaults 1 2 UUID=77fd7f45-c1e6-4014-a21e-75fe308e7edd /home ext4 defaults 1 2 UUID=98519c68-56ea-450e-b2e7-ca329d379e05 swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/sdb1 /sdb1 ext4 defaults 0 0 /dev/sdb5 swap swap defaults 0 0 /dev/sdb6 /sdb6 ext4 defaults 0 0
9.立即生效
partprobe
[root@weekend110 ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Error: Invalid partition table - recursive partition on /dev/sr0. [root@weekend110 ~]#
在我的虛擬機上面無法立即生效,重啟機器。
shutdown -r now
[root@weekend110 ~]# shutdown -r now Broadcast message from root@weekend110 (/dev/pts/0) at 23:58 ... The system is going down for reboot NOW! [root@weekend110 ~]#
沒生效,那是因為,遇到了
Error: Invalid partition table - recursive partition on /dev/sr0.
參考博客:
http://www.mincoder.com/article/3454.shtml
決方法:執行partprobe 命令
partprobe包含在parted的rpm軟件包中。
partprobe可以修改kernel中分區表,使kernel重新讀取分區表。
因此,使用該命令就可以創建分區並且在不重新啟動機器的情況下系統能夠識別這些分區。
[root@weekend110 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 16G 3.7G 12G 25% / tmpfs 931M 72K 931M 1% /dev/shm /dev/sda1 194M 30M 155M 16% /boot /dev/sda2 2.9G 2.8G 0 100% /home
[root@weekend110 ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Error: Invalid partition table - recursive partition on /dev/sr0. [root@weekend110 ~]# rpm -q parted parted-2.1-21.el6.x86_64 [root@weekend110 ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Error: Invalid partition table - recursive partition on /dev/sr0. [root@weekend110 ~]# mkfs -t ext4 /dev/sr0 mke2fs 1.41.12 (17-May-2010) /dev/sr0 is entire device, not just one partition! Proceed anyway? (y,n) y /dev/sr0: Read-only file system while setting up superblock [root@weekend110 ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Error: Invalid partition table - recursive partition on /dev/sr0. [root@weekend110 ~]#
出現這個問題,我查閱了一些資料,如http://www.linuxdiyf.com/viewarticle.php?id=312338
主要是因為是使用的虛擬機,如果是直接在Linux系統上,不會出現這個問題。
如:http://bbs.51cto.com/thread-1118884-1.html
在虛擬機中把光驅移除后,重新進入虛擬機新建分區,並通過partprobe重載分區,就沒有/dev/sr0 出現遞歸分區的錯誤信息了。
[root@weekend110 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 16G 3.7G 12G 25% / tmpfs 931M 72K 931M 1% /dev/shm /dev/sda1 194M 30M 155M 16% /boot /dev/sda2 2.9G 2.3G 524M 82% /home [root@weekend110 ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
但是仍然提示重載分區不成功,提示設備或資源忙,需要重啟生效。
直接格式化新建的分區,提示找不到新建的/dev/sdb分區。
重啟系統后,在格式化新建的分區/dev/sdb,成功。
[root@weekend110 ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. [root@weekend110 ~]# mkfs -t ext4 /dev/sdb //分區格式化 mke2fs 1.41.12 (17-May-2010) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y /dev/sdb is apparently in use by the system; will not make a filesystem here!
再次嘗試,
[root@weekend110 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 16G 3.7G 12G 25% / tmpfs 931M 72K 931M 1% /dev/shm /dev/sda1 194M 30M 155M 16% /boot /dev/sda2 2.9G 2.3G 524M 82% /home [root@weekend110 ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. [root@weekend110 ~]# mkfs -t ext4 /dev/sdb1 //格式化主分區 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655776 inodes, 2622603 blocks 131130 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2688548864 81 block groups 32768 blocks per group, 32768 fragments per group 8096 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@weekend110 ~]# mkfs -t ext4 /dev/sdb5 mke2fs 1.41.12 (17-May-2010) /dev/sdb5 is mounted; will not make a filesystem here! [root@weekend110 ~]# mkfs -t ext4 /dev/sdb6 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 523264 inodes, 2092458 blocks 104622 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2143289344 64 block groups 32768 blocks per group, 32768 fragments per group 8176 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@weekend110 ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. [root@weekend110 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 16G 3.7G 12G 25% / tmpfs 931M 72K 931M 1% /dev/shm /dev/sda1 194M 30M 155M 16% /boot /dev/sda2 2.9G 2.3G 524M 82% /home [root@weekend110 ~]#
依然,還是解決不了。
[root@weekend110 ~]# mount /dev/sdb1 /home //掛載分區/dev/sdb1到掛載點/home [root@weekend110 ~]# mount /dev/sda5 on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) /dev/sda2 on /home type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/sdb1 on /home type ext4 (rw) [root@weekend110 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 16G 3.7G 12G 25% / tmpfs 931M 72K 931M 1% /dev/shm /dev/sda1 194M 30M 155M 16% /boot /dev/sda2 9.9G 151M 9.3G 2% /home /dev/sdb1 9.9G 151M 9.3G 2% /home [root@weekend110 ~]#
至於,刪除磁盤分區,為什么呢?
答:在實際工作中,我們需要創建的分區來存放不同的數據和文件。當這些數據不再需要時,這個專門存儲這些數據和文件的分區幾乎沒有存在的意義。而對於這些沒有存在意義的分區,則需要將其刪除,方便管理分區。
刪除磁盤分區,很簡單,這里不多贅述。
后面我在自己實驗室里,嘗試成功。如下
如何在ubuntu系統里面用新加裝的硬盤對系統進行擴容
磁盤空間管理
不論是操作系統的磁盤空間有多大,在使用過程中可用空間總會不斷減小,雖然在磁盤空間已滿的情況下可把數據另存到其他的磁盤,但在實際的生產環境下,數據是連續的,因此對於某個位置下的數據,是不能將其中的某些部分移到其他的磁盤中存放的。
要保證數據的連續性,而磁盤的可用空間又不斷減少,雖然可用加磁盤,但並不能保證數據的連續性。而且對於海量的數據,僅靠單個磁盤的空間是不能存儲的,即使使用多塊磁盤拼接在一起形成RIAD即廉價磁盤冗余陣列,固定的磁盤空間也並不能無限地存儲不斷增長的數據。
對於這個問題,在Linux系統中可以使用邏輯卷的方式來解決。Linux系統支持對邏輯卷空間不斷地擴展,並且實現在線的方式擴展。
1、磁盤分區擴容
2、擴展交換分區空間
參考博客:
http://www.3fwork.com/b902/002559MYM000559/
http://www.linuxdiyf.com/viewarticle.php?id=312338
http://www.mincoder.com/article/3454.shtml
http://bbs.51cto.com/thread-1118884-1.html
同時,大家可以關注我的個人博客:
http://www.cnblogs.com/zlslch/ 和 http://www.cnblogs.com/lchzls/ http://www.cnblogs.com/sunnyDream/
詳情請見:http://www.cnblogs.com/zlslch/p/7473861.html
人生苦短,我願分享。本公眾號將秉持活到老學到老學習無休止的交流分享開源精神,匯聚於互聯網和個人學習工作的精華干貨知識,一切來於互聯網,反饋回互聯網。
目前研究領域:大數據、機器學習、深度學習、人工智能、數據挖掘、數據分析。 語言涉及:Java、Scala、Python、Shell、Linux等 。同時還涉及平常所使用的手機、電腦和互聯網上的使用技巧、問題和實用軟件。 只要你一直關注和呆在群里,每天必須有收獲
對應本平台的討論和答疑QQ群:大數據和人工智能躺過的坑(總群)(161156071)