RSS Feed

Linux containers (LXC) on Arch Linux


Due to a recent Q&A from DistroWatch.com, I am considering the advantages of using the scheduled-release or fixed-release distros, especially Debian which is famed of its stability. The following is the quote from DistroWatch.com,

Rolling releases do tend to have their downsides though. For instance, it is difficult for third-party developers to create software for rolling-releases as a rolling-release distribution is a moving target. It is difficult to target and support an operating system which is changing on a regular basis.

I agree with this point, because I have to change the source code on my old project which uses CEGUI. Moreover, latest PHP source code may not work on the web hosting server, due to the version differences. Though some people argue that rolling release like Arch Linux is not stable, yet I am very satisfied with its stability. The only thing is the compatibility problem to our own source code and other distros or OSes.

Because of this problem, the Debian is always my interested distro. Yet Debian packages are normally not up-to-date, and there is no Mozilla Firefox in its official repository due to the strong philosophy in Debian.

Running the different OSes in the virtual machines such as VirtualBox and Qemu with KVM is a very good solution. However, both solutions show a strong feeling that an OS (guest) within another OS (host). VirtualBox is really useful because of the configuration of the bridged network is very easy. Moreover, the USB devices sharing allows to use the Windows in the VirtualBox to do the printing and using the interactive projector (which beyond my expectation). On the other hand, Qemu is difficult to setup the bridged network. (But Android Emulator is using Qemu.)

There are some disadvantages on VirtualBox. The 3D graphics do not work properly in VirtualBox (I didn’t try on Qemu about 3D graphics). However, we can still install the Direct3D drivers through the VirtualBox Guest Addition. Furthermore, the solutions of using VirtualBox and Qemu require to create virtual hard drives. That means, transferring the files requires some networking solutions such as FTP or SSH. Yet, VirtualBox allows easier solution that mounts the shared folder from the host.

Interestingly, when I come across to the Linux Containers (LXC), this shows an interesting alternative to the VirtualBox and Qemu. Unlike the VirtualBox or Qemu, the guest OS can be run almost side-by-side with the host OS.

Running GVim in LXC on Arch Linux

Running GVim in LXC on Arch Linux

Setup LXC network

There are some useful tutorials/documents regarding how to setup LXC on the Linux distribution on the Internet. However, I found some difficulties when setting up the LXC on the Arch Linux. In Arch Linux, the kernel does not support User Namespace for the LXC. Thus, the LXC has to run in root privilege.

(I will not explain some of the basic steps such as using the commands lxc-create, lxc-start, lxc-stop, etc.)

After creating the container, the network support is also very important, because by default, the container cannot access the network. The easiest way is using bridge.

To setup the bridge, we can use the netctl.

Create a static IP for the netctl,

#In the /etc/ctl/lxbridge
Description="LXC Bridge"
Interface=br0
Connection=bridge
BindsToInterfaces=(wlan0) #Depends which connection we want to bind, do not use multiple interface
IP=static
Address=10.0.2.1/24 #Any
FwdDelay=0

Then,

sudo netctl start lxcbridge

This will produce a bridge interface br0.

Then, similar to Qemu, iptables and IP fowarding are required.

sudo sysctl net.ipv4.ip_foward=1
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE #where wlan0 can be others

Note: iptables is a must, despising whether the iptables service is started or not.

Then, in the “config” file of the created container, we have to setup the networking

lxc.network.type=veth
lxc.network.link=br0
lxc.network.flags=up
lxc.network.name=eth0
lxc.network.ipv4=10.0.2.2/24
lxc.network.ipv4.gateway=10.0.2.1 #Based on the Bridge address

Because of using the root, the lxc-usernet file is not required to be configured.

In order to run the GUI application, in the config file, we can add this

lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
lxc.mount.entry = /tmp/.X11-unix tmp/.X11-unix none bind,optional,create=dir
lxc.mount.entry = /dev/video0 dev/video0 none bind,optional,create=file

After installing GUI application such as GVim in the guest, to run and use the display,

DISPLAY=:0 gvim

This will run the GUI application as on the host.

Setup LXC sound

In order to play the sound, this can be done through PulseAudio. (I mostly refers to this page.)

The easier way is using the paprefs on the host OS and “Enable network access to local sound devices” in the “Network Server” tab. However, it can also be done in the command-line,

pactl load-module module-native-protocol-tcp #no root required

(If referring to other tutorials, there are other parameters. But in my case, the above command is sufficient.)

