Difference between pages "ZFS as Root Filesystem" and "Install/ru/Partitioning"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
== Introduction ==
<noinclude>
{{InstallPart|процесс разбиения диска и создания файловых систем}}
</noinclude>
=== Подготовка жесткого диска ===


This tutorial will show you how to install Funtoo on ZFS (rootfs). This tutorial is meant to be an "overlay" over the [[Funtoo_Linux_Installation|Regular Funtoo Installation]]. Follow the normal installation and only use this guide for steps 2, 3, and 8.
В этой части  мы научимся различным способам установки Funtoo Linux -- и загрузки с -- жесткого диска.


=== Introduction to ZFS ===
==== Введение ====


Since ZFS is a new technology for Linux, it can be helpful to understand some of its benefits, particularly in comparison to BTRFS, another popular next-generation Linux filesystem:
В прежние времена существовал лишь один способ загрузить PC-совместимый компьютер. Все наши дектопы и сервера имели стандартный PC BIOS, все наши харды использовали MBR и были разбиты используя схему разбивки MBR.  Вот как это все было и нам это нравилось!


* On Linux, the ZFS code can be updated independently of the kernel to obtain the latest fixes. btrfs is exclusive to Linux and you need to build the latest kernel sources to get the latest fixes.
Затем появились EFI и UEFI, встроенные программы нового образца наряду со схемой разбивки GPT, поддерживающая диски размером более 2.2TБ. Неожиданно, нам стали доступны различные способы установки и загрузки Линукс систем . То, что было единым методом, стало чем-то более сложным.


* ZFS is supported on multiple platforms. The platforms with the best support are Solaris, FreeBSD and Linux. Other platforms with varying degrees of support are NetBSD, Mac OS X and Windows. btrfs is exclusive to Linux.
Воспользуемся моментом и рассмотрим доступные способы конфигурации жесткого диска для загрузки Funtoo Linux. This Install Guide uses, and recommends, the old-school method of BIOS booting and using an MBR. It works and (except for rare cases) is universally supported. There's nothing wrong with it. If your system disk is 2TB or smaller in size, it won't prevent you from using all of your disk's capacity, either.


* ZFS has the Adaptive Replacement Cache replacement algorithm while btrfs uses the Linux kernel's Last Recently Used replacement algorithm. The former often has an overwhelmingly superior hit rate, which means fewer disk accesses.
But, there are some situations where the old-school method isn't optimal. If you have a system disk >2TB in size, then MBR partitions won't allow you to access all your storage. So that's one reason. Another reason is that there are some so-called "PC" systems out there that don't support BIOS booting anymore, and force you to use UEFI to boot. So, out of compassion for people who fall into this predicament, this Install Guide documents UEFI booting too.


* ZFS has the ZFS Intent Log and SLOG devices, which accelerates small synchronous write performance.
Our recommendation is still to go old-school unless you have reason not to. The boot loader we will be using to load the Linux kernel in this guide is called GRUB, so we call this method the '''BIOS + GRUB (MBR)''' method. It's the traditional method of setting up a PC-compatible system to boot Linux.


