歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu搬遷:從虛擬磁盤到真實的分區

Ubuntu搬遷:從虛擬磁盤到真實的分區

日期:2017/2/28 16:51:40   编辑:Linux教程

Ubuntu為了增強Windows用戶的體驗,拉攏Windows用戶加入到linux陣營,做了一些重要改進:允許直接在Windows下安裝Ubuntu,就是運行安裝盤中那個叫做wubi.exe的Windows執行程序;允許Windows用戶在沒有剩余未分區磁盤空間的情況下,將Ubuntu安裝在Windows分區的一個文件內(類似vmware的虛擬硬盤)。

我當初也是直接在Windows下安裝的,用了一段時間後,覺得Ubuntu8.04很不錯,就想將它從虛擬文件中搬移出來,直接存放到我新建的分區下以提高Ubuntu的磁盤訪問性能。畢竟虛擬磁盤沒有真正的磁盤快。經過了一天的研究,最終搬遷成功了,拿出來和大家一起分享。寫此文的目的不是鼓勵大家也和我一樣也進行類似的搬遷行為,只是和大家一起學習,更能認識到linux操作系統的一些特長和技術。

步驟如下:

一、創建新分區

( 因為本人安裝Windows時將磁盤的最後50G沒有分區,留作以後它用,所以有剩余空間創建新分區)

創建分區需要在Ubuntu操作系統下進行,命令為:
sudo fdisk /dev/sda

具體操作見下邊:
administrator@administrator-desktop:~$ sudo fdisk /dev/sda

The number of cylinders for this disk is set to 19457.
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)

Command (m for help): p

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x1e851e84

Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10241406 7 HPFS/NTFS
/dev/sda2 1276 18355 137195100 f W95 Ext'd (LBA)
/dev/sda5 1276 2550 10241406 7 HPFS/NTFS
/dev/sda6 2551 6374 30716248+ 7 HPFS/NTFS
/dev/sda7 6375 8924 20482843+ b W95 FAT32

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (10750-18355, default 10750):
Using default value 10750
Last cylinder or +size or +sizeM or +sizeK (10750-18355, default 18355): +14G

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 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
administrator@administrator-desktop:~$

說明:
進入fdisk後,出現提示符Command (m for help):要求輸入命令,常用命令如下:
p 顯示已有分區
n 創建新分區
m 顯示幫助
w 將改動寫入磁盤

二、格式化新建分區
創建分區後使用fdisk 的p命令再次顯示分區情況,如下:
/dev/sda1 * 1 1275 10241406 7 HPFS/NTFS
/dev/sda2 1276 18355 137195100 f W95 Ext'd (LBA)
/dev/sda5 1276 2550 10241406 7 HPFS/NTFS
/dev/sda6 2551 6374 30716248+ 7 HPFS/NTFS
/dev/sda7 6375 8924 20482843+ b W95 FAT32
/dev/sda8 8925 10749 14659281 83 Linux

可以看到新分區的設備號為/dev/sda8 ,格式化它!命令為 sudo mkfs -j /dev/sda8

格式化完成後重啟一次。

Copyright © Linux教程網 All Rights Reserved