Note: The above command is run on host OS.

Once the module loaded, in the guest (container), we can set the environment variable,

export PULSE_SERVER=192.168.1.2 #where the IP address is the host IP address

Then, using the mplayer on any audio file can play the sound successfully.

 

Please note that LXC does not work with non-Linux OS such as Windows. There are some available OS templates for the container, such as Debian, CentOS, Fedora, Gentoo,OpenMandriva, OpenSUSE, and Ubuntu. This is very interesting that we can use different package manager in one computer almost seamlessly working on the host OS.

So far I didn’t test the OpenGL in container. But running glxinfo, it shows the same output as the host computer. I expect that it is using the host display, so the OpenGL should have no problem.

 

What next?

My next intention is to make the container accessible through the LAN of the host OS. Needs time to figure it out.

elinks “Host not found” crash in Arch Linux


I have come across with this problem for quite a long time. Whenever I elinks to a website, such as google.com or yahoo.com, it shows the message “Host not found”. I tried to google about the “elinks host not found”, “elinks resolve problem”, etc, none of them are relevant to my problem.

I thought it is the package error. But when I come across installation of the Arch Linux on a fresh computer, the elinks works fine.

The elinks can browse the http://localhost without any problem. And if I browse a website with the IP address (not the domain name), and if the website does not have redirection, then it works fine also. I think the problem is happened when elinks is trying to resolve the domain.

When going to seek for the help in the forum, in order to prepare significant information to other users, I tried to gather the error message as much as possible. Then I come across with the following message and I typed it out in “leafpad” (since copy and paste does not work in the terminal emulator).

elinks(dump_backtrace+0x22)[0x80ff9c2]
elinks[0x80cf3da]
elinks[0x80cfa5c]
linux-gate.so.1(__kernel_sigreturn+0x0)[0xb77c1d28]
elinks(timeval_add+0xf)[0x810463f]
/usr/lib/libsamba-util.so.0(timeval_current_ofs+0x34)[0xb5d51b64]
/usr/lib/samba/libgse.so(name_query+0x87)[0xb5cabe87]
/usr/lib/libnss_wins.so.2(_nss_wins_gethostbyname_r+0x4e8)[0xb5f24148]
/usr/lib/libnss_wins.so.2(_nss_wins_gethostbyname2_r+0x32)[0xb5f242]
/usr/lib/libc.so.6(+0xd217c)[0xb703917c]
/usr/lib/libc.so.6(getaddrinfo+0xe8)[0xb703a798]
elinks(do_real_lookup+0x69)[0x80cb0a9]
elinks[0x80cb24d]
elinks(start_thread+0xc0)[0x80cf110]
elinks[0x80cb360]
elinks(find_host+0xaf)[0x80cb4af]
elinks(make_connection+0xac)[0x80cc15c]
elinks(http_protocol_handler+0x4f)[0x80e22df]
elinks[0x80c91e0]
elinks[0x80c994f]

From the error message, I found that there is something wrong about the libnss_wins.so.2. Then I remembered I have done something regarding the nss for the Samba before. Thus, I open the /etc/nsswitch.conf and found the “wins” in “hosts” key.

The following is the corresponding line,

hosts: files wins dns myhostname

I remembered that this setting was done long time ago, and elinks never faced this problem before. Just a trial-and-error, I remove the “wins” from the line and elinks to Google again. Now it works.

So, it is confirmed that the “wins” is a problem. Then I add the wins again and disable the sambad systemd service and run the elinks. The problem still exists. That means it is not the sambad service problem, but the nsswitch.conf.

As a result, I just put the “wins” after the “dns”. Now, elinks work fine.

As a conclusion, the “wins” can be added, but only after the “dns”. So that, the elinks will use the DNS to resolve the domain first instead of using libnss_wins.so to resolve the the Windows computer name before hand, which causes some errors. Problem solved.

Experience of flashing ROM to Samsung devices

Posted on

Previously, I wrote my experience about installing CyanogenMod on the old Samsung phone. There are something worth to know before flashing, other than backup the precious data, download the ROM and tools, and take for any risk.

In my experience, it is best to get the stock ROM (that is the original ROM or firmware). This is to prevent some unexpected outcomes. With the stock ROM, at least we can recover to the (true) factory setting.

