Difference between pages "Funtoo:Networking/Configuration" and "Partitioning in Action, Part 1"

From Funtoo
< Funtoo:Networking(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
<blockquote>This document explains how to configure your network settings by explaining the network configuration functionality available in Funtoo Linux. Also covered is <tt>dhcpcd 5.x</tt>, Wi-Fi (IEEE 802.11) configuration, and the OpenResolv framework.
{{Article
</blockquote>
|Subtitle=Moving /home
{{#layout:doc}}
|Summary=In this new series of tips, Daniel Robbins shows you how to change partition layout on a running system. He'll also cover several tricks of the trade to minimize downtime and avoid making costly mistakes. In this particular tip, he'll show you how to move /home to another partition.
|Author=Drobbins
|Next in Series=Partitioning in Action, Part 2
}}
== Introduction ==
== Introduction ==


Funtoo Linux has its own core network configuration system that differs somewhat from upstream network configuration systems used in [http://www.gentoo.org Gentoo Linux] and [http://roy.marples.name/projects/openrc OpenRC].
The partition /home is one of the most-often-moved partitions. Sometimes, all the space in /home becomes exhausted, and an additional hard drive is required. Other times, /home is set up as part of the root partition, and it may need to be moved to improve performance or facilitate backup. Whatever the case, I'll show you how to move /home safely and efficiently.


In this document, I will explain the unique additions and changes to the Funtoo network configuration and show you how to use this system to configure your network.
{{Warning|The following technique describes how to move a partition(s). Although this technique is designed so that you can "back out" of a failed partition move, it doesn't protect against user error. In other words, any time that you format partitions or copy large numbers of files, there's a possibility that you will type the wrong thing, causing lots of data to be destroyed. For this reason, it's highly recommended that you take appropriate steps to back up all critical files before proceeding.}}


I'll also explain how to use <code>dhcpcd</code> for managing network interfaces on DHCP-based networks, and will also cover OpenRC stacked runlevel configuration, ''Wi-Fi'' (IEEE 802.11) configuration, and the OpenResolv framework, which is enabled in Funtoo Linux by default.
Now that you're prepared, we're ready to start moving /home. The exact steps you will take depend on whether /home currently resides on its own separate partition, or whether it is located on the root partition. Keep this in mind as we go through the steps (I'll make notes where necessary). Right now, if you are moving /home to a new hard drive, it should be physically installed in your system.


== A Gentle Introduction to Funtoo Network Configuration ==
If you are moving /home to an existing partition (it doesn't need to be ext2, as long as the target primary or extended partition exists), skip this step.


Before I get into the technical details of configuring your network, it's important to understand that Funtoo Linux has a number of different options available to you for network configuration, with more likely to be added in the future. Each approach is different and has its own strengths and weaknesses, and this is, in my opinion, a good thing.
== Create a new partition, if necessary ==


=== The Easy (Dynamic) Way ===
If the new partition doesn't exist yet, you'll need to create it using cfdisk (preferred) or fdisk. If the partition doesn't reside on your first drive, remember to specify the name of the device as the first argument to cfdisk or fdisk. After creating the appropriate primary or extended partition, you should reboot so that the partition table can be reread correctly. This is the only time you will need to reboot the system.


When configuring your network, one option is to skip traditional network configuration and simply rely on DHCP. This is by far the simplest method of configuring your network. If you are on a wired network, no other steps are typically required beyond enabling a DHCP client, and Funtoo Linux includes <code>dhcpcd 6.x</code> by default.
==  Create a filesystem on the new partition ==


==== Network Manager, Wicd ====
To create a filesystem on the new partition, first make sure you know the exact device name for the new partition (for example, /dev/sda5). If you're not sure of the exact device name, stop now and double-check! Then type the following, as root:
 
If you are going to use a third party package such as [[Network Manager]] or [[Wicd]] to manage your network then you do not need to configure DHCP at all. These packages configure DHCP for you. Simply emerge the package you want to use and start using it.
 
==== DHCP-Only Systems ====
 
If you are not planning to use a third-party package to manage your network interfaces, it is still extremely easy to set up DHCP networking, especially if you always use DHCP to connect to networks, which is common for desktops or laptops. In this scenario, we can simply enable <code>dhcpcd</code> to run at system startup. It will run in the background and automatically look for DHCP servers on all your network interfaces, and will attempt to lease an IP address from any DHCP servers found.
 
If this sounds like what you want to do, then add <code>dhcpcd</code> to your default runlevel as follows:
 
<console># ##i##rc-update add dhcpcd default</console>
 
To enable DHCP immediately, you would follow the previous command with an <code>rc</code> command, which would start the <code>dhcpcd</code> client you just added:
 
<console># ##i##rc</console>
 
If you're on a wired network and have the necessary drivers in your kernel, then this should get you going. For wireless networks, more steps are required to utilize your wireless hardware to associate with an access point, which will be covered later in this document.
 
===== Tweaking Dhcpcd =====
 
For now, it's important to note that <code>dhcpcd 6.x</code> will manage ''all'' available network interfaces by default. If you want to run a DHCP client on ''all but one'' interface, or some other subset of interfaces, you can add the appropriate <code>denyinterfaces</code> or <code>allowinterfaces</code> [[glob pattern]] to <code>/etc/dhcpcd.conf</code>:
 
<pre>
# manage all interfaces but eth0 with dhcpcd
denyinterfaces eth0
</pre>
 
This can also be accomplished by modifying <code>/etc/init.d/dhcpcd</code> directly and adding <code>-Z ''ifglob''</code> or <code>-z ''ifglob''</code> (the equivalent command-line parameters) to <code>command_args</code>.
 
==== Using Funtoo Scripts for DHCP ====
 
You can also use the Funtoo Linux networking scripts to start a DHCP client just on a specific interface. This approach is best if you are planning to also do some advanced bridging, bonding or VLAN configuration on your machine along with DHCP, since you will be using the Funtoo Linux networking scripts for that too.
 
To use this variant approach, ''don't'' enable <code>/etc/init.d/dhcpcd</code> directly. Instead, use the Funtoo Linux <code>dhcpcd</code> template which will start dhcpcd on only one interface. Below, you will see the steps to do this. This is very similar to how we set up advanced network interfaces, which will be covered later in this documentation:


<console>
<console>
# ##i##cd /etc/init.d
# ##i##mkfs.ext2 /dev/???
# ##i##ln -s netif.tmpl netif.eth0
# ##i##rc-update add netif.eth0 default
# ##i##echo template=dhcpcd > /etc/conf.d/netif.eth0
# ##i##rc
</console>
</console>


The last command, <code>rc</code>, causes <code>netif.eth0</code> to be started.
In the above and following code samples, ??? should be replaced with the target partition name. After executing this command, the target partition will contain an empty ext2 filesystem.
 
=== Server Network Configuration ===
 
For servers and advanced networking scenarios, Funtoo Linux offers its own modular, template-based network configuration system. This system offers a lot of flexibility for configuring network interfaces, essentially serving as a &quot;network interface construction kit.&quot; This system can be used by itself, or even combined with <tt>dhcpcd</tt>, as shown in the previous section.
 
Here are the key components of the template-based network configuration system:
 
;<tt>/etc/init.d/netif.lo</tt>: An init script that configures the localhost interface. This script is always enabled and is part of the boot process.
;<tt>/etc/netif.d</tt>: This is a directory that contains various network configuration templates. Each of these templates is focused on configuring a particular type of network interface, such as a general static IP-based interface, a bridge interface, a bond interface, etc.
;<tt>/etc/init.d/netif.tmpl</tt>: This is the master init script for the template-based network configuration system. New interfaces are added to your system by creating '''symbolic links''' to this file in <tt>/etc/init.d</tt>.
 
So, if you wanted to use this system to configure <tt>eth0</tt> with a static IP address, you would create a <tt>netif.eth0</tt> symlink to <tt>netif.tmpl</tt> as follows:
 
<console># ##i##cd /etc/init.d
# ##i##ln -s netif.tmpl netif.eth0</console>
Then, you would create an <tt>/etc/conf.d/netif.eth0</tt> configuration file that would specify which template to use from the <tt>/etc/netif.d</tt> directory:
 
<pre>
template="interface"
ipaddr="10.0.1.200/24"
gateway="10.0.1.1"
nameservers="10.0.1.1 10.0.1.2"
domain="funtoo.org"
</pre>
 
To complete our static IP network configuration we would need to:
 
<console># ##i##rc-update add netif.eth0 default</console>
When configuring your own static network interface, one of <tt>ipaddr</tt> or <tt>ipaddrs</tt> is required and should specify the IP address(es) to configure for this interface, in &quot;a.b.c.d/netmask&quot; format. Optional parameters include <tt>gateway</tt>, which defines a default gateway for your entire network, and if set should specify the gateway's IP address. In addition, <tt>domain</tt> and <tt>nameservers</tt> (space-separated if more than one) can be used to specify DNS information for this interface.
 
=== Configuration Variables ===
 
==== Interface Variables ====
 
The <tt>ipaddr</tt> and <tt>ipaddrs</tt> variables are supported by the <tt>interface</tt> and <tt>bridge</tt> templates, and are used to specify a single or multiple  IPv4 or IPv6 address(es) for the interface. IP addresses should be specified in 'IP/netmask' format, such as <tt>10.0.0.1/24</tt>. Multiple IP addresses can be specified delimited by whitespace:
 
<pre>ipaddrs=&quot;10.0.0.1/24 10.0.0.2/24&quot;</pre>
 
===== Broadcast Address =====


By default, a broadcast address will be calculated based on the IP address and network mask. If you need to manually specify a broadcast address, use the following format for your IP address:
== Mount the new filesystem in /mnt ==


<pre>
Create a directory called /mnt/newpart, and then mount the new partition there:
ipaddrs="10.0.0.1/24;broadcast=10.0.1.255 10.0.0.2/24"
</pre>
 
===== Not Specifying An Address =====
 
Note that in some cases, you may choose to '''not''' specify <tt>ipaddr</tt> or <tt>ipaddrs</tt> for a <tt>bridge</tt> template. That is allowed. If you don't want to specify an IP address for a regular interface, you can choose to use the <tt>interface</tt> template without an IP address specified in the config, or use the <tt>interface-noip</tt> template instead, for the sake of clarity.
 
===== Viewing All Configured IP Addresses =====
 
Also note that if you specify multiple IPv4 addresses, <tt>ifconfig</tt> will only show the first IP address. To view all IP addresses associated with the interface, use the <tt>ip addr show</tt> command.
 
=== General Variables ===
 
The following variables are enabled by default for all network scripts, and if specified will trigger a corresponding configuration action:
 
;<tt>nameservers</tt>: Set DNS nameservers using OpenResolv. Specify multiple IPv4 or IPv6 nameservers like this: &quot;1.2.3.4 1.2.3.5 1.2.3.6&quot;. Please note that OpenResolv treats <tt>127.0.0.1</tt> specially, and it indicates that you are running a local name resolver like <tt>dnsmasq</tt> or <tt>bind</tt>. OpenResolv will ignore all other name servers specified alongside <tt>127.0.0.1</tt>. See <tt>man resolvconf</tt> and <tt>man resolvconf.conf</tt> for additional setup information.
;<tt>search</tt>: Set DNS search information using OpenResolv.
;<tt>domain</tt>: Set DNS domain using OpenResolv.
;<tt>gateway</tt>: Define a default IPv4 gateway on this interface.
;<tt>gateway6</tt>: Define a default IPv6 gateway on this interface.
;<tt>route</tt>: Specify a semi-colon delimited list of IPv4 routes to apply when this interface is brought up. Will be appended to <tt>ip -4 route add</tt>.
;<tt>route6</tt>: Specify a semi-colon delimited list of IPv6 routes to apply when this interface is brought up. Will be appended to <tt>ip -6 route add</tt>.
;<tt>mtu</tt>: Set Maximum Transmit Unit for the interface
 
 
 
==== VLAN Variables ====
 
VLAN support is enabled by default for all network configuration scripts. If a network script has a name in the format <tt>netif.ethX.Y</tt>, then it is assumed to be a VLAN interface referencing trunk <tt>ethX</tt> and VLAN ID <tt>Y</tt>. If you desire a custom name for your VLAN interface, you can name your interface whatever you'd like and specify the following variables in your interface config:
 
;<tt>trunk</tt>: VLAN trunk interface, e.g. &quot;eth0&quot;
;<tt>vlan</tt>: VLAN id, e.g. &quot;32&quot;
 
==== Bridge / Tap Variables ====
 
The following variables for configuring a functional bridge interface with optional tap interfaces:
 
;<tt>slaves</tt>: Set slave interfaces of this interface (for bridges, etc.) All slaves will automatically be depended upon, and will also automatically have their <tt>mtu</tt> set to that of the current interface, if an <tt>mtu</tt> is specified for the current interface. This setting is required for the <tt>bond</tt> template and optional for the <tt>bridge</tt> template.
;<tt>stp</tt>: Enables Spanning Tree Protocol on a bridge interface like this &quot;stp=on&quot;
;<tt>forwarding</tt>: Enables forwarding on a bridge interface by calling sysctl; as this interface does not exist when sysctl is called by init, we do it here. If this is disabled, your bridge will not forward traffic back out onto the network. useage: &quot;forwarding=1&quot;
;<tt>mac_addr</tt>: Sets a MAC address on a tap interface. This is usefull for avoiding layer2 address collisions when using large numbers of TUN interfaces (KVM, openVPN, ect)
 
=== OpenResolv and resolv.conf ===
 
OpenResolv will be used to set DNS information provided by the <tt>nameservers</tt>, <tt>domain</tt> and <tt>search</tt> variables when an interface is brought up. The OpenResolv framework will add entries to <tt>/etc/resolv.conf</tt>, and will also handle removing these entries when the interface is brought down. This way, <tt>/etc/resolv.conf</tt> should always contain current information and should not need to be manually edited by the system administrator. <tt>dhcpcd</tt> will use OpenResolv for updating system DNS information as well.
 
=== Network-Dependent Services ===
 
One important difference between Gentoo Linux and Funtoo Linux is that, in Funtoo Linux, network-dependent services only strictly depend on <tt>netif.lo</tt>. This means that if another network service requires an interface to be up, such as <tt>samba</tt> requiring <tt>eth0</tt>, then the system administrator must specify this relationship by adding the following line to <tt>/etc/conf.d/samba</tt>:
 
<pre>rc_need=&quot;netif.eth0&quot;</pre>
This will have the effect of ensuring that <tt>netif.eth0</tt> is started prior to <tt>samba</tt> and that <tt>samba</tt> is stopped prior to stopping <tt>netif.eth0</tt>.
 
Many network services, especially those that listen on all network intefaces, don't need an <tt>rc_need</tt> line in order to function properly. Avoiding the use of <tt>rc_need</tt> when required will optimize boot times and allow more network services to remain available when network interfaces are brought up and down by the system administrator.
 
=== Multiple Network Configurations ===
 
For information on how to have multiple, independent network configurations, please see [[Stacked Runlevels]].
 
=== Alternate Configs ===
If you need to run the same service with different configuration parameters depending upon runlevel, then you'll be happy to know that you can specify runlevel-specific conf.d files by appending a <tt>.
&lt;runlevel&gt;</tt> suffix. In this particular example, we could imagine a situation where we had two child runlevels named <tt>home</tt> and <tt>work</tt>:
 
<pre>/etc/conf.d/netif.eth0.home
/etc/conf.d/netif.eth0.work</pre>Note that this feature works for all init scripts, not just network configuration scripts.
 
=== Interface Renaming ===
 
Funtoo network scripts now support interface renaming, so you can create an interface called <tt>lan</tt> if you would like. To do this, simply specify the MAC address of the interface you would like to rename using the <tt>macaddr</tt> variable:
<pre>macaddr=&quot;00:15:17:19:b6:a3&quot;</pre>If this MAC address is part of the <tt>netif.lan</tt> configuration file, then when this interface starts, whatever interface currently has the MAC address of 00:15:17:19:b6:a3 (i.e. <tt>eth5</tt>) will be renamed to <tt>lan</tt> prior to the interface being brought up, and will show up in <tt>ifconfig</tt> and <tt>ip</tt> commands as being an interface named <tt>lan</tt>.
 
=== Basic VLAN Configuration ===
 
The standard <tt>interface</tt> template supports VLANs. To use VLAN support, first ensure that your kernel was compiled with VLAN support (the module name is <tt>8021q</tt>) :


<console>
<console>
# ##i##grep CONFIG_VLAN /usr/src/linux/.config
# ##i##mount /dev/??? /mnt/newpart
CONFIG_VLAN_8021Q=m
CONFIG_VLAN_8021Q_GVRP=y
</console>
</console>


Then, configure the trunk interface using the <tt>interface-noip</tt> template. Assuming <tt>eth1</tt> is trunked, you would create the file <tt>/etc/conf.d/netif.eth1</tt> with the following contents:
==  Drop to single-user mode ==
 
<pre>template=&quot;interface-noip&quot;</pre>


Then, create a network interface symlink for the trunk and add it to your default runlevel:
I delayed this step as long as possible to maximize system availability, but we now must drop into single-user mode, and copy files from /home to /mnt/newpart. You shouldn't have any files open in /home, and entering single-user mode eliminates this possibility:


<console>
<console>
# ##i##cd /etc/init.d
# ##i##init 1
# ##i##ln -s netif.tmpl netif.eth1
# ##i##rc-update add netif.eth1 default
</console>
</console>


Now, assuming you wanted to configure a VLAN of 32, you would create a config file named <tt>/etc/conf.d/netif.eth1.32</tt> that looks something like this:
==  Change directories to /home and copy files ==


<pre>
Type the following:
template=&quot;interface&quot;
ipaddr=&quot;1.2.3.4/24&quot;
gateway=&quot;1.2.3.1&quot;# etc...
</pre>
 
Then, create a VLAN network interface symlink and add it to your default runlevel:


<console>
<console>
# ##i##cd /etc/init.d
# ##i##cd /home
# ##i##ln -s netif.tmpl netif.eth1.32
# ##i##cp -ax * /mnt/newpart
# ##i##rc-update add netif.eth1.32 default
</console>
</console>


The Funtoo network configuration scripts will automatically recognize the filename <tt>netif.eth1.32</tt> as being VLAN 32 of trunk interface <tt>netif.eth1</tt>.
The cp -ax command recursively copies the contents of /home to /mnt/newpart, preserving all file attributes, and not crossing any mount points. After this command finishes, /mnt/newpart will contain an exact copy of all the files and directories currently in /home. If the old /home was on its own separate partition (listed on a separate line in /etc/fstab), go to step 6a. Otherwise, proceed to step 6b.


When the VLAN interface is brought up, it will be named <tt>eth1.32</tt>.
==  Use the new partition ==


=== Custom VLAN Names ===
=== /home on its own partition ===


However, sometimes you may want to turn off automatic file-based VLAN naming and give your VLAN interface a custom name, such as <tt>mgmt</tt>. To do this, you would set up the trunk interface in the exact same way as described above, but instead of creating a <tt>netif.eth1.32</tt> interface, you would create a <tt>netif.mgmt</tt> interface, and specify <tt>vlan</tt> and <tt>trunk</tt> in the <tt>/etc/conf.d/netif.mgmt</tt> config file, as follows:
{{Note|These instructions are for systems where the old /home is already on its own dedicated partition. If this isn't the case, see the next section.}}


<pre>template=&quot;interface&quot;
Unmount the old partition by typing:
vlan=&quot;32&quot;
trunk=&quot;eth1&quot;
ipaddr=&quot;1.2.3.4/24&quot;
gateway=&quot;1.2.3.1&quot;
# etc...</pre>
When you specify <tt>trunk</tt> and <tt>vlan</tt> in the interface config file, filename-based auto-detecting of VLAN ID and trunk is disabled. Both <tt>trunk</tt> and <tt>vlan</tt> must be specified -- you can't specify just one.
 
Then you would simply create a VLAN network interface symlink for <tt>netif.mgmt</tt>:
 
<console># ##i##cd /etc/init.d
# ##i##ln -s netif.tmpl netif.mgmt
# ##i##rc-update add netif.mgmt default</console>
When the VLAN interface is brought up, it will be named <tt>mgmt</tt>.
 
=== Bonding Configuration ===
 
Bonding allows you to aggregate multiple network interfaces into a single logical network interface, allowing for benefits in throughput as well as resiliency in the case that an individual interface may go down. This example shows how you would create a bonding interface (<tt>mybond</tt>) with a simple static ip setup, containing two slave devices (<tt>eth0</tt> and <tt>eth1</tt>).
 
First, ensure that your kernel is configured to support bonding (the module name is <tt>bonding</tt>) :


<console>
<console>
$ ##i##grep CONFIG_BONDING /usr/src/linux/.config
# ##i##cd /
CONFIG_BONDING=m
# ##i##umount /home
</console>
</console>


You'l want to ensure that CONFIG_BONDING is set to "m" or "y". You can find this kernel configuration option tucked under "Device Drivers" -> "Network Device Support" -> "Bonding driver support".
Then, unmount and remount the new partition:
Be sure that ifenslave is emerged (this package included in Funtoo stage3):


<console>
<console>
# ##i##emerge ifenslave
# ##i##umount /mnt/newpart
# ##i##mount /dev/??? /home
</console>
</console>
Once bonding is enabled in the kernel, you will need to choose at least two devices to bond together. These will be set up as "slave" interfaces with no IP address.


<console>
Now, the new partition is available at /home and is ready to be used. We can perform the last few steps in multiuser mode. Exit single-user mode, so that the system is back up and running, by pressing CTRL-D.
# ##i##cd /etc/init.d/
# ##i##ln -s netif.tmpl netif.eth0
# ##i##ln -s netif.tmpl netif.eth1
</console>


Then, configure the slave interfaces by creating <tt>/etc/conf.d/netif.eth0</tt> and <tt>/etc/conf.d/netif.eth1</tt> with the following contents:
Important: After the system starts up normally, log in as root and edit /etc/fstab so that /dev/??? is now mounted automatically at /home instead of your old partition. For example, change this line:


<pre>
<pre>
template="interface-noip"
/dev/hda3  /home  ext2  defaults  1  2
</pre>
</pre>


Now, we will create the bond interface and make <tt>netif.eth0</tt> and <tt>netif.eth1</tt> slaves of this interface. Note that our bond interface can have any name. To demonstrate this, we will give it the name of "mybond" below:
to this line:
 
<console>
# ##i##ln -s netif.tmpl netif.mybond
# ##i##rc-update add netif.mybond default
</console>
 
Now we can configure "mybond" using its configuration file <tt>/etc/conf.d/netif.mybond</tt>, just as we would a regular interface, except that we specify <tt>slaves</tt>:
 
<pre>
template="bond"
ipaddr="10.0.1.200/24"
gateway="10.0.1.1"
nameservers="10.0.1.1 10.0.1.2"
domain="funtoo.org"
slaves="netif.eth0 netif.eth1"
</pre>
 
In a bonded configuration, it is common to set the MTU to the maximum possible value supported by hardware to maximize throughput. In order to do this, simply set the MTU option in <tt>/etc/conf.d/netif.mybond</tt> to the maximum value supported by your hardware. The network scripts will ensure that this MTU setting is applied to all slave interfaces:


<pre>
<pre>
mtu=9000
/dev/???  /home  ext2  defaults  1  2
</pre>
</pre>


=== Bridge Configuration ===
=== /home on a shared partition ===


When hosting virtual machines, it can be convenient to use a bridge setup. This example shows how you would create a bridge (br0) with a simple static ip setup, containing two slave devices (eth0, tap0).
{{Note|These instructions are for systems where the old /home is on a shared partition.}}
 
First, ensure that your kernel is configured to support bridging (the module name is <tt>bridge</tt>) :
 
<console>
$ ##i##grep CONFIG_BRIDGE /usr/src/linux/.config
CONFIG_BRIDGE=m
CONFIG_BRIDGE_IGMP_SNOOPING=y
</console>
 
Second, make sure you have the required software installed:
 
<console>
# ##i##emerge -av bridge-utils usermode-utilities
</console>
 
Then, create the necessary symlinks for the interfaces and add them to your default runlevel :


<console>
<console>
# ##i##cd /etc/init.d/
# ##i##cd /
# ##i##ln -s netif.tmpl netif.eth0
# ##i##mv /home /home.old
# ##i##ln -s netif.tmpl netif.br0
# ##i##mkdir /home
# ##i##ln -s netif.tmpl netif.tap0
# ##i##mount /dev/??? /home
# ##i##rc-update add netif.br0 default
# ##i##rc-update add netif.tap0 default
</console>
</console>


Then, configure the slave interface <tt>/etc/conf.d/netif.eth0</tt> :
Now, leave single user mode by pressing CTRL-D. When the system is back up and running, edit /etc/fstab and add a line like the following:
 
<pre>
template="interface-noip"
</pre>
 
Then, configure the slave interface <tt>/etc/conf.d/netif.tap0</tt> - note you only require group OR user, not both :


<pre>
<pre>
template="tap"
/dev/???  /home  ext2  defaults  1  2
group="kvm"
user="kvm"
mac_addr="10:20:30:40:50:66"
</pre>
</pre>


... and the bridge interface <tt>/etc/conf.d/netif.br0</tt> :
That way, your new partition will get mounted correctly the next time the system is rebooted.
 
<pre>
template="bridge"
ipaddr="10.0.1.200/24"
gateway="10.0.1.1"
nameservers="10.0.1.1 10.0.1.2"
domain="funtoo.org"
slaves="netif.eth0 netif.tap0"
stp="on"
forwarding=1
</pre>
 
If you are using dhcpcd, you should ensure that it does not attempt to configure <tt>eth0</tt> or <tt>br0</tt> by adding the following to <tt>/etc/dhcpcd.conf</tt> :
 
<pre>
# don't attempt to pull an ip address for br0 or its slave device
denyinterfaces eth0 br0
</pre>
 
=== More Complex Network Configuration ===
 
If the standard templates don't work for your needs, simply create a new template -- I recommend starting from the <tt>interface</tt> template for most things:
 
<console># ##i##cd /etc/netif.d
# ##i##cp interface custom</console>
You can now call whatever commands you need to <tt>/etc/netif.d/custom</tt>. The following shell functions can be defined in a network script:
 
==== netif_create ====
 
In <tt>netif_create</tt>, you should call any commands to create the interface if it does not yet exist.
 
==== netif_depend ====
 
In <tt>netif_depend</tt>, you can define dependencies, using the functions <tt>need</tt> and <tt>use</tt>.
 
==== netif_pre_up ====
 
In <tt>netif_pre_up</tt>, you can define network configuration actions to perform prior to bringing the interface up. You can also ensure certain variables are specified by calling <tt>require var1 [var2...]</tt> here.
 
==== netif_post_up====
 
In <tt>netif_post_up</tt>, you can define network configuration actions to perform after bringing the interface up.
 
==== netif_pre_down ====
 
In <tt>netif_pre_down</tt>, you can define network configuration actions to perform prior to bringing the interface down.
 
==== netif_post_down ====
 
In <tt>netif_post_down</tt>, you can define network configuration actions to perform after bringing the interface down.
 
==== netif_destroy ====
 
In <tt>netif_destroy</tt>, you can call any commands necessary to destroy/delete the interface if it is dynamic in nature (tun/tap, etc.)
 
==== How It Works ====
 
You do not specify a function for actually bringing up the interface, because the template-based system does this for you. The template-based system also performs all normal actions required to bring an interface down, so you only need to specify atypical actions that must be performed - such as removing child interfaces or destroying a bridge using <tt>brctl</tt>.
 
When you create your own network configuration template, the following capabilities are available for use automatically, as long as the appropriate variables are set in the <tt>/etc/conf.d/netif.&lt;ifname&gt;</tt> file, without requiring any explicit steps on your part:
 
* DNS configuration using <tt>domain</tt> and <tt>nameservers</tt> config settings. OpenResolv is used automatically.
* VLAN configuration using auto-naming (<tt>netif.ethX.Y</tt>) or via custom naming with <tt>trunk</tt> and <tt>vlan</tt> config settings.
* Default IPv4 gateway and route configuration using the <tt>gateway</tt> and <tt>route</tt> settings.
* Default IPv6 gateway and route configuration using the <tt>gateway6</tt> and <tt>route6</tt> settings.
* MTU configuration using the <tt>mtu</tt> setting.
* Auto-depend (and auto-MTU configuration) of slave interfaces specified using <tt>slaves</tt> setting.
* Renaming of existing network interface (specify MAC address using <tt>macaddr</tt> setting).
 
To take advantage of this functionality, simply enable the appropriate variables.
 
All other necessary network configuration and dependency behavior should be defined using the <tt>netif_</tt>-prefix functions described above.
 
== Wireless Configuration ==
 
The recommended approach for setting up Wi-Fi under Funtoo Linux is to use NetworkManager. Steps are provided in the [[Funtoo Linux Installation#Wi-Fi|Wi-Fi section of the Funtoo Linux Installation Guide]].
 
== Other Network Configurations ==
 
If you have a network configuration template that might be useful to others, please post it to the [http://groups.google.com/group/funtoo-dev funtoo-dev mailing list] so we can review it and possibly incorporate it into Funtoo.
 
== License ==


Funtoo Linux networking scripts are released under the following license:
==  Finishing up ==


{{BSD2 Funtoo|src=http://github.com/funtoo/corenetwork}}
We deliberately left the old /home directory/partition behind, just in case there were problems copying files. After verifying that the system is running smoothly, you can either use your old /home partition for something else, or remove the /home.old directory.


[[Category:HOWTO]]
Congratulations, you've just moved /home! In my next tip, we'll reconfigure a system so that /tmp and /var are on their own shared partition. See you then.
[[Category:Projects]]
{{ArticleFooter}}
[[Category:Networking]]
[[Category:Install]]
[[Category:Funtoo features]]
[[Category:Official Documentation]]

Revision as of 20:26, January 1, 2015

Moving /home

In this new series of tips, Daniel Robbins shows you how to change partition layout on a running system. He'll also cover several tricks of the trade to minimize downtime and avoid making costly mistakes. In this particular tip, he'll show you how to move /home to another partition.
   Support Funtoo!
Get an awesome Funtoo container and support Funtoo! See Funtoo Containers for more information.

Introduction

The partition /home is one of the most-often-moved partitions. Sometimes, all the space in /home becomes exhausted, and an additional hard drive is required. Other times, /home is set up as part of the root partition, and it may need to be moved to improve performance or facilitate backup. Whatever the case, I'll show you how to move /home safely and efficiently.

   Warning

The following technique describes how to move a partition(s). Although this technique is designed so that you can "back out" of a failed partition move, it doesn't protect against user error. In other words, any time that you format partitions or copy large numbers of files, there's a possibility that you will type the wrong thing, causing lots of data to be destroyed. For this reason, it's highly recommended that you take appropriate steps to back up all critical files before proceeding.

Now that you're prepared, we're ready to start moving /home. The exact steps you will take depend on whether /home currently resides on its own separate partition, or whether it is located on the root partition. Keep this in mind as we go through the steps (I'll make notes where necessary). Right now, if you are moving /home to a new hard drive, it should be physically installed in your system.

If you are moving /home to an existing partition (it doesn't need to be ext2, as long as the target primary or extended partition exists), skip this step.

Create a new partition, if necessary

If the new partition doesn't exist yet, you'll need to create it using cfdisk (preferred) or fdisk. If the partition doesn't reside on your first drive, remember to specify the name of the device as the first argument to cfdisk or fdisk. After creating the appropriate primary or extended partition, you should reboot so that the partition table can be reread correctly. This is the only time you will need to reboot the system.

Create a filesystem on the new partition

To create a filesystem on the new partition, first make sure you know the exact device name for the new partition (for example, /dev/sda5). If you're not sure of the exact device name, stop now and double-check! Then type the following, as root:

root # mkfs.ext2 /dev/???

In the above and following code samples, ??? should be replaced with the target partition name. After executing this command, the target partition will contain an empty ext2 filesystem.

Mount the new filesystem in /mnt

Create a directory called /mnt/newpart, and then mount the new partition there:

root # mount /dev/??? /mnt/newpart

Drop to single-user mode

I delayed this step as long as possible to maximize system availability, but we now must drop into single-user mode, and copy files from /home to /mnt/newpart. You shouldn't have any files open in /home, and entering single-user mode eliminates this possibility:

root # init 1

Change directories to /home and copy files

Type the following:

root # cd /home
root # cp -ax * /mnt/newpart

The cp -ax command recursively copies the contents of /home to /mnt/newpart, preserving all file attributes, and not crossing any mount points. After this command finishes, /mnt/newpart will contain an exact copy of all the files and directories currently in /home. If the old /home was on its own separate partition (listed on a separate line in /etc/fstab), go to step 6a. Otherwise, proceed to step 6b.

Use the new partition

/home on its own partition

   Note

These instructions are for systems where the old /home is already on its own dedicated partition. If this isn't the case, see the next section.

Unmount the old partition by typing:

root # cd /
root # umount /home

Then, unmount and remount the new partition:

root # umount /mnt/newpart
root # mount /dev/??? /home

Now, the new partition is available at /home and is ready to be used. We can perform the last few steps in multiuser mode. Exit single-user mode, so that the system is back up and running, by pressing CTRL-D.

Important: After the system starts up normally, log in as root and edit /etc/fstab so that /dev/??? is now mounted automatically at /home instead of your old partition. For example, change this line:

/dev/hda3   /home   ext2   defaults   1   2

to this line:

/dev/???   /home   ext2   defaults   1   2

/home on a shared partition

   Note

These instructions are for systems where the old /home is on a shared partition.

root # cd /
root # mv /home /home.old
root # mkdir /home
root # mount /dev/??? /home

Now, leave single user mode by pressing CTRL-D. When the system is back up and running, edit /etc/fstab and add a line like the following:

/dev/???   /home   ext2   defaults   1   2

That way, your new partition will get mounted correctly the next time the system is rebooted.

Finishing up

We deliberately left the old /home directory/partition behind, just in case there were problems copying files. After verifying that the system is running smoothly, you can either use your old /home partition for something else, or remove the /home.old directory.

Congratulations, you've just moved /home! In my next tip, we'll reconfigure a system so that /tmp and /var are on their own shared partition. See you then.

   Tip

Read the next article in this series: Partitioning in Action, Part 2

   Note

Browse all our available articles below. Use the search field to search for topics and keywords in real-time.

Article Subtitle
Article Subtitle
Awk by Example, Part 1 An intro to the great language with the strange name
Awk by Example, Part 2 Records, loops, and arrays
Awk by Example, Part 3 String functions and ... checkbooks?
Bash by Example, Part 1 Fundamental programming in the Bourne again shell (bash)
Bash by Example, Part 2 More bash programming fundamentals
Bash by Example, Part 3 Exploring the ebuild system
BTRFS Fun
Funtoo Filesystem Guide, Part 1 Journaling and ReiserFS
Funtoo Filesystem Guide, Part 2 Using ReiserFS and Linux
Funtoo Filesystem Guide, Part 3 Tmpfs and Bind Mounts
Funtoo Filesystem Guide, Part 4 Introducing Ext3
Funtoo Filesystem Guide, Part 5 Ext3 in Action
GUID Booting Guide
Learning Linux LVM, Part 1 Storage management magic with Logical Volume Management
Learning Linux LVM, Part 2 The cvs.gentoo.org upgrade
Libvirt
Linux Fundamentals, Part 1
Linux Fundamentals, Part 2
Linux Fundamentals, Part 3
Linux Fundamentals, Part 4
LVM Fun
Making the Distribution, Part 1
Making the Distribution, Part 2
Making the Distribution, Part 3
Maximum Swappage Getting the most out of swap
On screen annotation Write on top of apps on your screen
OpenSSH Key Management, Part 1 Understanding RSA/DSA Authentication
OpenSSH Key Management, Part 2 Introducing ssh-agent and keychain
OpenSSH Key Management, Part 3 Agent Forwarding
Partition Planning Tips Keeping things organized on disk
Partitioning in Action, Part 1 Moving /home
Partitioning in Action, Part 2 Consolidating data
POSIX Threads Explained, Part 1 A simple and nimble tool for memory sharing
POSIX Threads Explained, Part 2
POSIX Threads Explained, Part 3 Improve efficiency with condition variables
Sed by Example, Part 1
Sed by Example, Part 2
Sed by Example, Part 3
Successful booting with UUID Guide to use UUID for consistent booting.
The Gentoo.org Redesign, Part 1 A site reborn
The Gentoo.org Redesign, Part 2 The Documentation System
The Gentoo.org Redesign, Part 3 The New Main Pages
The Gentoo.org Redesign, Part 4 The Final Touch of XML
Traffic Control
Windows 10 Virtualization with KVM