Jeff Mikels » Blog Archives

Author Archives: Jeff Mikels

ffmpeg compilation script for Ubuntu

Geekery

Ubuntu doesn’t provide the latest ffmpeg or include the modules I use all the time, so I wrote a little script to automatically compile and install my own version:


#!/bin/sh

# https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

# SERVER COMPILATION SKIPS ffplay AND A X11 DEPENDENCIES

echo 'THIS SCRIPT USES SUDO, SO IT MIGHT ASK FOR YOUR PASSWORD'
sudo apt-get update -qq

sudo apt-get -y install \
	autoconf \
	automake \
	build-essential \
	cmake \
	git \
	libass-dev \
	libfreetype6-dev \
	libtheora-dev \
	libtool \
	libvorbis-dev \
	mercurial \
	pkg-config \
	texinfo \
	wget \
	zlib1g-dev \
	yasm \
	libx264-dev \
	libvpx-dev \
	libfdk-aac-dev \
	libmp3lame-dev \
	libopus-dev



cd ~/src

# DO WE NEED NASM?
# wget http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2
# tar xjvf nasm-2.13.02.tar.bz2
# pushd nasm-2.13.02
# ./autogen.sh
# PATH="$HOME/bin:$PATH" ./configure --prefix="/usr/local" --bindir="/usr/local/bin"
# make
# sudo make install


# DO WE NEED x265
if cd x265 2> /dev/null; then hg pull && hg update; else hg clone https://bitbucket.org/multicoreware/x265; fi
cd x265/build/linux
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/usr/local/" -DENABLE_SHARED:bool=off ../../source
PATH="$HOME/bin:$PATH" make
sudo make install


# ACTUAL COMPILATION
cd ~/src
wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" ./configure \
  --prefix="/usr/local" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I/usr/local/include" \
  --extra-ldflags="-L/usr/local/lib" \
  --extra-libs="-lpthread -lm" \
  --bindir="/usr/local/bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree

make
sudo make install
hash -r


Published by:

WordPress Development Behind the Scenes

Geekery

After doing some research into how to develop a WordPress site in a “staging” area behind the scenes before going public, I have finally stumbled upon an elegant and simple solution:

  • Using a plugin like simply-static, convert all wordpress-generated data to static html files.
  • Tell nginx to try those files first (unless there is a logged-in user) falling back to the normal wordpress generation when they can’t be found.
  • Now, public viewers will bypass wordpress entirely, grabbing all the static files while you happily do your coding in the background.
  • When you are ready to go public with your modified design, either regenerate the static files for a super-fast site or delete the static files. Without the html files, nginx will simply hand the requests over to wordpress for dynamic generation.
Published by:

Is it Discrimination to Discriminate against Discriminators?

Front Page Lafayette Leadership

My church office received an email today that called me out for what was printed in the local newspaper reporting on my involvement in the City Council meeting last Monday.

A woman named Kathy wrote this:

Dear Pastor Mikels,

Reading the newspaper Tuesday morning, I felt quite sad to read about your objections to our community protecting the rights of transgendered people and your positioning yourself as one who should judge them. I do not believe discrimination against anyone is right. Your suggestion that transgendered people are not submitting to nature or nature’s God–and therefore subject to discrimination–is highly and inappropriately judgmental and hurtful.

I hope you will refrain from this line of speaking about others.

The irony of our current social climate is that a person can say in one sentence, “I do not believe discrimination against anyone is right,” and then in the next sentence call someone’s behavior “highly and inappropriately judgmental and hurtful.” Not only is the first sentence pragmatically impossible, the accusatory tone of the second sentence invalidates the claim of the first.

Nevertheless, now that I have entered into this world, I’m committed to this dialogue. I don’t feel a burden to defend myself, but I feel a deep burden to help all of us think through these issues lovingly and rationally even if we can’t discuss them biblically.

It took me 45 minutes to craft a reply, but this is what I wrote:


Hi Kathy,

Is it okay for me to give you a phone call?