In order to flash the ROM, rooting is not required. But with an un-rooted Android, the backup will only works on the SD card (internal or external) and backup feature from the apps themselves, such as WhatsApp conversation backup and Wechat conversation backup. That means, all the games data and other apps data cannot be backup.

Therefore, if possible, root the phone then backup the data with Titanium Backup, then we no need to save the data to the cloud.

Flash a ROM or root only?

In my opinion, flashing a ROM is simpler than just rooting a phone. In order to root the phone, the method is varied between the phones. But to flash the ROM, the method is similar (in my case, Samsung device only). (As I never successfully root the phone directly, even using the one-click rooting tool.)

Flashing a custom ROM, normally provides a lot of features especially superuser (root) and busybox. Both are my favourites, as I can adb shell to do a lot of things. However, if root only, then we need to install busybox ourselves. This may be time consuming. Furthermore, with root only, we may have difficulty to upgrade the Android version, such as from Froyo to Jelly Bean. Yet, if flashing the ROM, we can choose the version of Android that we prefer (normally the latest stable).

Benefits

Originality and genuineness is nice. Root an Android phone or flash in a custom ROM will void the warranty. If the warranty is expired, and the phone is “dying”, maybe flashing a new ROM is good solution to “renew” the phone. After flashing a custom ROM, you can enjoy the features provided by the ROM, especially root. So that you can install more powerful apps to your phone, including advertisement blocking apps.

Other than that, some new apps (such as games) require higher version of Android. The official firmware may only support to Ice Cream Sandwich. But, now already KitKat, you at least try to get Jelly Bean. But your Android is still Froyo or Gingerbread. Where is Honeycomb? You have missed a lot of things.

The best thing I like is busybox. With busybox, I can enjoy command-line in Terminal Emulator and also the adb shell to hack the device.

IMEI

After flashing the CyanogenMod, then I had a message about the invalid IMEI. This is seriously exhaustive when I want to restore it. Finally, I give up the IMEI.

In order to restore IMEI, I had done several things. Firstly, I re-flashed the stock ROM. Then the IMEI is restored. However, in order to preserve IMEI for the custom ROM, I have to backup the /efs folder. Yet, this folder cannot be accessed without the root permission. That is why, root is needed. I failed to root the phone. As a result, I used the psneuter method to gain the root access then used the busybox to “tar” the /efs folder.

According to the forums, if we have backup efs, then we can restore the IMEI. But, after I re-flashed the CyanogenMod, then I restored the efs folder, there is a message related to “not enough disk space”. Rebooted the phone, the phone then had a valid IMEI, but it could not call and no signal. This was worse than invalid IMEI. That is why I give up the IMEI.

Heimdall and Odin

In order to flash ROMs to Samsung devices, we need to use either Heimdall or Odin. I personally use Heimdall since I am using Linux. The stock ROM I obtained are the files end with tar.md5 extension. These files are compatible to Odin. However, they can be still flashed by using Heimdall. I used “tar xf” command to extract the tar.md5 files. As a result, I got some files like recovery.img, modem.bin, factoryfs.rfs, etc. These are the files that can be flashed with Heimdall.

Therefore, to flash with Heimdall, I can use a command like

heimdall flash --KERNEL zImage --CACHE cache.rfs --DBDATAFS dbdata.rfs --FACTORYFS factoryfs.rfs --MODEM modem.bin --PARAM param.lfs

For the parameters, such as --KERNEL, these are depending on the device. In order to know what parameters are available, we can use

heimdall print-pit

By these information, we can relate the parameters with the corresponding files.

During flashing, I caused my phone always boot into the Recovery Mode. The phone cannot boot into the Bootloader. I think that was because the files I flashed were incompatible and they damaged the bootloader. Thus, I downloaded another stock ROM that contains the boot.bin. Flashed it, then only that the phone can boot normally.

So, now I can enjoy my phone with custom ROM or stock ROM. Great Android phone!

tcplay script

Posted on

Recently, when I was using TrueCrypt in Arch Linux to mount a truecrypt container file, it was very slow to mount the container. Furthermore, I also read that the TrueCrypt is discontinued.

Therefore, I decided to use the tcplay. However, it is a command-line. Arch Linux wiki page shows a good tutorial on how to use tcplay.

When using tcplay in Linux, unlike mounting the folder like encfs, tcplay requires losetup for loop device. Thus, it involves 3 steps to mount a truecrypt container: i) setup loop device, ii) setup device-mapper with tcplay, and iii) mount. Consequently, to unmount the truecrypt containter need to reverse these 3 steps.

