Difference between pages "User:Apple" and "User:Apple/projects/Transplant"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
m
 
(Created page with "''a.k.a. I like my Linux how I like my women... <s>easy to set up</s>flexible.'' This is a script to backup and/or transfer a working Funtoo installation onto a fresh install (o...")
 
Line 1: Line 1:
==about==
''a.k.a. I like my Linux how I like my women... <s>easy to set up</s>flexible.''
generic enthusiastic linux user. (probably) better at writing documentation than code.


===linux history===
This is a script to backup and/or transfer a working Funtoo installation onto a fresh install (on the same or a different host).
my first experience of open-source was early 2004 when I checked out blender (I had used it before in 2001, before it was open-source). I was using it in windows but irc chatter was quite abuzz with linux, so I checked it out.


I started with Fedora Core 2, and about 2 weeks later started with gentoo. The first install was handled by two irc users over ssh, which was a first for all of us.
It won't speed up an install and it doesn't make it easier, but with it you can do a single reboot
and have a complete working system without tedious config file editing.


around August 2004, I helped out with a little known binary distro called h3knix until 2005 (h3knix and arcane linux were merged in late 2005, died shortly afterwards).
==The Script==


resigned back to windows in 2005.
{| width="100%" cellpadding=0 cellspacing=0 style="margin: .5em 0; background-color: #f2fff2; border: solid 1px #bfffbf;"
| style="background-color: #c1ffc1; border: solid 1px #a0ffa0; border-bottom: 1px solid #888; font-size: 0.9em" | '''Code:''' /usr/local/bin/transplant
|-
| style="padding: 0 0.5em; font-family=monospace, fixed; white-space: pre;"|
<tt><nowiki>
#!/bin/bash
# I use heavy amounts of bashisms
# ...see if you can find them all!


the next few years are a bit fuzzy.
# Copyright 2010 Daniel Cordero
# Licensed under the GPLv2


in 2008, I got an Asus EeePC 901 (Linux ver.). Within a few days I formatted Xandros and installed Arch.
test "$PWD" = "$HOME" && cd /tmp # I don't clean up after myself


A few months later, it was formatted again for Funtoo.
# When I say "list", I mean space-separated (ahem... $IFS) list.
NETIF_LIST="" # List of interface initscripts
SERVICES="" # List of services to be placed into default runlevel
HOST_FILES="" # List of host-specific /etc files
ETC_FILES="" # List of generic/shared /etc files
HOME_FILES="" # List of files in $HOME
HOME_FOLDERS="" # List of folders in $HOME


==Boxes==
mkdir -p etc/{portage/{package.use,savedconfig,profile},runlevels/default}
* cumin - EeePC 901 - dead (broken screen)
mkdir -p etc/init.d
* rosemary - Acer Aspire 5633 - 1.6GHz core 2 duo
mkdir -p home/$USER
* nutmeg - Desktop (amd64 athlon x2) - 2.2GHz
mkdir -p usr/lib/X11/xdm
* thyme - Desktop (unknown)
mkdir -p var/lib/portage
* heather - dead (blown psu) - amd athlon 1.1GHz
mkdir -p host
* poppy - dead (ps3 firmware update)


* rover - n900
rsync -ar --exclude .keep {/usr/,}local/
rsync -r /etc/portage/{package.use,savedconfig,profile} etc/portage


==looking at==
for service in $SERVICES; do
* server administration (home servers) / backup & sync [[User:Apple/projects/Transplant]]
ln -sf /etc/init.d/$service etc/runlevels/default/$service
* live cds/usbs [[User:Apple/projects/ISOMetro]]
done


==loves==
for netif in $NETIF_LIST; do
* lists!!!
ln -sf /etc/init.d/netif.tmpl etc/init.d/netif.$netif
* emerge(1)
done
* n900
* not being root (but having root access)
* btrfs
* per-process namespaces
* homogenous operating systems


==dislikes==
for home_folder in $HOME_FOLDERS; do
* X(1)
rsync -ra $HOME/$home_folder/ home/$USER/$home_folder
* voting schemes where you cannot rank the candidates
done
* gnu coding standards and practices
 
* debian (and offshoots) and the apt package manager
for home_file in $HOME_FILES; do
* capital letters
cp -a $HOME/$home_file home/$USER/$home_file
test x"$home_file" = "x.xinitrc" && ln -sf .xinitrc home/$USER/.xsession
done
 
 
for etc_file in $ETC_FILES; do
(test "x$(dirname $etc_file)" != "x." && \
test ! -d "$(dirname $etc_file)") && \
mkdir -p etc/$(dirname $etc_file)
cp -a /etc/$etc_file etc/$(dirname $etc_file)/$(basename $etc_file)
done
 
for host_file in ${HOST_FILES}; do
(test "x$(dirname $host_file)" != "x." && \
test ! -d "$(dirname $host_file)") && \
mkdir -p host/$(dirname $host_file)
cp -a /etc/$host_file host/$(dirname $host_file)/$(basename $host_file)
done
 
cp -a {/,}usr/lib/X11/xdm/Xsetup_0
cp -a {/,}var/lib/portage/world
 
tar cf $(hostname)-overlay.tar host/
tar cf usrlocal-overlay.tar local/
tar cf home-overlay.tar home/
tar cf funtoo-overlay.tar etc/ usr/ var/ \
home-overlay.tar usrlocal-overlay.tar $(hostname)-overlay.tar
# DESTRUCTIVE
xz funtoo-overlay.tar # non-destructive
</nowiki>
</tt>
|}
 
==Usage==
 
Fill in the 6 variables at the top of the script. You'll constantly be adding more files as the original system gets more customised.
 
