寫下來, 以後比較好找...(明明就是懶的再爬一次文...XD)
如果你跟我一樣, 平時以windows為主要作業系統, 有時又需要linux的環境, 除了安裝多重開機系統外(但只同一時間只能選一種作業系統使用), 另一種選擇就是安裝虛擬機(virtual machine); 常見虛擬機有VM ware 或是Virtual Box. 又因Virtualbox是freeware, 所以很自然地, 我就使用它啦! (我愛freeware~~:D)
然而, virtualbox內的OS跑久了, vdi檔就會變得肥大, 即使在virtualbox內已經把用不著的肥大檔案刪除了, 仍不見vdi檔跟著變小; virtualbox自己有提供VBoxManage的指令來重整夯實vdi檔, 不過對於ext檔案系統, Vbox Manage只會壓縮zeroblock, 所以想要有效幫vdi檔減肥, 得多一個步驟: 先將沒用到的block都標示成zero.
也就是說, 我們要作的就兩大步驟:
1. 用zerofree 來將沒有用到的block標示成0 (zeroblock),
2. 用 VBoxManage.exe 來把zeroblock壓縮.
因為我在vbox上跑的另一個系統是ubuntu, 所以以下也就依ubuntu來說明步驟.
1. 用zerofree 來將沒有用到的block標示成0 (zeroblock)
(1) 在vbox上用iso檔開機
我的方式是去下載ubuntu的iso檔, 然後把它mount到vbox的CD, 再次開機時, 它就自動從iso檔開機了, 它會問你是要試用或安裝ubuntu, 請選擇試用, 因為我們只是需要另一個系統來執行zerofree.
mount the ubuntu iso file to vbox CD rom:
(2)進到live CD ubuntu後, 開啟"terminal",
a. install zerofree
sudo apt-get install zerofree
b. mount the rootfs which you want to compress.
(a) you need to find your unbuntu device name. Mine is /dev/sda1.
(b) mount the ubuntu device to /mnt of LiveCD as read only.
sudo mkdir /mnt/sda1
sudo mount -n -o ro -t ext4 /dev/sda1 /mnt/sda1
c. execute the zerofree
sudo /mnt/sda1/usr/sbin/zerofree -v /dev/sda1
(-v to show the progress ).
(a) you need to find your unbuntu device name. Mine is /dev/sda1.
(b) mount the ubuntu device to /mnt of LiveCD as read only.
sudo mkdir /mnt/sda1
sudo mount -n -o ro -t ext4 /dev/sda1 /mnt/sda1
c. execute the zerofree
sudo /mnt/sda1/usr/sbin/zerofree -v /dev/sda1
(-v to show the progress ).
2. 用 VBoxManage.exe 來把zeroblock壓縮.
(1) find the location which you install the Vbox. Mine is under “c:\Program Files\Oracle\VirtualBox”. We need the path to find the VBoxManage.exe.
(2) use VBoxManage.exe to compress the zeroblock.
C:\Users\JW\VirtualBox VMs>"c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvdi ubuntu12.04\ubuntu12.04.3.vdi compact
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
C:\Users\JW\VirtualBox VMs>"
in my case, the images size were below.
before: 92GB
after: 70GB
沒有留言:
張貼留言