##// END OF EJS Templates
Added: dphys-swapfile autoresize
drtyhlpr -
r540:958b7908f047
parent child
Show More
@@ -1,68 +1,76
1 1 logger -t "rc.firstboot" "Expanding root partition"
2 2
3 3 # Detect root partition device
4 4 ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
5 5 if [ -z "$ROOT_PART" ] ; then
6 6 log_warning_msg "unable to detect root partition device"
7 7 return 1
8 8 fi
9 9
10 10 # Extract root device name
11 11 case "${ROOT_PART}" in
12 12 mmcblk0*) ROOT_DEV=mmcblk0 ;;
13 13 sda*) ROOT_DEV=sda ;;
14 14 esac
15 15
16 16 # Check detected root partition name
17 17 PART_NUM=$(echo ${ROOT_PART} | grep -o '[1-9][0-9]*$')
18 18 if [ "$PART_NUM" = "$ROOT_PART" ] ; then
19 19 logger -t "rc.firstboot" "$ROOT_PART is not an SD card. Don't know how to expand"
20 20 return 0
21 21 fi
22 22
23 23 # NOTE: the NOOBS partition layout confuses parted. For now, let's only
24 24 # agree to work with a sufficiently simple partition layout
25 25 if [ "$PART_NUM" -gt 2 ] ; then
26 26 logger -t "rc.firstboot" "Your partition layout is not currently supported by this tool."
27 27 return 0
28 28 fi
29 29
30 30 # Check if last partition number
31 31 LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:)
32 32 if [ $LAST_PART_NUM -ne $PART_NUM ]; then
33 33 logger -t "rc.firstboot" "$ROOT_PART is not the last partition. Don't know how to expand"
34 34 return 0
35 35 fi
36 36
37 37 # Get the starting offset of the root partition
38 38 PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
39 39 if [ -z "$PART_START" ] ; then
40 40 logger -t "rc.firstboot" "${ROOT_DEV} unable to get starting sector of the partition"
41 41 return 1
42 42 fi
43 43
44 44 # Get the possible last sector for the root partition
45 45 PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }')
46 46 if [ -z "$PART_LAST" ] ; then
47 47 logger -t "rc.firstboot" "${ROOT_DEV} unable to get last sector of the partition"
48 48 return 1
49 49 fi
50 50
51 51 ### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit
52 52 fdisk /dev/${ROOT_DEV} <<EOF2 || true
53 53 p
54 54 d
55 55 $PART_NUM
56 56 n
57 57 p
58 58 $PART_NUM
59 59 $PART_START
60 60 $PART_LAST
61 61 p
62 62 w
63 63 EOF2
64 64
65 65 # Reload the partition table, resize root filesystem then remove resizing code from this file
66 66 partprobe &&
67 67 resize2fs /dev/${ROOT_PART} &&
68 68 logger -t "rc.firstboot" "Root partition successfully resized."
69
70 # Restart dphys-swapfile service if it exists
71 if systemctl list-units | grep -q dphys-swapfile ; then
72 if systemctl is-enabled dphys-swapfile ; then
73 logger -t "rc.firstboot" "Restarting dphys-swapfile"
74 systemctl restart dphys-swapfile
75 fi
76 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant