From 0eb02adc27344e3ae1243e728ad30aa9a2529028 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 27 Jan 2010 20:14:29 +0000 Subject: [PATCH] initial commit of partman-btrfs This is untested and unlikely to work without parted support. Committing what I have since I don't trust btrfs to preserve the data. ;-) Note to translators: Probably not worth wasting your time with this yet. Have not run debconf-updatepo. r62090 --- TODO | 10 ++++ active_partition/_numbers | 1 + active_partition/btrfs/choices | 70 +++++++++++++++++++++++++++ active_partition/btrfs/do_option | 41 ++++++++++++++++ check.d/_numbers | 2 + check.d/no_btrfs_boot | 32 +++++++++++++ check.d/nomountpoint_btrfs | 37 +++++++++++++++ commit.d/_numbers | 1 + commit.d/format_btrfs | 81 ++++++++++++++++++++++++++++++++ debian/changelog | 6 +++ debian/compat | 1 + debian/control | 14 ++++++ debian/copyright | 4 ++ debian/di-numbers | 7 +++ debian/install | 3 ++ debian/partman-btrfs.templates | 73 ++++++++++++++++++++++++++++ debian/rules | 3 ++ finish.d/_numbers | 1 + finish.d/aptinstall_btrfs | 27 +++++++++++ fstab.d/btrfs | 39 +++++++++++++++ init.d/_numbers | 1 + init.d/kernelmodules_btrfs | 20 ++++++++ mount.d/_numbers | 1 + mount.d/btrfs | 20 ++++++++ mountoptions/btrfs | 17 +++++++ parted_names/btrfs | 1 + valid_filesystems/_numbers | 1 + valid_filesystems/btrfs | 25 ++++++++++ 28 files changed, 539 insertions(+) create mode 100644 TODO create mode 100644 active_partition/_numbers create mode 100755 active_partition/btrfs/choices create mode 100755 active_partition/btrfs/do_option create mode 100644 check.d/_numbers create mode 100755 check.d/no_btrfs_boot create mode 100755 check.d/nomountpoint_btrfs create mode 100644 commit.d/_numbers create mode 100755 commit.d/format_btrfs create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/di-numbers create mode 100644 debian/install create mode 100644 debian/partman-btrfs.templates create mode 100755 debian/rules create mode 100644 finish.d/_numbers create mode 100755 finish.d/aptinstall_btrfs create mode 100755 fstab.d/btrfs create mode 100644 init.d/_numbers create mode 100755 init.d/kernelmodules_btrfs create mode 100644 mount.d/_numbers create mode 100755 mount.d/btrfs create mode 100644 mountoptions/btrfs create mode 100644 parted_names/btrfs create mode 100644 valid_filesystems/_numbers create mode 100755 valid_filesystems/btrfs diff --git a/TODO b/TODO new file mode 100644 index 0000000..8c95a65 --- /dev/null +++ b/TODO @@ -0,0 +1,10 @@ +* Support for multi-volume btrfs filesystems +* Support for other mkfs.btrfs options, if any are useful. +* Support for btrfs snapshots / using existing btrfs? +* Check if errors=remount-ro makes sense to use. +* mountoptions is missing a few options that may be worth supporting, + including degraded, and all optionds that require a parameter. +* mountoptions contains nobarrier, which is an unsafe option. Remove? Warn? +* parted support needed for filesystem detection #567176 +* Resizing? +* Allow forcing use of btrfs for /boot (would probably work with eg, lilo) diff --git a/active_partition/_numbers b/active_partition/_numbers new file mode 100644 index 0000000..6ff6666 --- /dev/null +++ b/active_partition/_numbers @@ -0,0 +1 @@ +45 btrfs diff --git a/active_partition/btrfs/choices b/active_partition/btrfs/choices new file mode 100755 index 0000000..262746a --- /dev/null +++ b/active_partition/btrfs/choices @@ -0,0 +1,70 @@ +#!/bin/sh + +. /usr/share/debconf/confmodule + +set -e + +dev=$1 +id=$2 +part=$dev/$id + +cd $dev + +[ -f $part/method -a -f $part/acting_filesystem ] || exit 0 + +filesystem=$(cat $part/acting_filesystem) + +case "$filesystem" in + btrfs) + : + ;; + *) + exit 0 + ;; +esac + +choice_mountpoint () { + case "$filesystem" in + btrfs) + if [ -f $part/mountpoint ]; then + mp=$(cat $part/mountpoint) + else + db_metaget partman-basicfilesystems/text/no_mountpoint description + mp="$RET" + fi + db_metaget partman-btrfs/text/specify_mountpoint description + printf "mountpoint\t%s\${!TAB}%s\n" "$RET" "$mp" + ;; + esac +} + +choice_options () { + db_metaget partman-basicfilesystems/text/options description + printf "options\t%s\${!TAB}%.45s\n" "$RET" "$(get_mountoptions $dev $id)" +} + +choice_label () { + # allow to set label only if the partition is to be formatted + [ -f $part/format ] || return 0 + [ ! -f $part/formatted \ + -o $part/formatted -ot $part/method \ + -o $part/formatted -ot $part/filesystem ] || return 0 + case "$filesystem" in + btrfs) + if [ -f $part/label ]; then + label=$(cat $part/label) + else + db_metaget partman-basicfilesystems/text/none description + label=$RET + fi + db_metaget partman-basicfilesystems/text/specify_label description + printf "label\t%s\${!TAB}%s\n" "$RET" "$label" + ;; + esac +} + +choice_mountpoint + +choice_options + +choice_label diff --git a/active_partition/btrfs/do_option b/active_partition/btrfs/do_option new file mode 100755 index 0000000..a4c6ae4 --- /dev/null +++ b/active_partition/btrfs/do_option @@ -0,0 +1,41 @@ +#!/bin/sh + +. /lib/partman/lib/base.sh + +dev=$2 +id=$3 +part=$dev/$id + +cd $dev + +[ -f $part/method -a -f $part/acting_filesystem ] || return 0 +filesystem=$(cat $part/acting_filesystem) + +case $1 in + mountpoint) + if select_mountpoint $dev $id; then + update_partition $dev $id + fi + ;; + options) + select_mountoptions $dev $id + ;; + label) + label='' + if [ -f $part/label ]; then + label=$(cat $part/label) + fi + db_set partman-basicfilesystems/choose_label "$label" + db_input critical partman-basicfilesystems/choose_label || true + db_go || exit 1 + db_get partman-basicfilesystems/choose_label + if [ "$RET" ]; then + echo "$RET" >$part/label + else + rm -f $part/label + fi + db_reset partman-basicfilesystems/choose_label + ;; +esac + +exit 0 diff --git a/check.d/_numbers b/check.d/_numbers new file mode 100644 index 0000000..710d9fa --- /dev/null +++ b/check.d/_numbers @@ -0,0 +1,2 @@ +09 nomountpoint_btrfs +05 no_btrfs_boot diff --git a/check.d/no_btrfs_boot b/check.d/no_btrfs_boot new file mode 100755 index 0000000..ef9c180 --- /dev/null +++ b/check.d/no_btrfs_boot @@ -0,0 +1,32 @@ +#!/bin/sh +# grub and other bootloaders that read the filesystem do not support /boot +# on btrfs. (lilo should work). Detect and warn. + +. /lib/partman/lib/base.sh + +get_btrfs_root_boot () { + (for i in /lib/partman/fstab.d/*; do + [ -x "$i" ] || continue + $i + done) | + while read fs mp type options dump pass; do + if [ "$mp" = / ]; then + echo root_type=$type + elif [ "$mp" = /boot ]; then + echo boot_type=$type + fi + done +} +eval "$(get_btrfs_root_boot)" + +if [ "$boot_type" = btrfs ]; then + db_input critical partman-btrfs/btrfs_boot || true + db_go || exit 1 + exit 1 +fi + +if [ "$boot_type" = "" ] && [ "$root_type" = btrfs ]; then + db_input critical partman-btrfs/btrfs_root || true + db_go || exit 1 + exit 1 +fi diff --git a/check.d/nomountpoint_btrfs b/check.d/nomountpoint_btrfs new file mode 100755 index 0000000..f6ce818 --- /dev/null +++ b/check.d/nomountpoint_btrfs @@ -0,0 +1,37 @@ +#!/bin/sh + +. /lib/partman/lib/base.sh + +for dev in $DEVICES/*; do + [ -d "$dev" ] || continue + cd $dev + partitions= + open_dialog PARTITIONS + while { read_line num id size type fs path name; [ "$id" ]; }; do + [ "$fs" != free ] || continue + partitions="$partitions $id,$num" + done + close_dialog + + for part in $partitions; do + id=${part%,*} + num=${part#*,} + [ -f $id/method ] || continue + [ -f $id/acting_filesystem ] || continue + filesystem=$(cat $id/acting_filesystem) + case "$filesystem" in + btrfs) + [ ! -f "$id/mountpoint" ] || continue + db_subst partman-btrfs/no_mount_point PARTITION "$num" + db_subst partman-btrfs/no_mount_point FILESYSTEM "$filesystem" + db_subst partman-btrfs/no_mount_point DEVICE $(humandev $(cat device)) + db_input critical partman-btrfs/no_mount_point || true + db_go || exit 1 + db_get partman-btrfs/no_mount_point + if [ "$RET" = true ]; then + exit 1 + fi + ;; + esac + done +done diff --git a/commit.d/_numbers b/commit.d/_numbers new file mode 100644 index 0000000..6fbce3c --- /dev/null +++ b/commit.d/_numbers @@ -0,0 +1 @@ +50 format_btrfs diff --git a/commit.d/format_btrfs b/commit.d/format_btrfs new file mode 100755 index 0000000..a402fdf --- /dev/null +++ b/commit.d/format_btrfs @@ -0,0 +1,81 @@ +#!/bin/sh + +. /lib/partman/lib/base.sh + +enable_swap + +for dev in $DEVICES/*; do + [ -d "$dev" ] || continue + cd $dev + partitions= + open_dialog PARTITIONS + while { read_line num id size type fs path name; [ "$id" ]; }; do + [ "$fs" != free ] || continue + partitions="$partitions $id,$num" + done + close_dialog + + for part in $partitions; do + id=${part%,*} + num=${part#*,} + [ -f $id/method -a -f $id/format \ + -a -f $id/acting_filesystem ] || continue + filesystem=$(cat $id/acting_filesystem) + case $filesystem in + btrfs) + if [ -f $id/formatted ] && \ + [ $id/formatted -nt $id/method ] && \ + ([ ! -f $id/filesystem ] || \ + [ $id/formatted -nt $id/filesystem ]); then + continue + fi + log "Try to create file system for $dev/$id" + if [ -f $id/mountpoint ]; then + template=partman-basicfilesystems/progress_formatting_mountable + db_subst $template MOUNT_POINT "$(cat $id/mountpoint)" + else + template=partman-basicfilesystems/progress_formatting + fi + open_dialog PARTITION_INFO $id + read_line x1 x2 x3 x4 x5 device x6 + close_dialog + + RET='' + db_metaget partman/filesystem_short/"$filesystem" description || RET='' + [ "$RET" ] || RET="$filesystem" + db_subst $template TYPE "$RET" + db_subst $template PARTITION "$num" + db_subst $template DEVICE $(humandev $(cat device)) + + db_progress START 0 3 partman/text/formatting + db_progress INFO $template + db_progress SET 1 + + label='' + if [ -f $id/label ]; then + label=$(cat $id/label | \ + sed 's/\(............\).*/\1/g') + fi + code=0 + # Ensure label is quoted correctly + log-output -t partman --pass-stdout \ + mkfs.btrfs ${label:+-L "$label"} \ + $device >/dev/null || code=$? + sync + db_progress STOP + + if [ "$code" != 0 ]; then + db_subst partman-btrfs/create_failed PARTITION "$num" + db_subst partman-btrfs/create_failed DEVICE $(humandev $(cat device)) + db_input critical partman-btrfs/create_failed || true + db_go || true + #disable_swap + exit 1 + fi + >$id/formatted + ;; + esac + done +done + +#disable_swap diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..d131f28 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,6 @@ +partman-btrfs (1) UNRELEASED; urgency=low + + * Took partman-xfs and s/xfs/btrfs/, essentially. + * Added error messages if /boot is on btrfs. + + -- Joey Hess Thu, 4 Mar 2004 12:42:40 -0500 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..9714b7f --- /dev/null +++ b/debian/control @@ -0,0 +1,14 @@ +Source: partman-btrfs +Section: debian-installer +Priority: standard +Maintainer: Debian Install System Team +Uploaders: Anton Zinoviev , Joey Hess +Build-Depends: debhelper (>= 7.0.8), dh-di, po-debconf (>= 0.5.0) +Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/partman/partman-btrfs + +Package: partman-btrfs +XC-Package-Type: udeb +Architecture: all +Depends: ${misc:Depends}, btrfs-tools-udeb, btrfs-modules, partman-basicfilesystems (>= 59), partman-base (>= 124) +Provides: partman-filesystem +Description: Add to partman support for btrfs diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..4740f09 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,4 @@ +This package is under the GNU GPL version 2, or any later +version at your option. +On Debian system, the GPL is available in +/usr/share/common-licenses/GPL-2 diff --git a/debian/di-numbers b/debian/di-numbers new file mode 100644 index 0000000..3f4a990 --- /dev/null +++ b/debian/di-numbers @@ -0,0 +1,7 @@ +active_partition lib/partman +valid_filesystems lib/partman +init.d lib/partman +check.d lib/partman +commit.d lib/partman +finish.d lib/partman +mount.d lib/partman diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..2ab08be --- /dev/null +++ b/debian/install @@ -0,0 +1,3 @@ +mountoptions lib/partman +fstab.d lib/partman +parted_names lib/partman diff --git a/debian/partman-btrfs.templates b/debian/partman-btrfs.templates new file mode 100644 index 0000000..12c76c2 --- /dev/null +++ b/debian/partman-btrfs.templates @@ -0,0 +1,73 @@ +Template: partman-btrfs/progress_checking +Type: text +# :sl2: +_Description: Checking the btrfs file system in partition #${PARTITION} of ${DEVICE}... + +Template: partman-btrfs/check_failed +Type: boolean +# :sl2: +_Description: Go back to the menu and correct errors? + The test of the file system with type btrfs in partition #${PARTITION} + of ${DEVICE} found uncorrected errors. + . + If you do not go back to the partitioning menu and correct these errors, + the partition will not be used at all. + +Template: partman-btrfs/create_failed +Type: error +# :sl2: +_Description: Failed to create a file system + The btrfs file system creation in partition + #${PARTITION} of ${DEVICE} failed. + +Template: partman-btrfs/no_mount_point +Type: boolean +# :sl2: +_Description: Do you want to return to the partitioning menu? + No mount point is assigned for the btrfs file system in partition + #${PARTITION} of ${DEVICE}. + . + If you do not go back to the partitioning menu and assign a mount point + from there, this partition will not be used at all. + +Template: partman-btrfs/text/specify_mountpoint +Type: text +# :sl2: +# This is an item in the menu "Partition settings" +_Description: Mount point: + +Template: partman-btrfs/text/btrfs +Type: text +# :sl2: +# File system name (untranslatable in many languages) +_Description: btrfs + +Template: partman/filesystem_long/btrfs +Type: text +# :sl2: +# File system name +_Description: btrfs journaling file system + +Template: partman/filesystem_short/btrfs +Type: text +# :sl1: +# Short file system name (untranslatable in many languages) +_Description: btrfs + +Template: partman-btrfs/btrfs_root +Type: error +# :sl2: +_Description: btrfs root file system not supported without separate /boot + Your root file system is a btrfs file system. This is not supported + by the boot loader used by default by this installer. + . + You should use a small /boot partition with another file system, such as ext3. + +Template: partman-btrfs/btrfs_boot +Type: error +# :sl2: +_Description: btrfs file system not supported for /boot + You have mounted a btrfs file system as /boot. This is not supported + by the boot loader used by default by this installer. + . + You should use another file system, such as ext3, for the /boot partition. diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..37850fb --- /dev/null +++ b/debian/rules @@ -0,0 +1,3 @@ +#! /usr/bin/make -f +%: + dh --with d-i $@ diff --git a/finish.d/_numbers b/finish.d/_numbers new file mode 100644 index 0000000..c33c079 --- /dev/null +++ b/finish.d/_numbers @@ -0,0 +1 @@ +70 aptinstall_btrfs diff --git a/finish.d/aptinstall_btrfs b/finish.d/aptinstall_btrfs new file mode 100755 index 0000000..ae79b17 --- /dev/null +++ b/finish.d/aptinstall_btrfs @@ -0,0 +1,27 @@ +#!/bin/sh + +. /lib/partman/lib/base.sh + +btrfs=no + +for dev in $DEVICES/*; do + [ -d "$dev" ] || continue + cd $dev + partitions= + open_dialog PARTITIONS + while { read_line num id size type fs path name; [ "$id" ]; }; do + [ "$fs" != free ] || continue + [ -f $id/method -a -f $id/acting_filesystem ] || continue + filesystem=$(cat $id/acting_filesystem) + case $filesystem in + btrfs) + btrfs=yes + ;; + esac + done + close_dialog +done + +if [ "$btrfs" = yes ]; then + apt-install btrfs-tools || true +fi diff --git a/fstab.d/btrfs b/fstab.d/btrfs new file mode 100755 index 0000000..9111d3b --- /dev/null +++ b/fstab.d/btrfs @@ -0,0 +1,39 @@ +#!/bin/sh + +. /lib/partman/lib/base.sh + +for dev in $DEVICES/*; do + [ -d $dev ] || continue + cd $dev + open_dialog PARTITIONS + while { read_line num id size type fs path name; [ "$id" ]; }; do + [ $fs != free ] || continue + [ -f "$id/method" ] || continue + [ -f "$id/acting_filesystem" ] || continue + method=$(cat $id/method) + filesystem=$(cat $id/acting_filesystem) + case "$filesystem" in + btrfs) + [ -f "$id/mountpoint" ] || continue + mountpoint=$(cat $id/mountpoint) + # due to #249322, #255135, #258117: + if [ "$mountpoint" = /tmp ]; then + rm -f $id/options/noexec + fi + options=$(get_mountoptions $dev $id) + if [ "$mountpoint" = / ]; then + if [ "$options" = defaults ]; then + options="errors=remount-ro" + else + options="${options},errors=remount-ro" + fi + pass=1 + else + pass=2 + fi + echo "$path" "$mountpoint" btrfs $options 0 $pass + ;; + esac + done + close_dialog +done diff --git a/init.d/_numbers b/init.d/_numbers new file mode 100644 index 0000000..5dfb757 --- /dev/null +++ b/init.d/_numbers @@ -0,0 +1 @@ +03 kernelmodules_btrfs diff --git a/init.d/kernelmodules_btrfs b/init.d/kernelmodules_btrfs new file mode 100755 index 0000000..79a8244 --- /dev/null +++ b/init.d/kernelmodules_btrfs @@ -0,0 +1,20 @@ +#!/bin/sh + +mkdir -p /var/lib/partman + +cat /proc/modules | +while read module_name x; do + if [ "$module_name" = btrfs ]; then + >/var/lib/partman/btrfs + exit 0 + fi +done + +if modprobe btrfs >/dev/null 2>/dev/null; then + >/var/lib/partman/btrfs + exit 0 +fi + +if grep -q btrfs /proc/filesystems; then + >/var/lib/partman/btrfs +fi diff --git a/mount.d/_numbers b/mount.d/_numbers new file mode 100644 index 0000000..600e6d3 --- /dev/null +++ b/mount.d/_numbers @@ -0,0 +1 @@ +70 btrfs diff --git a/mount.d/btrfs b/mount.d/btrfs new file mode 100755 index 0000000..eb4b1fb --- /dev/null +++ b/mount.d/btrfs @@ -0,0 +1,20 @@ +#!/bin/sh + +set -- $1 + +fs=$1 +mp=$2 +type=$3 +options=$4 +dump=$5 +pass=$6 + +case $type in + btrfs) + mount -t btrfs ${options:+-o "$options"} $fs /target$mp || exit 1 + echo "umount /target$mp" + exit 0 + ;; +esac + +exit 1 diff --git a/mountoptions/btrfs b/mountoptions/btrfs new file mode 100644 index 0000000..01a5de8 --- /dev/null +++ b/mountoptions/btrfs @@ -0,0 +1,17 @@ +noatime +relatime +nodev +nosuid +noexec +ro +sync +usrquota +grpquota +nodatasum +nodatacow +nobarrier +compress +ssd +noacl +notreelog +flushoncommit diff --git a/parted_names/btrfs b/parted_names/btrfs new file mode 100644 index 0000000..00531f6 --- /dev/null +++ b/parted_names/btrfs @@ -0,0 +1 @@ +btrfs diff --git a/valid_filesystems/_numbers b/valid_filesystems/_numbers new file mode 100644 index 0000000..058feff --- /dev/null +++ b/valid_filesystems/_numbers @@ -0,0 +1 @@ +25 btrfs diff --git a/valid_filesystems/btrfs b/valid_filesystems/btrfs new file mode 100755 index 0000000..a92f933 --- /dev/null +++ b/valid_filesystems/btrfs @@ -0,0 +1,25 @@ +#!/bin/sh + +dev=$1 +id=$2 +property=$3 + +[ -f /var/lib/partman/btrfs ] || exit 0 + +case $property in + formatable) + echo btrfs + ;; + existing) + [ -f $id/detected_filesystem ] || exit 0 + fs=$(cat $id/detected_filesystem) + + case "$fs" in + btrfs) + echo btrfs + ;; + esac + ;; +esac + +