Sunday 16 December 2012

Building and using a Linux UML environment

Intro

I want to test a script that randomly creates files all over a file system.

Naturally, I don't want to test this on my Linux system.

I tried fakechroot fakeroot chroot and schroot but I could not get them to do what I wanted.
fakechroot fakeroot chroot in particular allowed access to all files using '/..' - not what I wanted at all.

Method

I'm using pbuilder because it seems easy (once you know how).

  • It can also be run as a user.
  • It does not take up much space since UML environment is in a tar gzip file.
  • Changes within UML can be saved or lost (default).

To construct your sandpit

I called it 'sandpit', but you can call it what you like. Just replace sandpit with your preferred name.
Also, there is nothing stopping you making multiple sandpits.

pcreate -a amd64 -d lucid sandpit

I was running 64 bit Linux so I choose amd64
I did not care what distro I used so I choose lucid

To put/copy files into your sandpit

Files in ~/Projects/sandpit are available within your sandpit

cp ~/Projects/sandpit/

To get into your sandpit

ptest -p sandpit

After you exit, any changes will be gone.

To save changes in your sandpit

ptest -p sandpit --save