I’ve been working for months to build a dialogue with the Lafayette Pride office to express my love and concern for people in the LGBT community, and to have conversations about how the faith community can do a better job of showing that love even if we disagree with their lifestyles. They haven’t replied yet, but I’m still working on it.

Furthermore, I have friends in the LGBT community, and I think if you gave me a few minutes of human-to-human time, you would see me in a different light.

After all, that’s really what all of this debate is about between “religious freedom” and “tolerance.” I think it all really comes down to the fact that people aren’t treating each other as humans but as categories.

For example, you have categorized me as someone who believes I should judge transgendered people, and yet I do not judge them nor do I want to. You have also categorized me as someone who thinks it is right to discriminate against transgendered people, and yet that too is inaccurate.

Sadly, I don’t think you see me as a human being who cares deeply for the people around me both those who are like me and those who are different from me, and in that regard, I think you might be discriminating against me.

If we had a chat over a cup of coffee, I think you would discover some things about me.

  1. I don’t buy into statements that are given to me by other Christians without wrestling through them personally. As a result, I don’t buy the statement that some Christians throw around that gender confusion or transgenderism is a sin. Additionally, I don’t believe that granting civil rights protections to transgender people will suddenly endanger women in our society and increase the chances for sexual exploitation in our bathrooms. I firmly oppose both the fear-motivated statements and the naively traditional statements.
  2. I also don’t buy into statements that are given to me by the secular media or by the modern “spirit of the age.” As a result, I don’t buy the statement that the only way for transgender people to live is to fully express their “true gender identity” as opposed to the one they were “assigned at birth.” The reason I don’t buy that statement is that I have known VERY effeminate men who were able to find great joy in just being really sensitive men. I have also known at least one woman who lived for many years as a transgender man only to later realize that there was great joy to be found in embracing her biological femininity. She has since completely turned around and embraces womanhood as her “identity.”
  3. I DON’T oppose anti-discrimination laws for any category of people. In fact, I think there are many categories that are underrepresented. Our laws say nothing protecting the rights of people who cannot work on a Holy Day. Sure there are “religious” protections on the books, but at least in Indiana, an employer can fire an employee who refuses to work on Sundays. Furthermore, I think it is wrong for an apartment complex to refuse to rent an apartment to a biological man who is dressed as a woman.
  4. Finally, I DO realize that there are some forms of “discrimination” that are allowable (and encouraged) in a pluralistic society. For example, Hollywood is allowed to discriminate in hiring when it comes to personal appearance. More attractive people make more money. Should we outlaw that discrimination? I don’t think so. It’s sad that it exists, but it should not be illegal. Additionally, a college whose declared purpose is to educate students in the Islamic faith should be allowed to discriminate in hiring when it comes to a person’s adherence to the Koran, and I don’t think Purdue should be forced to hire professors who deny Darwinian Evolution. In other words, SOME discrimination in our society is necessary, and SOME discrimination in our society is healthy. In fact, in order to live in a pluralistic society, we CANNOT outlaw every single act of discrimination as if it were even logically possible to do so.

In conclusion, the reason I opposed the amendment was not because I want to encourage “discrimination” against transgender people but because I think the issue in the amendment is ill-defined and unclear in two ways:

  1. The scientific understanding of “gender identity” is unclear. Psychiatrists are still trying to wrestle with what the DSM-5 calls “gender dysphoria” and the right way to treat it. As a result, the societal implications of fully embracing “transgender” as a category of human being are unclear. Some good science indicates that transgenderism is actually a birth defect of sorts resulting from low incidence of androgens in the body during gestation and infancy (see my blog article for the link). However, there is other good evidence that gender dysphoria is a condition that can be remedied either through psychological counseling or religious experience. Therefore, to categorize transgenderism as a protected class would be to completely ignore the science indicating transgender people might actually be better off if they could find joy in their assigned gender.
  2. The religious exemptions in the proposed Lafayette HRO only cover issues of employment. If a church-run school or homeless shelter wished to have sex-segregated bathrooms, showers, or locker rooms, according to the letter of the HRO, those organizations could be found guilty of “discrimination” against transgendered students. I grant that Target should have the right to desegregate its bathrooms. Much of Europe already has only unisex bathrooms, and people live there just fine. However, I think churches, mosques, church schools, and yes, businesses run by conscientious religious people should have the right to create sex-segregated bathrooms if they wish.

