2015年8月24日 星期一

利用 overlayfs 將 filesystem.squafs 與 casper-rw 合併成新的 filesystem.squasfs

參考文章:
http://davstott.me.uk/index.php/2013/09/05/ubuntu-13-04-on-a-usb-flash-drive-and-merging-its-persistent-storage.


太實用了! 改天來玩玩,
這樣就無需將 filesystem.squashfs 解壓縮再重裝, 那麼麻煩, 直接用 iso 檔開機, 刪刪減減, 再將他合併, 改成符合自己所適用的作業系統

重點節錄:
假設 persistent storage 放在 /dev/sdb2
sudo su
cd /mnt
mkdir  ro.dir  rw.dir  new.dir
mount /dev/sdb2  rw.dir
mount  -o  loop  filesystem.squashfs  ro.dir
mount  -o  lowerdir=ro.dir,upperdir=rw.dir  -t  overlayfs  none  new.dir
mksquashfs new.dir filesystem.squashfs

chroot new.dir dpkg-query -W --showformat='${Package} ${Version}\n' > filesystem.manifest
printf $(du -sx --block-size=1 new.dir | cut -f1) > filesystem.size

p.s. Linux mint 17.2 已經內建 overlayfs, 可以利用它來運作

2015年8月23日 星期日

Linux mint 無需安裝, 直接使用 LiveCD iso 檔開機, 並讓它擁有永久存放檔案的能力

1. 先規劃好一塊硬碟分區, 因為我的 DRAM 有 8G 空間, 原先 /dev/sdb2 預備當成 swap 分區, 我想 Livecd 應該不需要, 於是我直接將此分區約 2G bytes 空間廢棄, 直接將他改成 ext3 分區來使用, 於是用先 fdisk 將 partition type 0x82 改成 0x83, 接著將他 format 成 ext3 檔案系統(mkfs.ext3 /dev/sdb2). 最後重要的是將他 label 命名成 casper-rw  
tune2fs -L casper-rw /dev/sdb2
或者
e2label /dev/sdb2 casper-rw  
2. 我將整個 cdrom 直接複製到 /dev/sda2/boot/ 目錄內
mount /dev/sda2 /mnt  
dd if=/dev/sr0      of=/mnt/boot/linuxmint172.iso
3. 我使用 Grub 2 的 boot loader, 在 boot option 增加 persistent 字眼
menuentry "Linux Mint 17.2" {  
set root=(hd0,2)  
loopback loop (hd0,2)/boot/linuxmint172.iso
linux        (loop)/casper/vmlinuz boot=casper persistent iso-scan/filename=/boot/linuxmint172.iso ro quiet splash locale=zh_TW.UTF-8    
initrd        (loop)/casper/initrd.lz    
}
4. 大功告成, Linux mint 無需安裝到硬碟中, 只要將 cdrom 的轉成 iso 檔, 複製到 /boot/ 目錄內就好, 且以後任何 linux 系統內任何修改過的資料, 全部都會更新到 /dev/sdb2 中了

2015年8月16日 星期日

試用 linux mint 17.2

重裝 Linux Mint 的方式大致上與重裝 Ubuntu 一樣,
可參考:How to customize Linux Mint live cd/dvd:
http://community.linuxmint.com/tutorial/view/1784
感覺還不錯用, 但是在 zh.TW-UTF8 中文介面, 開啟 terminal, 有些英文字(m 或 w)會與旁邊的字擠成一起, 造成辨識困難.
後來上 google 終於解決了, 只要直接下兩條命令來更改字型便可(特別注意: 千萬不要使用 root 來執行):
gconftool-2 --set /apps/gnome-terminal/profiles/Default/use_system_font --type=boolean false
gconftool-2 --set /apps/gnome-terminal/profiles/Default/font --type string "Liberation Mono 11"
整個操作很像在使用 Windows XP 的感覺, 但無內建中文輸入法, 只好自行再重新封裝加入 gcin:
apt-get install gcin
之後變可以很順利的使用了. 免錢的 OS, 值得推荐.
另外找到 Monaco 字型也可以直接套用, 需先將字型放入 ~/.fonts 或 /usr/share/fonts/truetype 目錄內,並執行 fc-cache -vf 後, 再套用上述兩條命令
gconftool-2 --set /apps/gnome-terminal/profiles/Default/use_system_font --type=boolean false
gconftool-2 --set /apps/gnome-terminal/profiles/Default/font --type=string "Monaco 11"
最後我用 isolinux 製作開機光碟, 將所有檔案放入 isodir 目錄裡, 之後執行 mkisofs:
sudo mkisofs -r -V "Linux Mint 17.2" -cache-inodes -J -l -o linux172.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table isodir
附註1. isolinux 網址: http://www.syslinux.org/wiki/index.php/The_Syslinux_Project
使用 ISOLINUX 時的目錄及檔案結構:
isodir
isodir/isolinux
isodir/isolinux/isolinux.bin
isodir/isolinux/ldlinux.c32
isodir/isolinux/isolinux.cfg
casper
casper/vmlinuz
casper/initrd.lz
casper/filesystem.squashfs
casper/filesystem.manifest
.disk
.disk/casper-uuid-generic
如果是用 GRUB 2 來製作開機光碟, 將所有檔案放入 isodir 目錄裡, 之後再執行 grub-mkrescue
sudo grub-mkrescue -o linux172.iso isodir
附註2. apt-get install xorriso 安裝後, 才可以使用 grub-mkrescue
參考 grub-mkrescue 網址 https://www.gnu.org/software/grub/manual/html_node/Invoking-grub_002dmkrescue.html
使用 GRUB 2 時的目錄及檔案結構:
isodir
isodir/boot
isodir/boot/grub
isodir/boot/grub/grub.cfg
casper
casper/vmlinuz
casper/initrd.lz
casper/filesystem.squashfs
casper/filesystem.manifest
.disk
.disk/casper-uuid-generic

附註3. 如要移除桌面上的 "安裝" 按鈕需要執行在重新封裝(remaster)時將 ubituity 移除
apt-get remove ubiquity

改裝的 Linux mint 17.2 iso 檔案

附註4. 如果要 compile grub-2.0 時出現 stdio.in.h 錯誤訊息, 使用 sed 修改檔案內容變可解決:
sed -i -e ‘/gets is a security/d’ grub-core/gnulib/stdio.in.h








































(initramfs) Uable to find a medium containing a live file system

重裝 Ubuntu 時使用 GRUB 2或 ISOLINUX 當 boot loader 時, CDROM 根目錄 忘記將 .disk 目錄從原公版內複製過來時, 裏面有一個重要的檔案叫作 casper-uuid-generic, 內含當初 build 此公版時所創建的 uuid,如缺乏此檔將造成casper無法從此 CDROM 啟動 Ubuntu linux, 解決的方式是在 boot option 增加 ignore_uuid 便 可, 修改 grub.cfg 如下:

menuentry "Ubuntu Linux from CDROM" {

kernel /casper/vmlinuz.efi boot=casper ignore_uuid

initrd /casper/initrd.lz

}

如果是用 isolinux 則直接在 boot: 下命令

boot: kernel /casper/vmlinuz.efi initrd=/casper/initrd.lz boot=casper ignore_uuid

或修改 isolinux.cfg 內容如下:

label ubuntu

kernel /casper/vmlinuz.efi

append initrd=/casper/initrd.lz boot=casper ignore_uuid

應該可以解決