文章出處:http://leonarding.blog.51cto.com/6045525/1177871 Linux系統進行新磁盤分區 [[email protected]~]# fdisk –l 檢查現有系統磁盤空間 Disk/dev/sda: 21.4 GB, 21474836480 bytes 這是我們原來的那塊舊磁盤 255 heads, 63sectors/track, 2610 cylinders Units = cylindersof 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System 舊磁盤就分了 2個分區 /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 2610 20860402+ 8e Linux LVM Disk/dev/sdb: 21.4 GB, 21474836480 bytes 這是我們新添加的磁盤 /dev/sdb,還沒有分區 255 heads, 63sectors/track, 2610 cylinders Units = cylindersof 16065 * 512 = 8225280 bytes Disk /dev/sdbdoesn't contain a valid partition table 不包含有效分區表資訊,我們需要給新磁盤建立分區表 Disk /dev/dm-0:18.2 GB, 18253611008 bytes 下面這些都不用管 255 heads, 63sectors/track, 2219 cylinders Units = cylindersof 16065 * 512 = 8225280 bytes Disk /dev/dm-0doesn't contain a valid partition table Disk /dev/dm-1:3087 MB, 3087007744 bytes 255 heads, 63sectors/track, 375 cylinders Units = cylindersof 16065 * 512 = 8225280 bytes Disk /dev/dm-1doesn't contain a valid partition table [[email protected]~]# fdisk /dev/sdb sdb磁盤分區,有很多選項,我們選擇 m幫助資訊 Device containsneither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOSdisklabel. Changes will remain in memory only, until you decideto write them. After that, of course, the previous content won't be recoverable. The number ofcylinders for this disk is set to 2610. There is nothingwrong with that, but this is larger than 1024, and could incertain setups cause problems with: 1) software thatruns at boot time (e.g., old versions of LILO) 2) booting andpartitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Warning: invalidflag 0x0000 of partition table 4 will be corrected by w(rite) Command (m forhelp): m 選擇 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 forhelp): n 建立一個新分區 Command action e extended p primary partition (1-4) p 選擇 p添加主分區 Partition number(1-4): 1 選擇主分區編号為 1, 這樣建立後的主分區為 sdb1 First cylinder(1-2610, default 1): 選擇格式化分區從第幾個柱面開始 Using defaultvalue 1 直接“回車”預設從第 1個柱面開始 Last cylinder or+size or +sizeM or +sizeK (1-2610, default 2610): 選擇格式化分區從第幾個柱面結束 Using defaultvalue 2610 直接“回車”預設從最後 1個柱面結束 我們把所有 20GB空間都格式化為一個分區了,如果有朋友想劃分多個分區,如下方法 Last cylinder or+size or +sizeM or +sizeK (1-2610, default 2610): 以 MB為機關輸入自己想要的大小即可 這樣我們就建立完一個分區,如果要建立更多分區可以照上面的步驟繼續建立。 Command (m forhelp): w 鍵入 w,儲存設定并退出,完成新磁盤分區表建立 The partitiontable has been altered! Calling ioctl() tore-read partition table. Syncing disks. [[email protected]~]# fdisk –l 我們在看一下系統磁盤空間配置設定情況 Disk /dev/sda:21.4 GB, 21474836480 bytes 255 heads, 63sectors/track, 2610 cylinders Units = cylindersof 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 2610 20860402+ 8e Linux LVM Disk/dev/sdb: 21.4 GB, 21474836480 bytes 這時我們可以看到新磁盤已經加入分區表了 255heads, 63 sectors/track, 2610 cylinders Units =cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 2610 20964793+ 83 Linux 下面我們給新磁盤的 /dev/sdb1分區進行格式化操作 [[email protected]~]# mkfs -t ext4 /dev/sdb1 用 ext4格式對 /dev/sdb1分區進行格式化 mke4fs 1.41.12(17-May-2010) Filesystem label= OS type: Linux 作業系統類型 Linux Block size=4096(log=2) 作業系統塊大小 4k Fragment size=4096(log=2) Stride=0 blocks,Stripe width=0 blocks 1310720 inodes,5241198 blocks 262059 blocks(5.00%) reserved for the super user First data block=0 Maximum filesystemblocks=4294967296 160 block groups 32768 blocks pergroup, 32768 fragments per group 8192 inodes pergroup Superblock backupsstored on blocks: 32768, 98304, 163840, 229376, 294912,819200, 884736, 1605632, 2654208, 4096000 Writing inodetables: done Creating journal(32768 blocks): done Writingsuperblocks and filesystem accounting information: done This filesystemwill be automatically checked every 35 mounts or 180 days,whichever comes first. Use tune4fs -c or-i to override. 到此我們的新分區格式化完畢,下面我們就要挂載上分區就可以使用啦! [[email protected]~]# df –h 這是我們還沒有挂載新分區之前的挂載點分布 Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 17G 15G 1.6G 90% / /dev/sda1 99M 23M 71M 25% /boot tmpfs 731M 320M 411M 44% /dev/shm /dev/sr0 55M 55M 0 100% /media/VBOXADDITIONS_4.2.6_82870 [[email protected]/]# mkdir /u02 在根目錄上建立一個新的挂載目錄 /u02 [[email protected]/]# mount /dev/sdb1 /u02 将新磁盤分區挂載到 /u02目錄下 [[email protected]/]# df –h 這是我們挂載新分區之後的挂載點分布 Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 17G 15G 1.6G 90% / /dev/sda1 99M 23M 71M 25% /boot tmpfs 731M 320M 411M 44% /dev/shm /dev/sr0 55M 55M 0 100% /media/VBOXADDITIONS_4.2.6_82870 /dev/sdb1 20G 172M 19G 1% /u02 現在我們可以正常使用新添加的磁盤空間了 [[email protected]/]# cd /u02 [[email protected]]# mkdir app 建立一個 app目錄試試 [[email protected]]# ll total 20 drwxr-xr-x 2 rootroot 4096 Apr 14 09:12 app ok成功建立木有問題 drwx------ 2 rootroot 16384 Apr 14 08:59 lost+found 到此 Virtualbox中 Linux添加一個新磁盤 ->建立分區 ->格式化 ->挂載分區系列操作完畢
開機自動挂載新磁盤分區 /dev/sdb1 [[email protected] /]# vim /etc/fstab 修改檔案,在檔案最後新增一行 /dev/VolGroup00/LogVol00 / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 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/VolGroup00/LogVol01 swap swap defaults 0 0 /dev/sdb1 /u02 ext4 defaults 0 0 這樣在重新開機系統後就會自動挂載到 /u02目錄上