The media tends to always put people in two camps. Either you are pro-choice or pro-life. Either you are conservative or liberal. Either you are for love or for hate. The problem is that no one is ever one or the other. We are all real people with pains, hurts, loves, and passions.

And if we all stopped calling each other names, we might be able to understand each other. Luckily, we now live in a society where the vast majority of Christians no longer use rude and offensive language when speaking of LGBT people, but we now live in a society where people of religious conviction and a social conservative perspective are labelled as bigoted or hateful.

No matter what you believe, I will show you respect and hear you out, so again, I ask if you would share a cup of coffee with me.

Attempting to live with Grace and Truth,
Jeff Mikels

P.S. If you are interested to read my statement to the City Council in full, I posted it to my blog here: http://jeff.mikels.cc/posts/my-statement-to-the-lafayette-city-council-on-gender-identity/

Published by:

My Statement to the Lafayette City Council on Gender Identity

Last night, the Lafayette City Council met to consider putting an amendment into the Lafayette Human Relations Ordinance. Some time ago, the city codified a “Human Relations Ordinance” to fight against discrimination in our town. It created a Human Relations Commission tasked with the job of investigating cases of discrimination in our city and offering suggestions and education to individuals and businesses found to be discriminatory.

Continue reading

Published by:

Solving MMS Problems on Cricket Wireless

I have an android phone running on the Cricket Wireless network. I followed all their recommended settings, but I still had a major problem. The phone would not send or receive MMS messages when I was connected to Wi-Fi.

Well, my solution was found on reddit, but I will just give you the quick summary here if you have found the same problem:

Do everything like Cricket suggests on their APN settings page, but instead of using proxy.aiowireless.net where they tell you to, use the IP address of their servers directly. Pick one of the following numbers and use it instead of the proxy.aiowireless.net.

    <li>192.168.196.78</li>
    <li>192.168.196.79</li>
    <li>192.168.196.117</li>
    <li>192.168.196.118</li>
    

That should allow you to continue to use your favorite SMS app but still send and receive MMS regardless of your Wi-Fi settings.

Published by:

PG-13: Benefits of Eliminating Pornography

Spiritual Health

The views expressed in this video are not my own, but the scientific research is fascinating nonetheless. The video is not explicit, but it is not appropriate for children unless you use it as a teaching tool.


 

As a pastor, I hear the stories all the time.

One more guy is hooked on Internet Pornography. One more wife is struggling with the feeling that her husband is cheating on her.

There are so many proposed solutions especially among Christians. We vilify the behavior and try to convince men that they are doing something wrong in the hopes that their internal sense of good and evil and a good dose of teaching about the Holy Spirit will give them the willpower to say “No” to wrongful clicking. If that doesn’t work, we might try support groups and accountability groups and book studies.

I don’t have time today to analyze these different approaches, but there is one approach I haven’t yet seen—Science. In the video posted above, you can watch a TED talk that includes scientific research into the deleterious effects of Internet Pornography and the benefits of avoiding it. The speaker is clearly not taking a Christian perspective on sexuality, but the research is fascinating nonetheless.

Especially for men, I want to keep the conversation open on this topic so that guys who struggle with this can find strength to put it behind them once and for all.

Published by:

The Ethics of Superintelligence

Today, during my lunch, I watched a very interesting TED presentation from Nick Bostrom regarding machine intelligence and the difficult questions surrounding it. What I didn’t realize at the time was that Bostrom is a Philosopher more than an engineer. As a result, his talk ended up being about the ethical questions brought on by the potential of computer superintelligence.

