Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DATA_SIZE=$(du -s \
  4. --exclude="*_[A-Z][A-Z].*" \
  5. --exclude="*_[A-Z][A-Z]_*" \
  6. --exclude="*_[A-Z][A-Z][A-Z].*" \
  7. --exclude="*_[A-Z][A-Z][A-Z]_*" \
  8. /data/ | cut -f1)
  9.  
  10. #########################################################################
  11. # This is about the simplest way to resize a partition:
  12. # 1. Append the required space to the disk image
  13. # 2. Resize partition "2" to use the appended space
  14. # 3. Expose the partitions as devices (synchronously, so that we don't encounter race conditions)
  15. # 4. Modify the super block of the resized partition to match the new size
  16. #########################################################################
  17. truncate -s "+$(echo "(${DATA_SIZE} * 1024) + (1024 * 1024)" | bc)" "/tmp/raspbian.img"
  18. echo ",+" | sfdisk -N 2 "/tmp/raspbian.img"
  19. kpartx -a -s -v "/tmp/raspbian.img"
  20. resize2fs -f /dev/mapper/loop*p2
  21.  
  22. BOOT_PARTITION=$(basename /dev/mapper/loop*p1)
  23. DATA_PARTITION=$(basename /dev/mapper/loop*p2)
  24.  
  25. mkdir -p "/mnt/${BOOT_PARTITION}" "/mnt/${DATA_PARTITION}"
  26. mount "/dev/mapper/${BOOT_PARTITION}" "/mnt/${BOOT_PARTITION}"
  27. mount "/dev/mapper/${DATA_PARTITION}" "/mnt/${DATA_PARTITION}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement