Ensure to keep directories content if present

This way the script can be called before installation or at the end
(preseed/late_command).
This commit is contained in:
Jeremy Gardais 2019-01-23 18:56:57 +01:00
parent 0af422207b
commit 74eb9475b0
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 15 additions and 17 deletions

32
debian/part.btrfs.sh vendored
View File

@ -1,6 +1,6 @@
#!/bin/sh
# For Debian install
# For Debian install in late_command or in a TTY during installation.
# Complete the Btrfs partitionning
#
# Source: https://wiki.101010.fr/doku.php?id=debian:installation_btrfs
@ -8,22 +8,20 @@
# Remount the partition with "compress" option
mount -o remount,defaults,compress=lzo /target
# Create all subvolumes
btrfs subvolume create /target/home
btrfs subvolume create /target/opt
btrfs subvolume create /target/root
btrfs subvolume create /target/srv
btrfs subvolume create /target/tmp
btrfs subvolume create /target/usr
btrfs subvolume create /target/var
# Specific actions for "etc" subvolume
## In case the installation is based on LUKS/cryptsetup, we need to keep
## the generated cryptsetup's configuration.
mv /target/etc /target/etc.temp
btrfs subvolume create /target/etc
mv /target/etc.temp/* /target/etc
rmdir /target/etc.temp
# Manage subvolumes creation
for DIR in etc home opt root srv tmp usr var; do
## Move existent directory to a temp directory
test -d "/target/${DIR}" && mv -- /target/"${DIR}" /target/"${DIR}".temp
## Create subvolume
btrfs subvolume create /target/"${DIR}"
## If the directory already existed
if [ -d "/target/${DIR}.temp" ]; then
## Move the content to the new subvolume
mv -- /target/"${DIR}".temp/.* /target/"${DIR}".temp/* /target/"${DIR}"
## Remove the temp directory
rmdir -- /target/"${DIR}".temp
fi
done
# Ensure everything is ok
btrfs subvolume list -p /target