* ZFS handles internal fragmentation gracefully, such that you can fill it until 100%. Internal fragmentation in btrfs can make btrfs think it is full at 10%. Btrfs has no automatic rebalancing code, so it requires a manual rebalance to correct it.
If you need to use UEFI to boot, we recommend not using the MBR at all for booting, as some systems support this, but others don't. Instead, we recommend using UEFI to boot GRUB, which in turn will load Linux. We refer to this method as the '''UEFI + GRUB (GPT)''' method.


* ZFS has raidz, which is like RAID 5/6 (or a hypothetical RAID 7 that supports 3 parity disks), except it does not suffer from the RAID write hole issue thanks to its use of CoW and a variable stripe size. btrfs gained integrated RAID 5/6 functionality in Linux 3.9. However, its implementation uses a stripe cache that can only partially mitigate the effect of the RAID write hole.
And yes, there are even more methods, some of which are documented on the [[Boot Methods]] page. We used to recommend a '''BIOS + GRUB (GPT)''' method but it is not consistently supported across a wide variety of hardware.


* ZFS send/receive implementation supports incremental update when doing backups. btrfs' send/receive implementation requires sending the entire snapshot.
'''The big question is -- which boot method should you use?''' Here's how to tell.


* ZFS supports data deduplication, which is a memory hog and only works well for specialized workloads. btrfs has no equivalent.
;Principle 1 - Old School: If you can reliably boot System Rescue CD and it shows you an initial light blue menu, you are booting the CD using the BIOS, and it's likely that you can thus boot Funtoo Linux using the BIOS. So, go old-school and use BIOS booting, ''unless'' you have some reason to use UEFI, such as having a >2.2TB system disk. In that case, see Principle 2, as your system may also support UEFI booting.


* ZFS datasets have a hierarchical namespace while btrfs subvolumes have a flat namespace.
;Principle 2 - New School: If you can reliably boot System Rescue CD and it shows you an initial black and white menu -- congratulations, your system is configured to support UEFI booting. This means that you are ready to install Funtoo Linux to boot via UEFI. Your system may still support BIOS booting, but just be trying UEFI first. You can poke around in your BIOS boot configuration and play with this.


* ZFS has the ability to create virtual block devices called zvols in its namespace. btrfs has no equivalent and must rely on the loop device for this functionality, which is cumbersome.
;What's the Big Difference between Old School and New School?: Here's the deal. If you go with old-school MBR partitions, your <code>/boot</code> partition will be an ext2 filesystem, and you'll use <code>fdisk</code> to create your MBR partitions. If you go with new-school GPT partitions and UEFI booting, your <code>/boot</code> partition will be a vfat filesystem, because this is what UEFI is able to read, and you will use <code>gdisk</code> to create your GPT partitions. And you'll install GRUB a bit differently. That's about all it comes down to, in case you were curious.


The only area where btrfs is ahead of ZFS is in the area of small file
;Also Note: To install Funtoo Linux to boot via the New School UEFI method, you must boot System Rescue CD using UEFI -- and see an initial black and white screen. Otherwise, UEFI will not be active and you will not be able to set it up!
efficiency. btrfs supports a feature called block suballocation, which
enables it to store small files far more efficiently than ZFS. It is
possible to use another filesystem (e.g. reiserfs) on top of a ZFS zvol
to obtain similar benefits (with arguably better data integrity) when
dealing with many small files (e.g. the portage tree).


For a quick tour of ZFS and have a big picture of its common operations you can consult the page [[ZFS Fun]].
{{Note|'''Some motherboards may appear to support UEFI, but don't.''' Do your research. For example, the Award BIOS in my Gigabyte GA-990FXA-UD7 rev 1.1 has an option to enable UEFI boot for CD/DVD. '''This is not sufficient for enabling UEFI boot for hard drives and installing Funtoo Linux.''' UEFI must be supported for both removable media (so you can boot System Rescue CD using UEFI) as well as fixed media (so you can boot your new Funtoo Linux installation.) It turns out that later revisions of this board (rev 3.0) have a new BIOS that fully supports UEFI boot.  This may point to a third principle -- know thy hardware.}}


=== Disclaimers ===
==== Old-School (BIOS/MBR) Method ====