Now, if you don’t have time to listen to the whole talk, I’ll just put the main points here for you: Continue reading

Published by:

Bash // Create or Attach to Screen Session on Login

Geekery

I use GNU Screen for everything I do in Linux… perhaps you do too, but perhaps you are annoyed that every time you log in to a terminal session on your Linux machine, you have to go through the one extra step of reconnecting to your screen session or checking to see if one is already running and then maybe creating a new session.

Here’s a way to make sure whenever you SSH into your Linux server, you always get right back where you were in your previous screen session just like you left it. The added bonus of this is that whenever you detach from your screen session, you are also automatically logged out of the server.

Simply add these lines to the bottom of your .bash_profile (watch out for word wrapping).

# start screen session if not already started
# or connect to screen session if not already in it
echo ''
echo '----------- WE LIKE SCREEN ------------------------------'
if [ ${TERM:0:6} != "screen" ]
then
    echo "Attempting to connect/create screen session."

    # We don't want to forcibly disconnect other sessions if they are
    # Attached, so we check for Detached sessions first
    HAVE_DETACHED=$(screen -list | grep Detached)
    HAVE_ATTACHED=$(screen -list | grep Attached)

    if [ -n "$HAVE_DETACHED" ]
    then
        echo "Attaching to existing screen session"
        exec screen -r

    elif [ -n "$HAVE_ATTACHED" ]
    then
        echo "Existing screen sessions are all attached"
        echo "use 'screen -rd' to detach and attach here."
    else
        echo "There are no running screen sessions."
        echo "Creating new screen session."
        exec screen
    fi
else
        echo "Already in a screen session. Cool."
fi
Published by:

Hide Desktop for Distraction Free Writing

Distraction free writing is all the rage these days, and I’m a huge proponent of the movement because I am very prone to distraction. Why right now, I should be doing something else, but I got distracted with this!

Anyway, one of my essential tools for a distraction free environment is a totally black desktop with no icons showing. Each operating system has techniques for making this happen, but I have found a solution that works on all operating systems equally. The only requirement is that you have Python installed (tested on 2.7).

This code runs as an app, so you don’t have to change any operating system settings to get it to work, and as soon as you want to see your desktop again, just double-right-click on the black background and it will exit!

Here’s the python code to make it happen (watch out for word wrapping).

#!/usr/bin/python

from Tkinter import *

class App():
    def __init__(self):
        self.root = Tk()
        self.root.overrideredirect(1)

        screen_width = self.root.winfo_screenwidth()
        screen_height = self.root.winfo_screenheight()

        self.frame = Frame(self.root, width=screen_width, height=screen_height,
                           borderwidth=0, relief=RAISED, background="#000000")
        self.frame.bind("<FocusIn>", self.unfocus)
        self.frame.bind("<Button-1>", self.unfocus)
        self.frame.bind("<Double-Button-1>", self.unfocus)
        self.frame.bind("<Double-Button-2>", self.quit)
        self.frame.pack_propagate(False)
        self.frame.pack()

        self.root.geometry('%dx%d+%d+%d' % (screen_width, screen_height, 0, 0))

        self.root.lower();
        # self.root.call('wm', 'attributes', '.', '-topmost', True)
        # self.root.after_idle(self.root.call, 'wm', 'attributes', '.', '-topmost', False)

    def quit(self, event):
        self.root.quit()

    def unfocus(self, event):
        self.root.lower()


app = App()
app.root.mainloop()
Published by:

A Different Question about Gender Differences

This past week, I tried an experiment.

I posted a couple images to my Facebook timeline that I thought had the potential to become somewhat viral. That is, I thought these images would be shared around Facebook, and I wanted to see how widely they would go.

Well, my little experiment took me in a different direction than I thought it would.

So here’s the back-story. Continue reading

Published by:

Why are church people so strange?

Front Page

Why do church people do . . . ?

