[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Freedombox-discuss] Testing upgrades and installations in a btrfs snapshot



I mentioned the possibility to test package operations on a snapshot
before commiting to do them on the live system.  I tested this simple
script to do that on a btrfs based FreedomBox image, and it seem to
work fine:

  #!/bin/sh
  volname=@-upgrade-$$
  btrfs subvolume snapshot / /btrfs/$volname

  # Make sure no processes are started in test chroot
  printf "#!/bin/sh\nexit 101\n" > /btrfs/$volname/usr/sbin/policy-rc.d
  chmod a+rx /btrfs/$volname/usr/sbin/policy-rc.d

  # Run operation without inheriting libpam-tmpdir values.
  TMPDIR= TEMP= TEMPDIR= TMP= chroot /btrfs/$volname apt-get "$@"

  # Kill any stray processes before removing the subvolume
  fuser -mvk /btrfs/$volname

  btrfs subvolume delete /btrfs/$volname

It can for example be named 'test-apt-get' and used like this:

  test-apt-get install owncloud

It will check that a package is installable.  Here is a test run:

root at freedombox:~# ./test-apt-get install nullmailer
Create a snapshot of '/' in '/btrfs/@-upgrade-23838'
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  nullmailer
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 97.1 kB of archives.
After this operation, 444 kB of additional disk space will be used.
Get:1 http://http.debian.net/debian/ unstable/main nullmailer i386 1:1.13-1 [97.1 kB]
Fetched 97.1 kB in 1s (90.5 kB/s)     
Preconfiguring packages ...
E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)
Selecting previously unselected package nullmailer.
(Reading database ... 57269 files and directories currently installed.)
Preparing to unpack .../nullmailer_1%3a1.13-1_i386.deb ...
Unpacking nullmailer (1:1.13-1) ...
Processing triggers for man-db (2.7.0.2-3) ...
Setting up nullmailer (1:1.13-1) ...
invoke-rc.d: policy-rc.d denied execution of start.
[master ccf67d9] committing changes in /etc after apt run
 16 files changed, 109 insertions(+)
 create mode 100755 init.d/nullmailer
 create mode 100644 logcheck/ignore.d.paranoid/nullmailer
 create mode 100644 logcheck/ignore.d.server/nullmailer
 create mode 100644 logcheck/ignore.d.workstation/nullmailer
 create mode 100644 mailname
 create mode 100644 nullmailer/adminaddr
 create mode 100644 nullmailer/defaultdomain
 create mode 100644 nullmailer/remotes
 create mode 120000 rc0.d/K01nullmailer
 create mode 120000 rc1.d/K01nullmailer
 create mode 120000 rc2.d/S02nullmailer
 create mode 120000 rc3.d/S02nullmailer
 create mode 120000 rc4.d/S02nullmailer
 create mode 120000 rc5.d/S02nullmailer
 create mode 120000 rc6.d/K01nullmailer
======  How can you help?  (doc: https://wiki.debian.org/how-can-i-help ) ======

-----  Show old opportunities as well as new ones: how-can-i-help --old  -----
Transaction commit: none (default)
Delete subvolume '/btrfs/@-upgrade-23838'
root at freedombox:~#

A more complete script would ensure /proc/, /sys/ and /dev/ are
mounted from the system, to allow for example java to figure out what
CPU is used.  It should also be used with some care, as packages like
grub might change the disk images outside the snapshot and thus affect
the real system instead of the snapshot.

-- 
Happy hacking
Petter Reinholdtsen



Reply to: