Ubuntu Live CD root > 4G

Loading

Ubuntu 的 Desktop 版本就是 LiveCD ,這 Live CD 可以裝在 USB Key 隨身碟上,但這 Ubuntu Live CD USB flash drive 有個問題,就是 root 沒有辦法大於 > 4G ,這是為什麼呢!!

因為 Ubuntu Desktop 做成 Ubuntu Live CD USB flash drive 時,會將磁區分割成為 vfat ,而 root 檔案會寫成一個 loop file ( casper-rw) ,但 vfat 的檔案上限就是 4G ,如果要讓 root 大於 4g 必須用其他方式來做.

參考了下面幾個網站的說明.
http://ubuntu-usb-large-persistent-storage.blogspot.tw/
http://www.pendrivelinux.com/create-a-larger-than-4gb-casper-partition/

步驟如下:

  1. 刪除 casper-rw
  2. 縮小 Ubuntu Live CD USB flash drive vfat 磁區大小(預設會佔用全部的 USB flash drive 空間)
  3. 新增一 ext2 (3)(4) 磁區,標籤為 casper-rw (系統會把這磁區當作 root)

第一步先做好你的 Ubuntu Live CD USB flash drive ,可以透過 Universal USB Installer (Windows) 或是 Startup Disk Creator (Linux) ,方式請參考 Ubuntu Live CD on USB flash drive – https://benjr.tw/1550
透過 Universal-USB-Installer 將 Live CD 轉換成 Ubuntu Live USB Drive 需要注意的是第四步.
Step 4: Set a persistent file size for storing changes 設定預留 Ubuntu 的 root 空間大小. 一定要預留空間 (最大只能選擇到 4G)
parted01

  1. 刪除 casper-rw
    先找一台 Linux 系統或是 windows 都可以,把這 Ubuntu Live CD USB flash drive 內的 casper.rw (root loop file 檔案) 刪除 ,沒有這檔案請重做 Ubuntu Live USB Drive.

    [root@Benjr ~]# mount
    /dev/mapper/VolGroup-lv_root 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/mapper/VolGroup-lv_home on /home type ext4 (rw)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /tmp on /tmp type none (rw,bind)
    /var/tmp on /var/tmp type none (rw,bind)
    /home on /home type none (rw,bind)
    none on /sys/kernel/config type configfs (rw)
    gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
    /dev/sdb1 on /media/77D1-8400 type vfat (rw,nosuid,nodev,uhelper=udisks,uid=0,gid=0,shortname=mixed,dmask=0077,utf8=1,flush)
    
    [root@Benjr ~]# rm /media/77D1-8400/casper.rw
    
  2. 縮小 Ubuntu Live CD USB flash drive vfat 磁區大小
    預設 Ubuntu Live CD USB flash drive 會佔用全部的 USB flash drive 空間,第一步先縮小 Ubuntu Live CD USB flash drive vfat 磁區大小,但這一步搞好久才試成功

    這一步主要是透過 parted 的 resize (GParted 圖形介面) 來縮小 Ubuntu Live CD USB flash drive vfat 磁區,但不知道為什麼在 Ubuntu 14.04 (RHEL 7) 下面 resize 沒有辦法使用 (仔細一看說明,resize 將不再支援,建議用戶用 e2fsprogs 套件做放大縮小磁區 ),但在 RedHat (RHEL) 6.5 下使用就沒有問題.

    • Ubuntu 14.04 resize 會失敗.
      root@ben:~# parted /dev/sdc
      GNU Parted 2.3
      Using /dev/sdc
      Welcome to GNU Parted! Type 'help' to view a list of commands.
      (parted) print                                                            
      Model: ADATA USB Flash Drive (scsi)
      Disk /dev/sdc: 15.5GB
      Sector size (logical/physical): 512B/512B
      Partition Table: msdos
      
      Number  Start   End     Size    Type     File system  Flags
       1      1049kB  15.5GB  15.5GB  primary  fat32
      
      (parted) resize 1 1049k 2048M                                             
      WARNING: you are attempting to use parted to operate on (resize) a file system.
      parted's file system manipulation code is not as robust as what you'll find in
      dedicated, file-system-specific packages like e2fsprogs.  We recommend
      you use parted only to manipulate partition tables, whenever possible.
      Support for performing most operations on most types of file systems
      will be removed in an upcoming release.
      parted: malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1)) & ~((2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)' failed.
      Aborted (core dumped)
      
    • RHEL 7 下進入 parted 裡面找不到 resize 的功能.
    • RedHat (RHEL) 6.5 可以使用.
    • 關於 parted 使用,詳細說明請參考 放大縮小 Linux 磁區 https://benjr.tw/94843

      [root@Benjr ~]# parted /dev/sdb
      GNU Parted 2.1
      Using /dev/sdb
      Welcome to GNU Parted! Type 'help' to view a list of commands.
      (parted) p                                                                
      Model: SanDisk Ultra USB 3.0 (scsi)
      Disk /dev/sdb: 30.8GB
      Sector size (logical/physical): 512B/512B
      Partition Table: msdos
      
      Number  Start   End     Size    Type     File system  Flags
       1      1049kB  30.7GB  30.7GB  primary  fat32        boot
      
      (parted) resize                                                           
      WARNING: you are attempting to use parted to operate on (resize) a file system.
      parted's file system manipulation code is not as robust as what you'll find in
      dedicated, file-system-specific packages like e2fsprogs.  We recommend
      you use parted only to manipulate partition tables, whenever possible.
      Support for performing most operations on most types of file systems
      will be removed in an upcoming release.
      Partition number? 1                                                       
      Start?  [1049kB]?                                                         
      End?  [1200MB]? 2G                                                        
      (parted) p                                                                
      Model: SanDisk Ultra USB 3.0 (scsi)
      Disk /dev/sdb: 30.8GB
      Sector size (logical/physical): 512B/512B
      Partition Table: msdos
      
      Number  Start   End     Size    Type     File system  Flags
       1      1049kB  2000MB  1999MB  primary  fat32        boot
      
      (parted) q                                                                
      Information: You may need to update /etc/fstab.     
      

    其實還可以透過 Windows 下的一些免費工具來修改 fat32 磁區.如:

  3. 新增一 ext2 (3)(4) 磁區,標籤並成為 casper-rw
    當 casper.rw (root loop file 檔案) 沒有的時候,系統會找 標籤為 casper-rw 的磁區當成 root,所以這一步需要新增一 ext2 (3)(4) 磁區,標籤為 casper-rw ,可以透過 parted (GParted 圖形介面) 來做.
    parted02

前面步驟完成後就可以從這一 Ubuntu Live CD USB flash drive 開機吧! 你會發現 root 已經變成 /dev/sda2 , /cow (root) 的大小也變大了.

ubuntu@ubuntu:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/cow             27G   71M   25G   1% /
udev            989M  4.0K  989M   1% /dev
tmpfs           201M  1.1M  199M   1% /run
/dev/sda1       2.1G  986M  1.1G  49% /cdrom
/dev/loop0      939M  939M     0 100% /rofs
none            4.0K     0  4.0K   0% /sys/fs/cgroup
tmpfs          1001M  1.1M 1000M   1% /tmp
none            5.0M     0  5.0M   0% /run/lock
none           1001M   76K 1000M   1% /run/shm
none            100M   60K  100M   1% /run/user
/dev/sda2        27G   71M   25G   1% /media/ubuntu/casper-rw
ubuntu@ubuntu:~$ mount
/cow on / type overlayfs (rw)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
/dev/sda1 on /cdrom type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/dev/loop0 on /rofs type squashfs (ro,noatime)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)
gvfsd-fuse on /run/user/999/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=ubuntu)
/dev/sda2 on /media/ubuntu/casper-rw type ext4 (rw,nosuid,nodev,uhelper=udisks2)
沒有解決問題,試試搜尋本站其他內容

One thought on “Ubuntu Live CD root > 4G

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料