There are a lot of things that church people do that are different from the way the rest of the world lives:

  • Church people go to a church gathering nearly every Sunday while most people in the world rarely do anything “every week” except for weekly obligations like school/work or entertainment choices like eating out, seeing movies, etc.
  • Church people not only attend church gatherings, but they often are actually doing things at those gatherings like playing music, teaching a class, or greeting people.
  • Church people get together in smaller groups for “Bible Study” or “Service Projects” or things like that while most people might have a periodic game night with friends, hang out at the bar, or just stay home watching TV.
  • Church people volunteer their time to do things for church-owned buildings and grounds like cleaning, fixing, and upgrading while the rest of the world looks with apathy, frustration, or even disdain on church buildings taking up valuable real-estate.
  • Church people give money to the church, some even give more than 10% of their entire household income, while the rest of the world generally gives only 3% of their income to all charitable causes combined.

Why do church people do such weird things?
Continue reading

Published by:

Do the courts define marriage?

Same-sex Marriage is Now the Law of the Land

On June 26, 2014, wlfi.com published an article with this headline:

Same-sex couples wed at Tippecanoe Co. Courthouse

After great amounts of debate earlier this year over the locally infamous HJR-6, a resolution by the two houses of Indiana state government to put a prohibition against same-sex marriage into the state constitution, our legislators decided that one of the phrases in the resolution went too far. In response, they modified the resolution (now called HJR-3) and thereby also delayed its appearance on an Indiana ballot until 2016. Continue reading

Published by:

Single Sign-on for Multiple WordPress Installations

Geekery

Lafayette Community Church uses a couple different WordPress installations for its website.

I set it up so that users need log in only once, and their login persists across both sites. I didn’t need to use any plugins or LDAP or third party authentication systems for this.

Here’s what you need to do to make it work for your site as well:

  • Both WordPress installations must be running on the same domain, even though they might reside in different subdirectories or different subdomains.
  • Both installations must be running on the same database but with different table prefixes.
  • If your secondary site already has users, you will need to do manual database updates, and that’s beyond the scope of this tutorial. The rest of this tutorial assumes you are okay with the fact that your secondary installation’s user table will be completely ignored and both installations will use the primary installation’s user table.
  • Change the wp-config.php file on the secondary blog to tell WordPress which table to use for users.

define('CUSTOM_USER_TABLE', 'blog1_users');         // replace blog1 with the table prefix from your
define('CUSTOM_USER_META_TABLE', 'blog1_usermeta'); // main wordpress installation
  • Change both wp-config.php files to unify the cookies across the two installations. I’ll go into more detail here.

Unifying Authentication Cookies across multiple WordPress Installations

WordPress uses two cookies to handle authentication, but there are a number of settings that need to be synchronized between installations so that WordPress can read and understand the cookies properly.

Authentication Keys

Your WordPress installations may or may not have custom authentication keys set up, but in order for this to work properly, you should have the same keys set up on each installation. In wp-config.php on BOTH sites, add these lines:


/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY',         'custom-hash-here');
define('SECURE_AUTH_KEY',  'custom-hash-here');
define('LOGGED_IN_KEY',    'custom-hash-here');
define('NONCE_KEY',        'custom-hash-here');
define('AUTH_SALT',        'custom-hash-here');
define('SECURE_AUTH_SALT', 'custom-hash-here');
define('LOGGED_IN_SALT',   'custom-hash-here');
define('NONCE_SALT',       'custom-hash-here');

Of course, you want to replace “custom-hash-here” with different random strings, and of course, if you already have these values set in your wp-config.php files, you need to replace what’s currently there with these so that both sites are using the same exact settings.

Cookie Settings

Hash, Domain, and Path

When WordPress uses three defined constants when creating authentication cookies for the browser: COOKIEHASH, COOKIE_DOMAIN, and COOKIEPATH.


define('COOKIEHASH', 'custom-hash-here'); //define the hash
define('COOKIE_DOMAIN', '.example.org');  //remove the leading dot if you aren't using subdomains
define('COOKIEPATH', '/');                //this must be a parent directory to all WP installations

