forked from K-arch27/pinebtrfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPineBtrfs.sh
93 lines (73 loc) · 2.98 KB
/
PineBtrfs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
## Formating Partition and Getting UUID from them
clear
lsblk
echo -ne "-
Carefull all data on this partition is going to be deleted
-"
read -p "Please enter your BOOT partition : /dev/" partition1
mkfs.ext4 -L PINEBOOT /dev/$partition1
BOOTUUID=$(blkid -o value -s UUID /dev/$partition1)
clear
lsblk
echo -ne "-
Carefull all data on this partition is going to be deleted
-"
read -p "Please enter your Root partition : /dev/" partition2
mkfs.btrfs -L PINEROOT -m single -f /dev/$partition2
ROOTUUID=$(blkid -o value -s UUID /dev/$partition2)
clear
#Mounting Root on /mnt to create Btrfs Subvolumes
mount UUID=${ROOTUUID} /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@/.snapshots
mkdir /mnt/@/.snapshots/1
btrfs subvolume create /mnt/@/.snapshots/1/snapshot
mkdir /mnt/@/boot
btrfs subvolume create /mnt/@/root
btrfs subvolume create /mnt/@/srv
btrfs subvolume create /mnt/@/tmp
mkdir /mnt/@/usr
btrfs subvolume create /mnt/@/usr/local
mkdir /mnt/@/var
btrfs subvolume create /mnt/@/var/cache
btrfs subvolume create /mnt/@/var/log
btrfs subvolume create /mnt/@/var/spool
btrfs subvolume create /mnt/@/var/tmp
NOW=$(date +"%Y-%m-%d %H:%M:%S")
cp info.xml /mnt/@/.snapshots/1/info.xml
sed -i "s|2022-01-01 00:00:00|${NOW}|" /mnt/@/.snapshots/1/info.xml
btrfs subvolume set-default $(btrfs subvolume list /mnt | grep "@/.snapshots/1/snapshot" | grep -oP '(?<=ID )[0-9]+') /mnt
btrfs quota enable /mnt
chattr +C /mnt/@/var/cache
chattr +C /mnt/@/var/log
chattr +C /mnt/@/var/spool
chattr +C /mnt/@/var/tmp
# unmount root to remount with subvolume
umount /mnt
# mount @ subvolume
mount UUID=${ROOTUUID} -o compress=zstd /mnt
# make directories home, .snapshots, var, tmp
mkdir /mnt/.snapshots
mkdir /mnt/root
mkdir /mnt/srv
mkdir /mnt/tmp
mkdir -p /mnt/usr/local
mkdir -p /mnt/var/cache
mkdir /mnt/var/log
mkdir /mnt/var/spool
mkdir /mnt/var/tmp
mkdir /mnt/boot
mkdir /mnt/home
# mount subvolumes and partition
mount UUID=${ROOTUUID} -o noatime,compress=zstd,ssd,commit=120,subvol=@/.snapshots /mnt/.snapshots
mount UUID=${ROOTUUID} -o noatime,compress=zstd,ssd,commit=120,subvol=@/root /mnt/root
mount UUID=${ROOTUUID} -o noatime,compress=zstd,ssd,commit=120,subvol=@/srv /mnt/srv
mount UUID=${ROOTUUID} -o noatime,compress=zstd,ssd,commit=120,subvol=@/tmp /mnt/tmp
mount UUID=${ROOTUUID} -o noatime,compress=zstd,ssd,commit=120,subvol=@/usr/local /mnt/usr/local
mount UUID=${ROOTUUID} -o noatime,ssd,commit=120,subvol=@/var/cache /mnt/var/cache
mount UUID=${ROOTUUID} -o noatime,ssd,commit=120,subvol=@/var/log,nodatacow /mnt/var/log
mount UUID=${ROOTUUID} -o noatime,ssd,commit=120,subvol=@/var/spool,nodatacow /mnt/var/spool
mount UUID=${ROOTUUID} -o noatime,ssd,commit=120,subvol=@/var/tmp,nodatacow /mnt/var/tmp
mount UUID=${BOOTUUID} /mnt/boot
echo -ne "Done
Mount your Home partition in /mnt/home if you have one now and Extract your RootBackup inside /mnt"