{"id":295,"date":"2013-05-14T05:00:09","date_gmt":"2013-05-14T12:00:09","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=295"},"modified":"2014-06-05T08:39:42","modified_gmt":"2014-06-05T15:39:42","slug":"booting-ubuntu-on-a-zfs-root-file-system","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/booting-ubuntu-on-a-zfs-root-file-system\/","title":{"rendered":"Booting Ubuntu on a ZFS Root File System"},"content":{"rendered":"
I recently tried booting Ubuntu 13.04 with a zfs root file system; after the zfs 0.6.1 kernel module was released. \u00a0I set this up as a guest on Virtualbox. \u00a0Please read the instructions here for Ubuntu:<\/p>\n
https:\/\/github.com\/zfsonlinux\/pkg-zfs\/wiki\/HOWTO-install-Ubuntu-to-a-Native-ZFS-Root-Filesystem<\/a><\/p>\n Above link is very accurate for Ubuntu but I had just a couple small differences for Ubuntu 13.04 64-bit.<\/p>\n System Requirements<\/span><\/p>\n Step 1: Prepare The Install Environment<\/span><\/p>\n 1.1 Start the Ubuntu LiveCD and open a terminal at the desktop.<\/p>\n 1.2 Switch to a text terminal using Control-F2. \u00a0Shutdown X and Unity. \u00a0Input these commands at the terminal prompt:<\/p>\n 1.3 Check that the ZFS filesystem is installed and available:<\/p>\n 2.1 Use fdisk to create two partitions (100MB boot and 4G root)<\/span>\u00a0on the primary storage device. \u00a0You can expand the root volume later. \u00a0Device was <\/span> The partition table should look like this:<\/span><\/p>\n 3.1 Format the small boot partition created by Step 2.2 as a filesystem that has stage1 GRUB support like this:<\/p>\n 3.2 Create the root pool on the larger partition:<\/p>\n 3.3 Create a \"ROOT\" filesystem in the root pool:<\/span><\/p>\n 3.4 Create a descendant filesystem for the Ubuntu system:<\/p>\n 3.5 Dismount all ZFS filesystems.<\/span><\/p>\n 3.6 Set the\u00a0 3.7 Set the\u00a0 3.8 Export the pool:<\/span><\/p>\n Don't skip this step. The system is put into an inconsistent state if this command fails or if you reboot at this point.<\/p>\n 4.1 Import the pool:<\/span><\/p>\n 4.2 Mount the small boot filesystem for GRUB that was created in step 3.1:<\/p>\n 4.4 Install the minimal system:<\/p>\n 5.1 Copy these files from the LiveCD environment to the new system:<\/p>\n 5.2 The\u00a0 5.3 Edit the\u00a0<\/span> Customize this file if the new system is not a DHCP client on the LAN. \u00a0After you have rebooted and you want network-manager to manage your network connection remove eth0 again.<\/p>\n 5.4 Make virtual filesystems in the LiveCD environment visible to the new system and\u00a0 5.5 Install PPA support in the chroot environment like this:<\/p>\n 5.6 Install ZFS in the chroot environment for the new system:<\/span><\/p>\n Choose\u00a0<\/span> 5.7 Set a root password on the new system:<\/p>\n Hint:<\/strong>\u00a0If you want the ubuntu-desktop package, then install it after the first reboot. If you install it now, then it will start several process that must be manually stopped before dismount.<\/p>\n Remember:<\/strong>\u00a0All of Step 6 depends on Step 5.4 and must happen inside the chroot environment.<\/p>\n 6.1 Verify that the ZFS root filesystem is recognized by GRUB and that the ZFS modules for GRUB are installed:<\/p>\n 6.2 Refresh the initrd files:<\/span><\/p>\n 6.3 Update the boot configuration file:<\/p>\n Verify that\u00a0 Update 1:<\/strong><\/span><\/p>\n If you have issues booting on Ubuntu 13.04 I temporarily fixed two lines manually for the first boot and then once logged in I fixed \/boot\/grub\/grub.cfg as follow for subsequent boots:<\/p>\n Update 2:<\/strong><\/span><\/p>\n Grub issue on Ubuntu 13.04 is being worked:\u00a0https:\/\/github.com\/zfsonlinux\/zfs\/issues\/1441<\/a><\/p>\n 6.4 Now install the boot loader to the MBR like this:<\/p>\n Do not reboot the computer until you get exactly that result message. Note that you are installing the loader to the whole disk, not a partition.<\/p>\n\n
$ sudo -i\r\n# \/etc\/init.d\/lightdm stop\r\n# apt-add-repository --yes ppa:zfs-native\/stable\r\n# apt-get update\r\n# apt-get install debootstrap ubuntu-zfs\r\n<\/pre>\n
# modprobe zfs\r\n# dmesg | grep ZFS:\r\nZFS: Loaded module v0.6.1-rc14, ZFS pool version 5000, ZFS filesystem version 5\r\n<\/pre>\n
<\/h2>\n
<\/a>Step 2: Disk Partitioning<\/h2>\n
\/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252<\/code>\u00a0in my case. \u00a0Your disk names will vary.<\/span><\/p>\n
\r\nroot@ubuntu:~# fdisk -l \/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252\r\nDisk \/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252: 8589 MB, 8589934592 bytes\r\nDevice Boot Start End Blocks Id System\r\n\/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252-part1 * 63 96389 48163+ be Solaris boot\r\n\/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252-part2 96390 7903979 3903795 bf Solaris\r\n<\/pre>\n
<\/a>Step 3: Disk Formatting<\/h2>\n
\r\n# mke2fs -m 0 -L \/boot\/grub -j \/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252-part1\r\n<\/pre>\n
\r\n# zpool create -o ashift=9 rpool \/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252-part2\r\n<\/pre>\n
\r\n# zfs create rpool\/ROOT\r\n<\/pre>\n
\r\n# zfs create rpool\/ROOT\/ubuntu-1\r\n<\/pre>\n
\r\n# zfs umount -a\r\n<\/pre>\n
mountpoint<\/code>\u00a0property on the root filesystem:<\/p>\n
\r\n# zfs set mountpoint=\/ rpool\/ROOT\/ubuntu-1\r\n<\/pre>\n
bootfs<\/code>\u00a0property on the root pool.<\/p>\n
\r\n# zpool set bootfs=rpool\/ROOT\/ubuntu-1 rpool\r\n<\/pre>\n
\r\n# zpool export rpool\r\n<\/pre>\n
<\/h2>\n
<\/a>Step 4: System Installation<\/h2>\n
\r\n# zpool import -d \/dev\/disk\/by-id -R \/mnt rpool\r\n<\/pre>\n
\r\n# mkdir -p \/mnt\/boot\/grub\r\n# mount \/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252-part1 \/mnt\/boot\/grub\r\n<\/pre>\n
\r\n# debootstrap raring \/mnt\r\n<\/pre>\n
<\/h2>\n
<\/a>Step 5: System Configuration<\/h2>\n
\r\n# cp \/etc\/hostname \/mnt\/etc\/\r\n# cp \/etc\/hosts \/mnt\/etc\/\r\n<\/pre>\n
\/mnt\/etc\/fstab<\/code>\u00a0file should be empty except for a comment. Add this line to the\u00a0
\/mnt\/etc\/fstab<\/code>\u00a0file:<\/p>\n
\r\n\/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252-part1 \/boot\/grub auto defaults 0 1\r\n<\/pre>\n
\/mnt\/etc\/network\/interfaces<\/code>\u00a0file so that it contains something like this:<\/span><\/p>\n
\r\n# interfaces(5) file used by ifup(8) and ifdown(8)\r\nauto lo\r\niface lo inet loopback\r\n\r\nauto eth0\r\niface eth0 inet dhcp\r\n<\/pre>\n
chroot<\/code>\u00a0into it:<\/p>\n
\r\n# mount --bind \/dev \/mnt\/dev\r\n# mount --bind \/proc \/mnt\/proc\r\n# mount --bind \/sys \/mnt\/sys\r\n# chroot \/mnt \/bin\/bash --login\r\n<\/pre>\n
\r\n# locale-gen en_US.UTF-8\r\n# apt-get update\r\n# apt-get install ubuntu-minimal software-properties-common\r\n<\/pre>\n
\r\n# apt-add-repository --yes ppa:zfs-native\/stable\r\n# apt-add-repository --yes ppa:zfs-native\/grub\r\n# apt-get update\r\n# apt-get install --no-install-recommends linux-image-generic linux-headers-generic\r\n# apt-get install ubuntu-zfs\r\n# apt-get install grub2-common grub-pc\r\n# apt-get install zfs-initramfs\r\n# apt-get dist-upgrade\r\n<\/pre>\n
\/dev\/sda<\/code>\u00a0if prompted to install the MBR loader.<\/span><\/p>\n
\r\n# passwd root\r\n<\/pre>\n
<\/h2>\n
<\/a>Step 6: GRUB Installation<\/h2>\n
\r\n# grub-probe \/\r\nzfs\r\n\r\n# ls \/boot\/grub\/i386-pc\/zfs*\r\n\/boot\/grub\/i386-pc\/zfs.mod \/boot\/grub\/i386-pc\/zfsinfo.mod<\/code>\r\n<\/pre>\n
\r\n# update-initramfs -c -k all\r\n<\/pre>\n
\r\n# update-grub\r\n<\/pre>\n
boot=zfs<\/code>\u00a0appears in the boot configuration file:<\/p>\n
\r\n# grep boot=zfs \/boot\/grub\/grub.cfg\r\nlinux \/ROOT\/ubuntu-1\/@\/boot\/vmlinuz-3.8.0-19-generic root=\/dev\/sda2 ro boot=zfs $bootfs quiet splash $vt_handoff\r\nlinux \/ROOT\/ubuntu-1\/@\/ROOT\/ubuntu-1@\/\/boot\/vmlinuz-3.8.0-19-generic root=ZFS=rpool\/ROOT\/ubuntu-1\/@\/ROOT\/ubuntu-1 ro boot=zfs $bootfs quiet splash $vt_handoff\r\nlinux \/ROOT\/ubuntu-1\/@\/ROOT\/ubuntu-1@\/\/boot\/vmlinuz-3.8.0-19-generic root=ZFS=rpool\/ROOT\/ubuntu-1\/@\/ROOT\/ubuntu-1 ro single nomodeset boot=zfs $bootfs\r\n<\/pre>\n
#linux \/ROOT\/ubuntu-1\/@\/ROOT\/ubuntu-1@\/\/boot\/vmlinuz-3.8.0-19-generic root=ZFS=rpool\/ROOT\/ubuntu-1\/@\/ROOT\/ubuntu-1 ro boot=zfs $bootfs quiet splash $vt_handoff\r\nlinux \/ROOT\/ubuntu-1\/@\/boot\/vmlinuz-3.8.0-19-generic root=\/dev\/sda2 ro boot=zfs $bootfs quiet splash $vt_handoff\r\n\r\n#initrd \/ROOT\/ubuntu-1\/@\/ROOT\/ubuntu-1@\/\/boot\/initrd.img-3.8.0-19-generic\r\ninitrd \/ROOT\/ubuntu-1\/@\/boot\/initrd.img-3.8.0-19-generic\r\n<\/pre>\n
# grub-install $(readlink -f \/dev\/disk\/by-id\/scsi-SATA_VBOX_HARDDISK_VBb59e0ffb-68fb0252)\r\nInstallation finished. No error reported.\r\n<\/code><\/pre>\n