Again, these three settings must be exactly the same across your all installations, but there are additional concerns:

The COOKIE_DOMAIN and the COOKIEPATH must be parents of both installations. That means, if your installations are on separate subdomains, the COOKIE_DOMAIN must apply to both (a leading dot before the domain name will accomplish this), and if your installations are using separate subdirectories, your COOKIEPATH must be a parent to both. To be safe, you can make it ‘/’, but you actually want your cookies to be as specific as possible, so if one blog is in example.org/wordpress/blog1 and the other blog is in example.org/wordpress/blog2, you can use /wordpress as your COOKIEPATH, or if one blog is blog1.example.org/wordpress and the other is blog2.example.org/wordpress, you should also be able to use /wordpress as your COOKIEPATH.

Site and Admin

WordPress uses two defined constants to help it look for the right cookies to see if a user has been authenticated. One of those constants is SITECOOKIEPATH and it is used by the WordPress frontend. The other is ADMIN_COOKIE_PATH and it is used by the WordPress backend.

Simply set both of them to be the same as the COOKIEPATH and you should be fine.


define('SITECOOKIEPATH', COOKIEPATH);
define('ADMIN_COOKIE_PATH', COOKIEPATH);

Conclusion

So, for completeness, here are all the settings together:

In secondary wp-config.php files:


define('CUSTOM_USER_TABLE',      'blog1_users');    // replace blog1 with the table prefix from your
define('CUSTOM_USER_META_TABLE', 'blog1_usermeta'); // main wordpress installation

In all wp-config.php files


define('AUTH_KEY',           'custom-hash-here');
define('SECURE_AUTH_KEY',    'custom-hash-here');
define('LOGGED_IN_KEY',      'custom-hash-here');
define('NONCE_KEY',          'custom-hash-here');
define('AUTH_SALT',          'custom-hash-here');
define('SECURE_AUTH_SALT',   'custom-hash-here');
define('LOGGED_IN_SALT',     'custom-hash-here');
define('NONCE_SALT',         'custom-hash-here');
define('COOKIEHASH',         'custom-hash-here');
define('COOKIE_DOMAIN',      '.example.org');
define('COOKIEPATH',         '/');
define('SITECOOKIEPATH',     COOKIEPATH);
define( 'ADMIN_COOKIE_PATH', COOKIEPATH );

Post a comment if it doesn’t work for you.

Published by:

Transfer an Entire Ubuntu System to a new Drive

Geekery

After having done this same procedure a number of times, I have finally figured out the best way of transferring an entire Linux System from one drive to another and still have it be bootable.

Step 0: Did you format and partition the drives the way you want?

I write this down just to clarify that I’m assuming you know enough about Linux to have been able to partition and format your new drive the way you want. Furthermore, this guide assumes that your entire root file structure exists on one partition. If you are advanced enough to know how to have your filesystem span multiple partitions (e.g. one partition for /, another for /boot, another for /home, etc), then you should be able to translate these steps for your own situation.

Step 1: Mount your source and target devices.

Let’s say your current root filesystem exists on /dev/sda1 and you want to move it to /dev/sdb1. We want to mount the filesystems in a fresh location so that we are only dealing with those two filesystems. Note also that your target filesystem should be cleanly formatted and large enough to contain all the files from the source filesystem.

Commands starting with # should be run with root privileges.

# mkdir /mnt/source /mnt/target
# mount /dev/sda1 /mnt/source
# mount /dev/sdb1 /mnt/target

Step 2: Copy files

The following command will copy all the files from the source filesystem to the target filesystem

# rsync -av /mnt/source/ /mnt/target/

Note that the “v” option stands for “verbose” and tells rsync to print the name of every file it copies. You can remove the “v” option if you don’t want to see that output.

Step 3: Copy again (optional)

Since you are moving a live filesystem, it’s possible that a few things were changed. Usually, we don’t care about these incidental operating system changes, but just to be sure, you can run the exact same rsync command a second time.