When you're ready (or as a cron job), run the script and save the resulting tarball somewhere.
 
Boot your install environment. Partition, format and unpack (or work up to) a stage3. Grab a portage tree.
 
Unpack the main tarball (you probably don't want to unpack the other tarballs yet):
 
{{Root|<nowiki># tar xvJf --exclude "*.tar" funtoo-overlay.tar.xz -C /mnt/gentoo
</nowiki>}}
 
Take a peek at the list of files in $HOST_FILES and edit them to the host's specification.
 
{{Info|You cannot expect every host to have the exact geometry or architecture as the original host. If, by some miracle, the two are exactly alike, go ahead and unpack the host tarball (probably into <tt>/tmp</tt>).}}
 
{{Info|The host tarball uses the prefix <tt>host/</tt> instead of the regular <tt>etc/</tt>. This is for your protection (and a limitation of the script... but mostly protection).}}
 
Chroot in and run (I suggest in a screen, nohup or another VT):
{{Root|<nowiki># env-update; source /etc/profile
# emerge -uDN world</nowiki>}}
 
Wait (or finish configuration). Remember to make a kernel and <tt># boot-update</tt> (and installing the bootloader to MBR if necessary).
 
Add an identical user (it's not in the script, but you might want to save the output of <tt>$ groups</tt>) and unpack <tt>home-overlay.tar</tt>. If you have anything in <tt>usrlocal-overlay.tar</tt> you can unpack that too.
 
{{Info|If you're installing on a different architecture, the contents of <tt>/usr/local</tt> may be useless for your CPU.
If you're lucky, it may be all architecture-independent/interpreted scripts, or nothing at all.}}
 
If all goes well, reboot (and remove the install environment)!

Latest revision as of 14:19, November 17, 2010

a.k.a. I like my Linux how I like my women... easy to set upflexible.

This is a script to backup and/or transfer a working Funtoo installation onto a fresh install (on the same or a different host).

It won't speed up an install and it doesn't make it easier, but with it you can do a single reboot and have a complete working system without tedious config file editing.

The Script

Code: /usr/local/bin/transplant

#!/bin/bash # I use heavy amounts of bashisms # ...see if you can find them all! # Copyright 2010 Daniel Cordero # Licensed under the GPLv2 test "$PWD" = "$HOME" && cd /tmp # I don't clean up after myself # When I say "list", I mean space-separated (ahem... $IFS) list. NETIF_LIST="" # List of interface initscripts SERVICES="" # List of services to be placed into default runlevel HOST_FILES="" # List of host-specific /etc files ETC_FILES="" # List of generic/shared /etc files HOME_FILES="" # List of files in $HOME HOME_FOLDERS="" # List of folders in $HOME mkdir -p etc/{portage/{package.use,savedconfig,profile},runlevels/default} mkdir -p etc/init.d mkdir -p home/$USER mkdir -p usr/lib/X11/xdm mkdir -p var/lib/portage mkdir -p host rsync -ar --exclude .keep {/usr/,}local/ rsync -r /etc/portage/{package.use,savedconfig,profile} etc/portage for service in $SERVICES; do ln -sf /etc/init.d/$service etc/runlevels/default/$service done for netif in $NETIF_LIST; do ln -sf /etc/init.d/netif.tmpl etc/init.d/netif.$netif done for home_folder in $HOME_FOLDERS; do rsync -ra $HOME/$home_folder/ home/$USER/$home_folder done for home_file in $HOME_FILES; do cp -a $HOME/$home_file home/$USER/$home_file test x"$home_file" = "x.xinitrc" && ln -sf .xinitrc home/$USER/.xsession done for etc_file in $ETC_FILES; do (test "x$(dirname $etc_file)" != "x." && \ test ! -d "$(dirname $etc_file)") && \ mkdir -p etc/$(dirname $etc_file) cp -a /etc/$etc_file etc/$(dirname $etc_file)/$(basename $etc_file) done for host_file in ${HOST_FILES}; do (test "x$(dirname $host_file)" != "x." && \ test ! -d "$(dirname $host_file)") && \ mkdir -p host/$(dirname $host_file) cp -a /etc/$host_file host/$(dirname $host_file)/$(basename $host_file) done cp -a {/,}usr/lib/X11/xdm/Xsetup_0 cp -a {/,}var/lib/portage/world tar cf $(hostname)-overlay.tar host/ tar cf usrlocal-overlay.tar local/ tar cf home-overlay.tar home/ tar cf funtoo-overlay.tar etc/ usr/ var/ \ home-overlay.tar usrlocal-overlay.tar $(hostname)-overlay.tar # DESTRUCTIVE xz funtoo-overlay.tar # non-destructive

Usage

Fill in the 6 variables at the top of the script. You'll constantly be adding more files as the original system gets more customised.

When you're ready (or as a cron job), run the script and save the resulting tarball somewhere.

Boot your install environment. Partition, format and unpack (or work up to) a stage3. Grab a portage tree.

Unpack the main tarball (you probably don't want to unpack the other tarballs yet):

Template:Root

Take a peek at the list of files in $HOST_FILES and edit them to the host's specification.

Template:Info

Template:Info

Chroot in and run (I suggest in a screen, nohup or another VT): Template:Root

Wait (or finish configuration). Remember to make a kernel and # boot-update (and installing the bootloader to MBR if necessary).

Add an identical user (it's not in the script, but you might want to save the output of $ groups) and unpack home-overlay.tar. If you have anything in usrlocal-overlay.tar you can unpack that too.

Template:Info

If all goes well, reboot (and remove the install environment)!