In order to make my life easier, I wrote a simple script as following. Feel free to modify it.

# @author Allen Choong
# @date    2014-06-29
# @version    1.0.1
#
# Easy mount the truecrypt encryptinog by using tcplay.
# Assuming the truecrypt mounting name does not have whitespace.
#
# Changelog:
# 2014-06-29    1.0.1    Add display help if there is no argument
# 2014-06-02    1.0    Initial

tc_mount() {
  lo=`losetup -f`
  losetup "$lo" "$1"
  tcplay -m "`basename "$1"`" -d "$lo"
  mount "/dev/mapper/`basename "$1"`" "$2"
}

tc_unmount() {
  echo -en "Unmount ... "
  umount "/dev/mapper/$1"
  lo=`losetup -l | grep "$1" | cut -d ' ' -f 1`
  dmsetup remove "$1"
  losetup -d "$lo"
  echo "OK!"
}

mklist() {
  start="$1"
  num="$2"
  ret="$1"
  for ((i=1;$i<=$num;i++)) ; do
    ret+=$(echo " `expr $start + $i`")
  done
  echo $ret
}

show_mount() {
  mount|grep '/dev/mapper' |while read l ; do num=`echo "$l" | tr ' ' '\n' | wc -l`;
    cutnum=$(mklist 3 `expr $num - 6`)
    echo "$l" | cut -d ' ' -f "1 $cutnum" | sed -e 's/\s/ => /'
  done
}