# rsync -av /mnt/source/ /mnt/target/

Step 4: Mount System Directories and “chroot”

The following steps will allow you to step into the new filesystem just as if you had booted from it.

These commands will make the new filesystem work just like the real filesystem so that when you switch into it, the operating system isn’t confused.

# mount --bind /proc /mnt/target/proc
# mount --bind /sys /mnt/target/sys
# mount --bind /dev /mnt/target/dev
# mount --bind /run /mnt/target/run
# mount --bind /dev/pts /mnt/target/dev/pts
# mount --bind /etc/resolv.conf /mnt/target/etc/resolv.conf

This command puts you into the new filesystem just as if you had booted from it.

# chroot /mnt/target

At this point you are in your new filesystem. Note however, that the Linux kernel, modules and other operating system files are all still loaded from the real root, so you aren’t actually booted into your new system, but since this new filesystem is identical to the old one, everything should work just fine.

Step 5: Fix fstab

Get the UUID of your new filesystem.

# blkid |grep /dev/sdb1

(If your target filesystem was something other than /dev/sdb1, use that instead.)

In the command output, you will see something like this.

/dev/sdb1: UUID="af6dcc3f-a5c7-42a2-a2b5-e94ccac3cdd9" TYPE="ext4"

You need to know both the UUID and the TYPE, but you don’t need the quotation marks. Copy them down somewhere.

Graphical editors might not work from the chroot environment, so you will do better using a console based editor like nano or vim

# nano /etc/fstab

If you aren’t familiar with editing fstab files, you need to be careful here, but you shouldn’t be afraid. Each line in an fstab file tells the operating system which device to use for which part of the filesystem. The format is the same:

[device] [mount point] [filesystem type] [options] [dump] [pass]

(Each “column” is separated by one or more spaces or tabs, so even though I use the word “column” to refer to each item, they might not look like they are arranged into neat columns.)

One of the lines will have a simple slash in the second column, and that’s the line we want to change. It might look like this:

UUID=32322b4a-6b43-48da-a021-1f395a61bd2d / ext3 defaults,noatime,nodiratime 0 1

Replace the numbers after UUID= with the UUID numbers you got from the blkid command above, and also replace the ext3 (or whatever is in the third column) with the TYPE you got from the blkid command.

Save the file and exit.

Step 6: Fix initramfs

We only have two steps left. When Linux boots, in most cases, the first thing that is loaded is the kernel and the second thing that is loaded is an initial ram filesystem or initramfs. The initramfs is like a temporary operating system that helps the Linux kernel get everything set up for real. If your system doesn’t need an initramfs, you can skip this, but if you are running a system that doesn’t need one, you probably don’t need to be reading these instructions anyway!

This step is again platform specific, but on Ubuntu, the command is simple:

# update-initramfs -u

It may take a minute or two.

Step 7: Install the bootloader

Finally, to make sure your new drive is bootable, we need to install a bootloader. Most Linux systems these days are using grub or grub2 for their bootloader, and there are a lot of confusing ways out there to “fix” your bootloader or to “install” a bootloader, however, your Linux system should already know how to do this.

If you are running Ubuntu, simply type this:

# dpkg-reconfigure grub-pc

When the prompts ask you, be sure to install grub to your new device. In our example scenario, you would pick /dev/sdb.

Once this is done, you should exit the chroot environment, reboot your computer, tell your BIOS to boot from the new drive, and enjoy running Linux from your new drive!

# exit
# reboot

Conclusion

This has taken a number of steps, but in summary, transferring to a new drive isn’t all that hard. It really just boils down to these things:

  • freshly mount the source and target filesystems
  • transfer all files with rsync
  • create a good chroot environment and then chroot into it.
  • update the fstab file and the initramfs file
  • install the bootloader

The only tricky part is discovering how your specific Linux distribution handles the initramfs and bootloader installation. I’ve described how Ubuntu handles it here, but if your distribution handles it differently, put a comment below!

Published by: