Chroot: Simplify the creation of fstab file

This commit is contained in:
Jeremy Gardais 2019-04-06 10:15:50 +02:00
parent f7e3d68b7e
commit d797c80bd8
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 14 additions and 16 deletions

30
debian/chroot.install vendored
View File

@ -89,35 +89,47 @@ mkswap -L sw01 -- /dev/mapper/"${vgname}"-swap
### Root ### Root
mkdir -p -- /target mkdir -p -- /target
mountpoint -q /target || mount -- /dev/mapper/"${vgname}"-root /target mountpoint -q /target || mount -- /dev/mapper/"${vgname}"-root /target
### Prepare an fstab file
printf '%b' "/dev/mapper/${vgname}-root / ext4 defaults 0 0" > /tmp/target.fstab
### boot - grub ### boot - grub
mkdir -p -- /target/boot mkdir -p -- /target/boot
mountpoint -q /target/boot || mount -- ${hdd}1 /target/boot mountpoint -q /target/boot || mount -- ${hdd}1 /target/boot
printf '%b' "${hdd}1 /boot ext3 defaults 0 0" >> /tmp/target.fstab
### home LV ### home LV
mkdir -p -- /target/home mkdir -p -- /target/home
mountpoint -q /target/home || mount -- /dev/mapper/"${vgname}"-home /target/home mountpoint -q /target/home || mount -- /dev/mapper/"${vgname}"-home /target/home
printf '%b' "/dev/mapper/${vgname}-home /home ext4 defaults 0 0" >> /tmp/target.fstab
### opt LV ### opt LV
mkdir -p -- /target/opt mkdir -p -- /target/opt
mountpoint -q /target/opt || mount -- /dev/mapper/"${vgname}"-opt /target/opt mountpoint -q /target/opt || mount -- /dev/mapper/"${vgname}"-opt /target/opt
printf '%b' "/dev/mapper/${vgname}-opt /opt ext4 defaults 0 0" >> /tmp/target.fstab
### srv LV ### srv LV
mkdir -p -- /target/srv mkdir -p -- /target/srv
mountpoint -q /target/srv || mount -- /dev/mapper/"${vgname}"-srv /target/srv mountpoint -q /target/srv || mount -- /dev/mapper/"${vgname}"-srv /target/srv
printf '%b' "/dev/mapper/${vgname}-srv /srv ext4 defaults 0 0" >> /tmp/target.fstab
#### bkp LV #### bkp LV
mkdir -p -- /target/srv/backup mkdir -p -- /target/srv/backup
mountpoint -q /target/srv/backup || mount -- /dev/mapper/"${vgname}"-bkp /target/srv/backup mountpoint -q /target/srv/backup || mount -- /dev/mapper/"${vgname}"-bkp /target/srv/backup
printf '%b' "/dev/mapper/${vgname}-bkp /srv/backup ext4 defaults 0 0" >> /tmp/target.fstab
### tmp LV ### tmp LV
mkdir -p -- /target/tmp mkdir -p -- /target/tmp
chmod 0777 -- /target/tmp
mountpoint -q /target/tmp || mount -- /dev/mapper/"${vgname}"-tmp /target/tmp mountpoint -q /target/tmp || mount -- /dev/mapper/"${vgname}"-tmp /target/tmp
printf '%b' "/dev/mapper/${vgname}-tmp /tmp ext4 defaults 0 0" >> /tmp/target.fstab
### usr LV ### usr LV
mkdir -p -- /target/usr mkdir -p -- /target/usr
mountpoint -q /target/usr || mount -- /dev/mapper/"${vgname}"-usr /target/usr mountpoint -q /target/usr || mount -- /dev/mapper/"${vgname}"-usr /target/usr
printf '%b' "/dev/mapper/${vgname}-usr /usr ext4 defaults 0 0" >> /tmp/target.fstab
### var LV ### var LV
mkdir -p -- /target/var mkdir -p -- /target/var
mountpoint -q /target/var || mount -- /dev/mapper/"${vgname}"-var /target/var mountpoint -q /target/var || mount -- /dev/mapper/"${vgname}"-var /target/var
printf '%b' "/dev/mapper/${vgname}-var /var ext4 defaults 0 0" >> /tmp/target.fstab
#### vz LV #### vz LV
mkdir -p -- /target/var/lib/vz mkdir -p -- /target/var/lib/vz
mountpoint -q /target/var/lib/vz || mount -- /dev/mapper/"${vgname}"-vz /target/var/lib/vz mountpoint -q /target/var/lib/vz || mount -- /dev/mapper/"${vgname}"-vz /target/var/lib/vz
printf '%b' "/dev/mapper/${vgname}-vz /var/lib/vz ext4 defaults 0 0" >> /tmp/target.fstab
### Swap ### Swap
swapon -- /dev/mapper/"${vgname}"-swap swapon -- /dev/mapper/"${vgname}"-swap
@ -128,22 +140,8 @@ debootstrap --arch amd64 --include="${dbs_pkg_include}" --exclude="${dbs_pkg_exc
# }}} # }}}
# Configure system {{{ # Configure system {{{
## Fstab {{{ ## Fstab {{{
### Use the current mtab content as default fstab file for the target system ### Copy the temp fstab file to target
grep target /etc/mtab | grep -vE '(tmpfs|pts|proc|sysfs)' > /target/etc/fstab cp -- /tmp/target.fstab /target/etc/fstab
### Ensure to enable swap
grep swap /target/etc/fstab || echo "/dev/mapper/${vgname}-swap swap swap sw,pri=0 0 0" >> /target/etc/fstab
### Add extra tmpfs mount point
grep "^proc" /target/etc/fstab || echo "proc /proc proc rw,nodev,size=100M 0 0" >> /target/etc/fstab
grep "^sysfs" /target/etc/fstab || echo "sysfs /sys sysfs rw,nodev,size=100M 0 0" >> /target/etc/fstab
grep "/dev/shm" /target/etc/fstab || echo "tmpfs /dev/shm tmpfs rw,nodev,size=100M 0 0" >> /target/etc/fstab
grep "^devpts" /target/etc/fstab || echo "devpts /dev/pts devpts rw,relatime,size=10240k,nr_inodes=2051120,mode=755 0 0" >> /target/etc/fstab
grep "/var/tmp" /target/etc/fstab || echo "/tmp /var/tmp none rw,bind,size=1M,mode=1777 0 0" >> /target/etc/fstab
### Remove all occurrences to target and avoid double slashs
sed -i 's;target;;g' /target/etc/fstab
sed -i 's;//;/;g' /target/etc/fstab
## }}} ## }}}
## Ensure to (re)mount devices for chroot {{{ ## Ensure to (re)mount devices for chroot {{{
mkdir -p -- /target/dev mkdir -p -- /target/dev