#Get arguments
for ((i=0;i<=$#;i++)) ; do
  args[$i]=${!i}
done

action="mount"

#Print help
if [ $# == "0" ] ; then
  echo "This command requires root privilege."
  echo "Usage:"
  echo "`basename $0` TRUECRYPT_CONTAINER MOUNT_POINT"
  echo ""
  echo "To list the mounted container:"
  echo "`basename $0` -l"
  echo ""
  echo "To unmount (requires root):"
  echo "`basename $0` -u CONTAINER_FILENAME"
  echo "where CONTAINER_FILENAME is the device mapper name"
  echo ""
  exit
fi

for ((i=1;i<=$#;i++)) ; do
  case ${args[$i]} in
    -l)
      show_mount
      exit
      ;;
    -u)
      unmnt=`echo ${args[$i+1]}`
      action="unmount"
      ;;
    esac
done

if [[ "$action" == "mount" ]] ; then
  tc_mount "$1" "$2"
elif [[ "$action" == "unmount" ]] ; then
  tc_unmount "$unmnt"
fi

Update (2014-06-29):
In order to use this script, if you have a file called foobar.tc (already make file system),

sudo tcplay.sh foobar.tc /path/to/mnt

After this, you can list the mounted point as,

tcplay.sh -l

To unmount the container,

sudo tcplay.sh -u foobar.tc #where the foobar.tc is the device mapper name, not the path to the file

Experience of installing CyanogenMod to old phone

Posted on

Recently, my phone (3 years old) is slower and slower. This causes me frustrated, especially if I want to use it to call urgently. Interface changed slowly, the contacts listed slowly, and my urgency becomes meaningless. So, the phone is either to be replaced with a new phone, or hack it!

My old phone, namely Samsung Galaxy S (i9000), to make it reborn, I decided to install CyanogenMod. CyanogenMod is well-known of its performance and reliability. The installation steps can be found in the wiki page.

Backup

Whatever it is, data is always the most precious. So, I backup’ed all the data in the /sdcard, which is the only partition that can be accessed in a non-rooted Android. I also used Super Backup to backup the installed apps, SMS, contacts, and others. However, the backup of the apps does not include the apps setting. Sorry to say that, all the saved states of the games will be no more. Unless I root the Android first.

Since the apps data can not be backup’ed, but only the data stored in the /sdcard can be backup’ed, thus I used other ways to backup some important data. For instance, WeChat and WhatsApp. Because the conversations are precious to me, so, I used the built-in backup function of these apps.

Preparation

Before start flashing the ROM to the phone, I downloaded all the necessary files: CyanogenMod stable version for Samsung Galaxy S, Google Apps, Heimdall suite, and ClockworkMod Recovery. Because I am using Linux, I installed android-sdk-platform-tools which contains the adb command.

Take risk

Once prepared everything, and read the whole wiki several times, so that I know what are the possible problems and issues. Then I just followed the steps from the wiki. (However, anyone who is doing this must take the risk that, you may need to throw your phone away.)

Problems

I faced many problems. Firstly, there was no “disclaimer message” for me to accept as written in the wiki. Besides that, there was no screenshot available from the wiki. Thus, when first time I entered the download mode, I am waiting for the disclaimer message.

I ignored it, so I continued to follow the steps. The next problem was the message in the console after I flash the zImage downloaded from the wiki.

ERROR: Partition “kernel” does not exist in the specified PIT.

Immediately I searched for the information, then a user from a forum mentioned to use uppercase of --KERNEL parameter. Actually it was written in the wiki, yet the wiki didn’t mention the error message as above.

After flashed the “zImage” which was downloaded from the wiki, I came to a serious problem. My phone was stuck at the pre-boot screen. There was a Samsung logo, but the phone could not boot. The “zImage” came from the Semaphore.tar in the wiki. I immediately visited to ClockworkMod webpage to search for the “recovery image“. Yet I found none of them looks like “zImage” (they are .zip files which contain some scripts and programs). Thus, I searched “Semaphore.tar” then I came to the official page. I tried other files from the official site, yet none of them works.

Then, I found some forums mentioned they have the same problem that stuck at the pre-boot screen. Finally, I read the Discussion of the wiki. It is very useful. Other users had the same problem, and they provided some information in the discussion. Consequently, I downloaded another recovery image from the discussion page of the wiki.

Then I flashed it, and the other things worked fine (some issues were mentioned in the discussion page).

Post-install

After installation, booted it, and I saw something totally different: new theme, Android 4.3, superuser, etc. Yeah!!!

So, the next thing I did was installing the Super Backup, so that I can restore all the other apps. Then restored SMS and contacts. WeChat and WhatsApp conversations were also restored. Luckily, the flashing of a ROM does not destroy the data in the /sdcard, else I need to copy the things to the phone again.

Next, I setup the Google Account and also the emails.

Then I tried to install Facebook app. Seriously, the app was slow as usual. So, I removed it immediately.

Now, I am still trying it and hopefully it has much better performance then the original ROM.

Learning in Linux community

Posted on

If you are using Linux, then you are involved in the Linux community. As in the Linux community, most of the software are open source software, which is about sharing and distributing the source code among the community.

As a Linux user, I am not just learn to use the free software happily without paying money. Using the Linux is more benefit than just saving the money.

As a Linux user, I know that reading manual/documentations is important. There are a lot of questions are mostly answered in the documentations or manual. In order to find the answers, we should read the manual. If the answers are available in the manual, yet a newbie is asking in the forum, he or she will be asked to RTFM.

Internet is a good resource for the answers. Utilise the search engine and look for the solutions. Look for solutions properly before asking. Only if the solution is not available, then only we ask in the forum, IRC, or question-and-answer websites such as unix.stackexchange.com.

When using forum, IRC, or question-and-answer websites, we should practice good netiquette. Always ask politely and be grateful to the person who answers your questions. Besides that, wait patiently for the answers. It is community-based, do not expect there is 24 hours 7 days support to your problem. When asking, please provide necessary information so that others will know what is going on. When using the forum, other than netiquette, choose the related forum to post the topic. We do not ask Ubuntu related questions in Fedora forum.

Sometimes, we may see some annoying problems in a Linux distro. The problems may not be solved manually because those are the bugs. If they are bugs, we should file the bugs report properly. However, before file the bugs, please check whether the bugs are not yet reported. After file the bugs, do not expect the bugs will be solved soon or immediately. If you want to solve the problem immediately, sorry to say, you need to solve it by yourself.

Wiki is a good resource in the Linux community. It is a community-based documentation. Read them, search them, follow the instructions if available. Sometimes, the wiki is not updated or there is minor error, contribute to the wiki and update the page. Also, read the “talks” of the wiki page, which may give you some ideas about what is going on.

If you are a programmer or software developer, and if you are able to patch the bugs, then contribute the patch to the community. This will be a wonderful contribution to the community. Because this is also what you need when you found some bugs.

Some Linux distros may have limited packages available. If we need to have other packages, learn about packaging and share the packages.

As a conclusion, become a Linux user is to be involved in the open source community, which will improve your own learning ability, problem solving skills, and communication skills.

Create LiveUSB in a general way


We can produce our own LiveUSB manually. The following are the steps that based on Arch Linux distro.

  1. Build a kernel that supports AUFS, SquashFS, and optionally vfat support. So that we can mount these filesystems. In Arch Linux, we can build linux-pf for these supports. This package can be found from AUR.
  2.  Then we can generate the initramfs. In Arch Linux, we can use mkinitcpio to create an initramfs image. For instance,
    mkinitcpio -k /boot/vmlinuz-linux-pf -c mkinitcpio-custom.conf -g initramfs.img

    (In Arch Linux, it is recommended to add in some modules in the mkinitcpio configuration file: zram, squashfs, loop, fuse, aufs, vfat)

  3. Besides that, we also need to prepare a squashfs so that it will act as a read only filesystem with workable programs. In order to create the squashfs, we can prepare it by using the existing filesystem.
    The important folders are: bin, etc, home, lib, mnt, opt, root, sbin, srv, usr, var.
    The important folders but let them empty are: dev, media, proc, run, sys, tmp.
    And also need to comment the lines in the /etc/fstab, so that after boot, there is no automount.
  4. Then we can prepare a USB pendrive so that it can boot by using syslinux. syslinux will run the syslinux.cfg, which can be located at /syslinux or /boot/syslinux. The simplest way to make the syslinux.cfg to boot is something like
    DEFAULT myliveusb
    LABEL myliveusb
    KERNEL vmlinuz-linux-pf
    APPEND initrd=initramfs.img

    By this, it will use the kernel vmlinuz-linux-pf which is built at the beginning (in step 1), and initrd with the initramfs.img that is generated (in step 2). These files need to be put at the same path with syslinux.cfg.

  5. In order to boot properly, we need to modify the “init” file in the initramfs.img. This image is actually compressed cpio. We can extract the data by
    zcat ../initramfs.img | cpio -i

    The extracted data contains some scripts, kernel modules, and libraries that are required to boot up. So, we just modify the init script.
    In the init script, we may need to disable the fsck_root (in Arch Linux) so that it will not fsck the root file.
    Then, we need to add in the statements to mount the USB pendrive and created squashfs.
    Therefore, we add in the following statements to somewhere before the initramfs switch the root.

    #The statements are based on http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf
    mkdir -p /mnt/usb /squashfs /tmpfs
    mount -t vfat -o ro /dev/disk/by-label/MYPENDRIVE /mnt/usb
    mount -t squashfs -o ro,loop /mnt/usb/path-to/root.sfs /squashfs
    mount -t tmpfs none /tmpfs
    #cd /tmpfs ; mkdir -p tmp var/log ; chmod 1777 tmp ; cd / #This step is optional
    mount -t aufs -o br=/tmpfs:/squashfs none /new_root #where the new_root is the root which will be switched according to Arch Linux

    Finally we need to re-compress by

    find . | cpio -o -H newc | gzip > ../initramfs.img

    If we read through the init script, at the end there is a statement that calls “switch_root” which will switch to the /new_root. Then, the system will boot successfully.

The AUFS is required because SquashFS is read-only. The following is the explanation of the statements above,

mount -t vfat -o ro /dev/disk/by-label/MYPENDRIVE /mnt/usb

is to mount the current USB pendrive to the /mnt/usb. We use the /dev/disk/by-label because it is the easiest way by referring the pendrive based on the label. /dev/sd{a,b,c} and so on are not applicable because different computer may have different number of storages. After this,

mount -t squashfs -o ro,loop /mnt/usb/path-to/root.sfs /squashfs

we mount the root.sfs which is created by mksquashfs. Then,

mount -t tmpfs none /tmpfs

we mount the tmpfs to a new folder /tmpfs. So that we use the memory for read-write operation. We do not use the default /tmp because it is used by initramfs.

cd /tmpfs ; mkdir -p tmp var/log ; chmod 1777 tmp

This is to create a tmp folder with the 1777 ownership as /tmp in the root. Finally,

mount -t aufs -o br=/tmpfs:/squashfs none /new_root

we mount the tmpfs and squashfs unionly to the /new_root

Because tmpfs is writable, squashfs is read-only, but they are mounted unionly in the new_root, as a result after switch_root, then it can boot and write to the new_root file system, as all the data are actually stored in the memory (as tmpfs occupies the memory).

By this, we can also create our own filesystem as a file (formated with ext4), and mount it unionly to the /new_root. So, that we can “save” the data and restore it during the next boot. (I have not yet tested this step by editing the init script.)

Follow

Get every new post delivered to your Inbox.

Join 152 other followers