{{fancywarning|This guide is a work in progress. Expect some quirks.}}
{{Note|Use this method if you are booting using your BIOS, and if your System Rescue CD initial boot menu was light blue. If you're going to use the new-school method, [[#New-School (UEFI/GPT) Method|click here to jump down to UEFI/GPT.]]}}
{{fancyimportant|'''Since ZFS was really designed for 64 bit systems, we are only recommending and supporting 64 bit platforms and installations. We will not be supporting 32 bit platforms'''!}}
== Downloading the ISO (With ZFS) ==
In order for us to install Funtoo on ZFS, you will need an environment that already provides the ZFS tools. Therefore we will download a customized version of System Rescue CD with ZFS included.  


<pre>
===== Preparation =====
Name: sysresccd-4.2.0_zfs_0.6.2.iso  (545 MB)
Release Date: 2014-02-25
md5sum 01f4e6929247d54db77ab7be4d156d85
</pre>


First, it's a good idea to make sure that you've found the correct hard disk to partition. Try this command and verify that <code>/dev/sda</code> is the disk that you want to partition:


'''[http://ftp.osuosl.org/pub/funtoo/distfiles/sysresccd/ Download System Rescue CD with ZFS]'''<br />
<console>
# ##i##fdisk -l /dev/sda


== Creating a bootable USB from ISO (From a Linux Environment) ==
Disk /dev/sda: 640.1 GB, 640135028736 bytes, 1250263728 sectors
After you download the iso, you can do the following steps to create a bootable USB:
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt


<console>
Make a temporary directory
# ##i##mkdir /tmp/loop


Mount the iso
#         Start          End    Size  Type            Name
# ##i##mount -o ro,loop /root/sysresccd-4.2.0_zfs_0.6.2.iso /tmp/loop
1        2048  1250263694  596.2G  Linux filesyste Linux filesystem
 
Run the usb installer
# ##i##/tmp/loop/usb_inst.sh
</console>
</console>


That should be all you need to do to get your flash drive working.
Now, it's recommended that you erase any existing MBR or GPT partition tables on the disk, which could confuse the system's BIOS at boot time. We do this using <code>sgdisk</code>:
{{fancywarning|This will make any existing partitions inaccessible! You are '''strongly''' cautioned and advised to backup any critical data before proceeding.}}


== Booting the ISO ==
<console>
# ##i##sgdisk --zap-all /dev/sda


{{fancywarning|'''When booting into the ISO, Make sure that you select the "Alternate 64 bit kernel (altker64)". The ZFS modules have been built specifically for this kernel rather than the standard kernel. If you select a different kernel, you will get a fail to load module stack error message.'''}}
Creating new GPT entries.
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
</console>


== Creating partitions ==
This output is also nothing to worry about, as the command still succeded:
There are two ways to partition your disk: You can use your entire drive and let ZFS automatically partition it for you, or you can do it manually.


We will be showing you how to partition it '''manually''' because if you partition it manually you get to create your own layout, you get to have your own separate /boot partition (Which is nice since not every bootloader supports booting from ZFS pools), and you get to boot into RAID10, RAID5 (RAIDZ) pools and any other layouts due to you having a separate /boot partition.
<console>
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory.
***************************************************************
</console>


==== gdisk (GPT Style) ====
===== Partitioning =====


'''A Fresh Start''':
Now we will use <code>fdisk</code> to create the MBR partition table and partitions:
 
First lets make sure that the disk is completely wiped from any previous disk labels and partitions.
We will also assume that <tt>/dev/sda</tt> is the target drive.<br />


<console>
<console>
# ##i##sgdisk -Z /dev/sda
# ##i##fdisk /dev/sda
</console>
</console>


{{fancywarning|This is a destructive operation and the program will not ask you for confirmation! Make sure you really don't want anything on this disk.}}
Within <code>fdisk</code>, follow these steps:


Now that we have a clean drive, we will create the new layout.
'''Empty the partition table''':
 
First open up the application:


<console>
<console>
# ##i##gdisk /dev/sda
Command (m for help): ##i##o ↵
</console>
</console>


'''Create Partition 1''' (boot):
'''Create Partition 1''' (boot):
<console>
<console>
Command: ##i##n ↵
Command (m for help): ##i##n ↵
Partition Number: ##i##↵
Partition type (default p): ##i##↵
Partition number (1-4, default 1): ##i##↵
First sector: ##i##↵
First sector: ##i##↵
Last sector: ##i##+250M ↵
Last sector: ##i##+128M
Hex Code: ##i##
</console>
</console>


'''Create Partition 2''' (BIOS Boot Partition):
'''Create Partition 2''' (swap):
<console>Command: ##i##n ↵
Partition Number: ##i##↵
First sector: ##i##↵
Last sector: ##i##+32M ↵
Hex Code: ##i##EF02 ↵
</console>


'''Create Partition 3''' (ZFS):
<console>
<console>Command: ##i##n ↵
Command (m for help): ##i##n ↵
Partition Number: ##i##↵
Partition type (default p): ##i##↵
Partition number (2-4, default 2): ##i##↵
First sector: ##i##↵
First sector: ##i##↵
Last sector: ##i##↵
Last sector: ##i##+2G
Hex Code: ##i##bf00
Command (m for help): ##i##t ↵  
 
Partition number (1,2, default 2): ##i## ↵
Command: ##i##p
Hex code (type L to list all codes): ##i##82
 
Number  Start (sector)    End (sector) Size      Code  Name
  1            2048          514047  250.0 MiB  8300  Linux filesystem
  2          514048          579583  32.0 MiB    EF02  BIOS boot partition
  3          579584      1953525134  931.2 GiB  BF00  Solaris root
 
Command: ##i##w
</console>
</console>


 
'''Create the root partition:'''
=== Format your /boot partition ===


<console>
<console>
# ##i##mkfs.ext2 -m 1 /dev/sda1
Command (m for help): ##i##n ↵
Partition type (default p): ##i##
Partition number (3,4, default 3): ##i##↵
First sector: ##i##↵
Last sector: ##i##↵
</console>
</console>


=== Create the zpool ===
'''Verify the partition table:'''
We will first create the pool. The pool will be named `tank` and the disk will be aligned to 4096 (using ashift=12)
<console># ##i##zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo tank /dev/sda3</console>
 
=== Create the zfs datasets ===
We will now create some datasets. For this installation, we will create a small but future proof amount of datasets. We will have a dataset for the OS (/), and your swap. We will also show you how to create some optional datasets: <tt>/home</tt>, <tt>/var</tt>, <tt>/usr/src</tt>, and <tt>/usr/portage</tt>.


<console>
<console>
Create some empty containers for organization purposes, and make the dataset that will hold /
Command (m for help): ##i##p
# ##i##zfs create -p tank/funtoo
# ##i##zfs create -o mountpoint=/ tank/funtoo/root


Optional, but recommended datasets: /home
Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
# ##i##zfs create -o mountpoint=/home tank/funtoo/home
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x82abc9a6


Optional datasets: /usr/src, /usr/portage/{distfiles,packages}
Device    Boot    Start      End    Blocks  Id System
# ##i##zfs create -o mountpoint=/usr/src tank/funtoo/src
/dev/sda1          2048    264191    131072  83 Linux
# ##i##zfs create -o mountpoint=/usr/portage -o compression=off tank/funtoo/portage
/dev/sda2        264192  4458495  2097152  82 Linux swap / Solaris
# ##i##zfs create -o mountpoint=/usr/portage/distfiles tank/funtoo/portage/distfiles
/dev/sda3        4458496 625142447 310341976  83 Linux
# ##i##zfs create -o mountpoint=/usr/portage/packages tank/funtoo/portage/packages
</console>
</console>


=== Create your swap zvol ===
'''Write the parition table to disk:'''
For modern machines that have greater than 4 GB of RAM, A swap size of 2G should be enough. However if your machine doesn't have a lot of RAM, the rule of thumb is either 2x the RAM or RAM + 1 GB.
 
For this tutorial we will assume that it is a newer machine and make a 2 GB swap.


<console>
<console>
# ##i##zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -o volblocksize=4K -V 2G tank/swap
Command (m for help): ##i##w
</console>
</console>
{{fancywarning|ZFS swap is not stable and should be used with precautions.}}


=== Format your swap zvol ===
Your new MBR partition table will now be written to your system disk.
<console>
 
# ##i##mkswap -f /dev/zvol/tank/swap
{{Note|You're done with partitioning! Now, jump over to [[#Creating filesystems|Creating filesystems]].}}
# ##i##swapon /dev/zvol/tank/swap
</console>


Now we will continue to install funtoo.
==== New-School (UEFI/GPT) Method ====


== Installing Funtoo ==
{{Note|Use this method if you are booting using UEFI, and if your System Rescue CD initial boot menu was black and white. If it was light blue, this method will not work.}}


=== Pre-Chroot ===
The <tt>gdisk</tt> commands to create a GPT partition table are as follows. Adapt sizes as necessary, although these defaults will work for most users. Start <code>gdisk</code>:


<console>
<console>
Go into the directory that you will chroot into
# ##i##gdisk
# ##i##cd /mnt/funtoo
 
Make a boot folder and mount your boot drive
# ##i##mkdir boot
# ##i##mount /dev/sda1 boot
</console>
</console>


[[Funtoo_Linux_Installation|Now download and extract the Funtoo stage3 ...]]
Within <tt>gdisk</tt>, follow these steps:


Once you've extracted the stage3, do a few more preparations and chroot into your new funtoo environment:
'''Create a new empty partition table''' (This ''will'' erase all data on the disk when saved):


<console>
<console>
Bind the kernel related directories
Command: ##i##o ↵
# ##i##mount -t proc none proc
This option deletes all partitions and creates a new protective MBR.
# ##i##mount --rbind /dev dev
Proceed? (Y/N): ##i##y ↵
# ##i##mount --rbind /sys sys
</console>


Copy network settings
'''Create Partition 1''' (boot):
# ##i##cp -f /etc/resolv.conf etc


Make the zfs folder in 'etc' and copy your zpool.cache
<console>
# ##i##mkdir etc/zfs
Command: ##i##n ↵
# ##i##cp /etc/zfs/zpool.cache etc/zfs
Partition Number: ##i##1 ↵
First sector: ##i##↵
Last sector: ##i##+500M ↵
Hex Code: ##i##
</console>


Chroot into Funtoo
'''Create Partition 2''' (swap):
# ##i##env -i HOME=/root TERM=$TERM chroot . bash -l
</console>


=== In Chroot ===
Sync your tree
<console>
<console>
# ##i##emerge --sync
Command: ##i##n ↵
Partition Number: ##i##2 ↵
First sector: ##i##↵
Last sector: ##i##+4G ↵
Hex Code: ##i##8200 ↵
</console>
</console>


=== Add filesystems to /etc/fstab ===
'''Create Partition 3''' (root):


Before we continue to compile and or install our kernel in the next step, we will edit the <tt>/etc/fstab</tt> file because if we decide to install our kernel through portage, portage will need to know where our <tt>/boot</tt> is, so that it can place the files in there.
<console>
 
Command: ##i##n ↵
Edit <tt>/etc/fstab</tt>:
Partition Number: ##i##3 ↵
First sector: ##i##↵
Last sector: ##i##↵##!i## (for rest of disk)
Hex Code: ##i##↵
</console>


<pre>
Along the way, you can type "<tt>p</tt>" and hit Enter to view your current partition table. If you make a mistake, you can type "<tt>d</tt>" to delete an existing partition that you created. When you are satisfied with your partition setup, type "<tt>w</tt>" to write your configuration to disk:
# <fs>                 <mountpoint>   <type>          <opts>         <dump/pass>


/dev/sda1              /boot          ext2            defaults        0 2
'''Write Partition Table To Disk''':
/dev/zvol/tank/swap    none            swap            sw              0 0
</pre>
 
== Kernel Configuration ==
...wip
 
== Installing the ZFS userspace tools and kernel modules ==
Emerge {{Package|sys-fs/zfs}}. This package will bring in {{Package|sys-kernel/spl}}, and {{Package|sys-fs/zfs-kmod}} as its dependencies:


<console>
<console>
# ##i##emerge zfs
Command: ##i##w ↵
Do you want to proceed? (Y/N): ##i##Y ↵
</console>
</console>


Check to make sure that the zfs tools are working. The <code>zpool.cache</code> file that you copied before should be displayed.
The partition table will now be written to disk and <tt>gdisk</tt> will close.


<console>
Now, your GPT/GUID partitions have been created, and will show up as the following ''block devices'' under Linux:
# ##i##zpool status
# ##i##zfs list
</console>


If everything worked, continue.
* <tt>/dev/sda1</tt>, which will be used to hold the <tt>/boot</tt> filesystem,
* <tt>/dev/sda2</tt>, which will be used for swap space, and
* <tt>/dev/sda3</tt>, which will hold your root filesystem.


== Create the initramfs ==
==== Creating filesystems ====
There are two ways to do this, you can use "genkernel" or "bliss-initramfs". Both will be shown.


=== genkernel ===
{{Note|This section covers both BIOS ''and'' UEFI installs. Don't skip it!}}
Install genkernel and run it:
<console>
# ##i##emerge genkernel


You only need to add --luks if you used encryption
Before your newly-created partitions can be used, the block devices need to be initialized with filesystem ''metadata''. This process is known as ''creating a filesystem'' on the block devices. After filesystems are created on the block devices, they can be mounted and used to store files.
# ##i##genkernel --zfs --luks initramfs
</console>


== Installing & Configuring the Bootloader ==
Let's keep this simple. Are you using old-school MBR partitions? If so, let's create an ext2 filesystem on /dev/sda1:


=== GRUB 2  ===
<console>
<console>
# ##i##emerge grub
# ##i##mkfs.ext2 /dev/sda1
</console>
</console>


You can check that grub is version 2.00 by typing the following command:
If you're using new-school GPT partitions for UEFI, you'll want to create a vfat filesystem on /dev/sda1, because this is what UEFI is able to read:


<console>
<console>
# ##i##grub-install --version
# ##i##mkfs.vfat -F 32 /dev/sda1
grub-install (GRUB) 2.00
</console>
</console>


Now install grub to the drive itself (not a partition):
Now, let's create a swap partition. This partition will be used as disk-based virtual memory for your Funtoo Linux system.
<console>
# ##i##grub-install /dev/sda
</console>


You should receive the following message:
You will not create a filesystem on your swap partition, since it is not used to store files. But it is necessary to initialize it using the <code>mkswap</code> command. Then we'll run the <code>swapon</code> command to make your newly-initialized swap space immediately active within the live CD environment, in case it is needed during the rest of the install process:


<console>
<console>
Installation finished. No error reported.
# ##i##mkswap /dev/sda2
# ##i##swapon /dev/sda2
</console>
</console>


You should now see some a grub directory with some files inside your /boot folder:
Now, we need to create a root filesystem. This is where Funtoo Linux will live. We generally recommend ext4 or XFS root filesystems. If you're not sure, choose ext4. Here's how to create a root ext4 filesystem:


<console>
<console>
# ##i##ls -l /boot/grub
# ##i##mkfs.ext4 /dev/sda3
total 2520
-rw-r--r-- 1 root root    1024 Jan  4 16:09 grubenv
drwxr-xr-x 2 root root    8192 Jan 12 14:29 i386-pc
drwxr-xr-x 2 root root    4096 Jan 12 14:28 locale
-rw-r--r-- 1 root root 2555597 Feb  4 11:50 unifont.pf2
</console>
</console>


=== boot-update ===
...and here's how to create an XFS root filesystem, if you choose to use XFS:
boot-update comes as a dependency of grub2, so if you already installed grub, it's already on your system!
 
==== Genkernel ====
If your using genkernel you must add 'real_root=ZFS=<root>' and 'dozfs' to your params.
Example entry for <tt>/etc/boot.conf</tt>:
 
<pre>
"Funtoo ZFS" {
        kernel vmlinuz[-v]
        initrd initramfs-genkernel-x86_64[-v]
        params real_root=ZFS=tank/funtoo/root
        params += dozfs=force
}
</pre>
 
After editing /etc/boot.conf, you just need to run boot-update to update grub.cfg


<console>
<console>
###i## boot-update
# ##i##mkfs.xfs /dev/sda3
</console>
</console>


== Final configuration ==
Your filesystems (and swap) have all now been initialized, so that that can be mounted (attached to your existing directory heirarchy) and used to store files. We are ready to begin installing Funtoo Linux on these brand-new filesystems.
=== Add the zfs tools to openrc ===
<console># ##i##rc-update add zfs boot</console>


=== Clean up and reboot ===
{{fancywarning|1=
We are almost done, we are just going to clean up, '''set our root password''', and unmount whatever we mounted and get out.
When deploying an OpenVZ host, please use ext4 exclusively. The Parallels development team tests extensively with ext4, and modern versions of <code>openvz-rhel6-stable</code> are '''not''' compatible with XFS, and you may experience kernel bugs.
}}


<console>
==== Mounting filesystems ====
Delete the stage3 tarball that you downloaded earlier so it doesn't take up space.
# ##i##cd /
# ##i##rm stage3-latest.tar.xz


Set your root password
Mount the newly-created filesystems as follows, creating <code>/mnt/funtoo</code> as the installation mount point:
# ##i##passwd
>> Enter your password, you won't see what you are writing (for security reasons), but it is there!


Get out of the chroot environment
<console>
# ##i##exit
# ##i##mkdir /mnt/funtoo
 
# ##i##mount /dev/sda3 /mnt/funtoo
Unmount all the kernel filesystem stuff and boot (if you have a separate /boot)
# ##i##mkdir /mnt/funtoo/boot
# ##i##umount -l proc dev sys boot
# ##i##mount /dev/sda1 /mnt/funtoo/boot
 
Turn off the swap
# ##i##swapoff /dev/zvol/tank/swap
 
Export the zpool
# ##i##cd /
# ##i##zpool export tank
 
Reboot
# ##i##reboot
</console>
</console>


{{fancyimportant|'''Don't forget to set your root password as stated above before exiting chroot and rebooting. If you don't set the root password, you won't be able to log into your new system.'''}}
Optionally, if you have a separate filesystem for <code>/home</code> or anything else:
 
and that should be enough to get your system to boot on ZFS.


== After reboot ==
=== Forgot to reset password? ===
==== System Rescue CD ====
If you aren't using bliss-initramfs, then you can reboot back into your sysresccd and reset through there by mounting your drive, chrooting, and then typing passwd.
Example:
<console>
<console>
# ##i##zpool import -f -R /mnt/funtoo tank
# ##i##mkdir /mnt/funtoo/home
# ##i##chroot /mnt/funtoo bash -l
# ##i##mount /dev/sda4 /mnt/funtoo/home
# ##i##passwd
# ##i##exit
# ##i##zpool export -f tank
# ##i##reboot
</console>
</console>


=== Create initial ZFS Snapshot ===
If you have <code>/tmp</code> or <code>/var/tmp</code> on a separate filesystem, be sure to change the permissions of the mount point to be globally-writeable after mounting, as follows:
Continue to set up anything you need in terms of /etc configurations. Once you have everything the way you like it, take a snapshot of your system. You will be using this snapshot to revert back to this state if anything ever happens to your system down the road. The snapshots are cheap, and almost instant.
 
To take the snapshot of your system, type the following:
<console># ##i##zfs snapshot -r tank@install</console>
 
To see if your snapshot was taken, type:
<console># ##i##zfs list -t snapshot</console>
 
If your machine ever fails and you need to get back to this state, just type (This will only revert your / dataset while keeping the rest of your data intact):
<console># ##i##zfs rollback tank/funtoo/root@install</console>
 
{{fancyimportant|'''For a detailed overview, presentation of ZFS' capabilities, as well as usage examples, please refer to the [[ZFS_Fun|ZFS Fun]] page.'''}}
 
== Troubleshooting ==
 
=== Starting from scratch ===
If your installation has gotten screwed up for whatever reason and you need a fresh restart, you can do the following from sysresccd to start fresh:


<console>
<console>
Destroy the pool and any snapshots and datasets it has
# ##i##chmod 1777 /mnt/funtoo/tmp
# ##i##zpool destroy -R -f tank
 
This deletes the files from /dev/sda1 so that even after we zap, recreating the drive in the exact sector
position and size will not give us access to the old files in this partition.
# ##i##mkfs.ext2 /dev/sda1
# ##i##sgdisk -Z /dev/sda
</console>
</console>
Now start the guide again :).
[[Category:HOWTO]]
[[Category:Filesystems]]
[[Category:Featured]]
[[Category:Install]]
__NOTITLE__

Revision as of 15:36, January 5, 2015


   Note

This is a template that is used as part of the Installation instructions which covers: процесс разбиения диска и создания файловых систем. Templates are being used to allow multiple variant install guides that use most of the same re-usable parts.


Подготовка жесткого диска

В этой части мы научимся различным способам установки Funtoo Linux -- и загрузки с -- жесткого диска.

Введение

В прежние времена существовал лишь один способ загрузить PC-совместимый компьютер. Все наши дектопы и сервера имели стандартный PC BIOS, все наши харды использовали MBR и были разбиты используя схему разбивки MBR. Вот как это все было и нам это нравилось!

Затем появились EFI и UEFI, встроенные программы нового образца наряду со схемой разбивки GPT, поддерживающая диски размером более 2.2TБ. Неожиданно, нам стали доступны различные способы установки и загрузки Линукс систем . То, что было единым методом, стало чем-то более сложным.

Воспользуемся моментом и рассмотрим доступные способы конфигурации жесткого диска для загрузки Funtoo Linux. This Install Guide uses, and recommends, the old-school method of BIOS booting and using an MBR. It works and (except for rare cases) is universally supported. There's nothing wrong with it. If your system disk is 2TB or smaller in size, it won't prevent you from using all of your disk's capacity, either.

But, there are some situations where the old-school method isn't optimal. If you have a system disk >2TB in size, then MBR partitions won't allow you to access all your storage. So that's one reason. Another reason is that there are some so-called "PC" systems out there that don't support BIOS booting anymore, and force you to use UEFI to boot. So, out of compassion for people who fall into this predicament, this Install Guide documents UEFI booting too.

Our recommendation is still to go old-school unless you have reason not to. The boot loader we will be using to load the Linux kernel in this guide is called GRUB, so we call this method the BIOS + GRUB (MBR) method. It's the traditional method of setting up a PC-compatible system to boot Linux.

If you need to use UEFI to boot, we recommend not using the MBR at all for booting, as some systems support this, but others don't. Instead, we recommend using UEFI to boot GRUB, which in turn will load Linux. We refer to this method as the UEFI + GRUB (GPT) method.

And yes, there are even more methods, some of which are documented on the Boot Methods page. We used to recommend a BIOS + GRUB (GPT) method but it is not consistently supported across a wide variety of hardware.

The big question is -- which boot method should you use? Here's how to tell.

Principle 1 - Old School
If you can reliably boot System Rescue CD and it shows you an initial light blue menu, you are booting the CD using the BIOS, and it's likely that you can thus boot Funtoo Linux using the BIOS. So, go old-school and use BIOS booting, unless you have some reason to use UEFI, such as having a >2.2TB system disk. In that case, see Principle 2, as your system may also support UEFI booting.
Principle 2 - New School
If you can reliably boot System Rescue CD and it shows you an initial black and white menu -- congratulations, your system is configured to support UEFI booting. This means that you are ready to install Funtoo Linux to boot via UEFI. Your system may still support BIOS booting, but just be trying UEFI first. You can poke around in your BIOS boot configuration and play with this.
What's the Big Difference between Old School and New School?
Here's the deal. If you go with old-school MBR partitions, your /boot partition will be an ext2 filesystem, and you'll use fdisk to create your MBR partitions. If you go with new-school GPT partitions and UEFI booting, your /boot partition will be a vfat filesystem, because this is what UEFI is able to read, and you will use gdisk to create your GPT partitions. And you'll install GRUB a bit differently. That's about all it comes down to, in case you were curious.
Also Note
To install Funtoo Linux to boot via the New School UEFI method, you must boot System Rescue CD using UEFI -- and see an initial black and white screen. Otherwise, UEFI will not be active and you will not be able to set it up!
   Note

Some motherboards may appear to support UEFI, but don't. Do your research. For example, the Award BIOS in my Gigabyte GA-990FXA-UD7 rev 1.1 has an option to enable UEFI boot for CD/DVD. This is not sufficient for enabling UEFI boot for hard drives and installing Funtoo Linux. UEFI must be supported for both removable media (so you can boot System Rescue CD using UEFI) as well as fixed media (so you can boot your new Funtoo Linux installation.) It turns out that later revisions of this board (rev 3.0) have a new BIOS that fully supports UEFI boot. This may point to a third principle -- know thy hardware.

Old-School (BIOS/MBR) Method

   Note

Use this method if you are booting using your BIOS, and if your System Rescue CD initial boot menu was light blue. If you're going to use the new-school method, click here to jump down to UEFI/GPT.

Preparation

First, it's a good idea to make sure that you've found the correct hard disk to partition. Try this command and verify that /dev/sda is the disk that you want to partition:

root # fdisk -l /dev/sda

Disk /dev/sda: 640.1 GB, 640135028736 bytes, 1250263728 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt


root #         Start          End    Size  Type            Name
 1         2048   1250263694  596.2G  Linux filesyste Linux filesystem

Now, it's recommended that you erase any existing MBR or GPT partition tables on the disk, which could confuse the system's BIOS at boot time. We do this using sgdisk:

   Warning

This will make any existing partitions inaccessible! You are strongly cautioned and advised to backup any critical data before proceeding.

root # sgdisk --zap-all /dev/sda

Creating new GPT entries.
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.

This output is also nothing to worry about, as the command still succeded:

***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. 
***************************************************************
Partitioning

Now we will use fdisk to create the MBR partition table and partitions:

root # fdisk /dev/sda

Within fdisk, follow these steps:

Empty the partition table:

Command (m for help): o ↵

Create Partition 1 (boot):

Command (m for help): n ↵
Partition type (default p): 
Partition number (1-4, default 1): 
First sector: 
Last sector: +128M ↵

Create Partition 2 (swap):

Command (m for help): n ↵
Partition type (default p): 
Partition number (2-4, default 2): 
First sector: 
Last sector: +2G ↵
Command (m for help): t ↵ 
Partition number (1,2, default 2): 
Hex code (type L to list all codes): 82 ↵

Create the root partition:

Command (m for help): n ↵
Partition type (default p): 
Partition number (3,4, default 3): 
First sector: 
Last sector: 

Verify the partition table:

Command (m for help): p

Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x82abc9a6

Device    Boot     Start       End    Blocks  Id System
/dev/sda1           2048    264191    131072  83 Linux
/dev/sda2         264192   4458495   2097152  82 Linux swap / Solaris
/dev/sda3        4458496 625142447 310341976  83 Linux

Write the parition table to disk:

Command (m for help): w

Your new MBR partition table will now be written to your system disk.

   Note

You're done with partitioning! Now, jump over to Creating filesystems.

New-School (UEFI/GPT) Method

   Note

Use this method if you are booting using UEFI, and if your System Rescue CD initial boot menu was black and white. If it was light blue, this method will not work.

The gdisk commands to create a GPT partition table are as follows. Adapt sizes as necessary, although these defaults will work for most users. Start gdisk:

root # gdisk

Within gdisk, follow these steps:

Create a new empty partition table (This will erase all data on the disk when saved):

Command: o ↵
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y ↵

Create Partition 1 (boot):

Command: n ↵
Partition Number: 1 ↵
First sector: 
Last sector: +500M ↵
Hex Code: 

Create Partition 2 (swap):

Command: n ↵
Partition Number: 2 ↵
First sector: 
Last sector: +4G ↵
Hex Code: 8200 ↵

Create Partition 3 (root):

Command: n ↵
Partition Number: 3 ↵
First sector: 
Last sector:  (for rest of disk)
Hex Code: 

Along the way, you can type "p" and hit Enter to view your current partition table. If you make a mistake, you can type "d" to delete an existing partition that you created. When you are satisfied with your partition setup, type "w" to write your configuration to disk:

Write Partition Table To Disk:

Command: w ↵
Do you want to proceed? (Y/N): Y ↵

The partition table will now be written to disk and gdisk will close.

Now, your GPT/GUID partitions have been created, and will show up as the following block devices under Linux:

  • /dev/sda1, which will be used to hold the /boot filesystem,
  • /dev/sda2, which will be used for swap space, and
  • /dev/sda3, which will hold your root filesystem.

Creating filesystems

   Note

This section covers both BIOS and UEFI installs. Don't skip it!

Before your newly-created partitions can be used, the block devices need to be initialized with filesystem metadata. This process is known as creating a filesystem on the block devices. After filesystems are created on the block devices, they can be mounted and used to store files.

Let's keep this simple. Are you using old-school MBR partitions? If so, let's create an ext2 filesystem on /dev/sda1:

root # mkfs.ext2 /dev/sda1

If you're using new-school GPT partitions for UEFI, you'll want to create a vfat filesystem on /dev/sda1, because this is what UEFI is able to read:

root # mkfs.vfat -F 32 /dev/sda1

Now, let's create a swap partition. This partition will be used as disk-based virtual memory for your Funtoo Linux system.

You will not create a filesystem on your swap partition, since it is not used to store files. But it is necessary to initialize it using the mkswap command. Then we'll run the swapon command to make your newly-initialized swap space immediately active within the live CD environment, in case it is needed during the rest of the install process:

root # mkswap /dev/sda2
root # swapon /dev/sda2

Now, we need to create a root filesystem. This is where Funtoo Linux will live. We generally recommend ext4 or XFS root filesystems. If you're not sure, choose ext4. Here's how to create a root ext4 filesystem:

root # mkfs.ext4 /dev/sda3

...and here's how to create an XFS root filesystem, if you choose to use XFS:

root # mkfs.xfs /dev/sda3

Your filesystems (and swap) have all now been initialized, so that that can be mounted (attached to your existing directory heirarchy) and used to store files. We are ready to begin installing Funtoo Linux on these brand-new filesystems.

   Warning

When deploying an OpenVZ host, please use ext4 exclusively. The Parallels development team tests extensively with ext4, and modern versions of openvz-rhel6-stable are not compatible with XFS, and you may experience kernel bugs.

Mounting filesystems

Mount the newly-created filesystems as follows, creating /mnt/funtoo as the installation mount point:

root # mkdir /mnt/funtoo
root # mount /dev/sda3 /mnt/funtoo
root # mkdir /mnt/funtoo/boot
root # mount /dev/sda1 /mnt/funtoo/boot

Optionally, if you have a separate filesystem for /home or anything else:

root # mkdir /mnt/funtoo/home
root # mount /dev/sda4 /mnt/funtoo/home

If you have /tmp or /var/tmp on a separate filesystem, be sure to change the permissions of the mount point to be globally-writeable after mounting, as follows:

root # chmod 1777 /mnt/funtoo/tmp